Skip to content
Advertisement

How to perfectly set up virtual host for codeigniter project?

I am trying to make a virtual host for a codeigniter project. I have done this in httpd-vhosts.conf:

    <VirtualHost *:80>
      DocumentRoot "C:xampphtdocsCI_projectsfacebook-login"
       ServerName dev.facebook-login.com
       <Directory "C:xampphtdocsCI_projectsfacebook-login">
     Require all granted
    </Directory>
    </VirtualHost>

and in application/config/config.php,

$config['base_url'] = 'http://dev.facebook-login.com';

and

$config['index_page'] = '';

the browser opens the landing page. but when transiting from any other uri it says object not found. And when i configure httpd-vhosts.conf like this:

   <VirtualHost *:80>
      DocumentRoot "C:xampphtdocsCI_projectsfacebook-loginindex.php"
       ServerName dev.facebook-login.com
       <Directory "C:xampphtdocsCI_projectsfacebook-loginindex.php">
     Require all granted
    </Directory>
    </VirtualHost>

It arises problem with assets things, i,e images and some css doesnt loads. How can I solve it?

Advertisement

Answer

I am on windows 10 and I use xampp with virtual host this is way I set up.

Put forward slash at end of base url

$config['base_url'] = 'http://dev.facebook-login.com/';

First go to

Windows > System32 > drivers > etc > host

You may need to open as administrator to be able to save it

You might see some thing like

127.0.0.1       localhost 

Below that create another one for dev.facebook-login.com like example:

127.0.0.1       localhost
127.0.0.1       dev.facebook-login.com

Save it

Then go to the

xampp > apache > conf > extra > httpd-vhosts.conf

open it as administrator so you can save it.

No need for the index.php on DocumentRoot

<VirtualHost *:80>
    ##ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "C:/xampp/htdocs/CI_projects/facebook-login"
    ServerName dev.facebook-login.com
    ##ServerAlias www.dummy-host.example.com
    ##ErrorLog "logs/dummy-host.example.com-error.log"
    ##CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost> 

Save it and restart the severs.

I use this for my htaccess

Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index.php|images|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement