Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:\xampp\htdocs\CI_projects\facebook-login"
       ServerName dev.facebook-login.com
       <Directory "C:\xampp\htdocs\CI_projects\facebook-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:\xampp\htdocs\CI_projects\facebook-login\index.php"
       ServerName dev.facebook-login.com
       <Directory "C:\xampp\htdocs\CI_projects\facebook-login\index.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?

like image 540
Tekraj Shrestha Avatar asked Mar 10 '23 09:03

Tekraj Shrestha


1 Answers

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 [email protected]
    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]
like image 112
Mr. ED Avatar answered Apr 26 '23 15:04

Mr. ED