Question

I am using ubuntu 13.10 OS and LAMP, Apache 2.4.

I would like to create a virtual host on apache. I tried some code, but it didn't work.

The following modifications are made. but it's not working.

First I changed HostnameLookups off to HostnameLookups on on etc\apache2\apache2.conf file. Then I added the below code,

<VirtualHost *:80>
ServerName local.scholarships.theiet.in
DocumentRoot /home/www/my_project/public_html
<Directory path_to_code_base/public>
    Options -Indexes
    Require all granted
    DirectoryIndex index.php
    AllowOverride All
</Directory>
</VirtualHost>

After restart apache I ran http://localhost/ . The site is not loaded.

How can I load my site when running http://localhost/

Was it helpful?

Solution 3

This is an another way of create a virtual host in ubuntu 13.10

Below example shows how to create a virtual host,

Step 1: create a PHP project named site1.com on /home/user/www/

Step 2: Change HostnameLookups off to HostnameLookups on in /etc/apache2/apache2.conf

Step 3: Create a config file named site1.com.conf on /etc/apache2/sites-available/

Add this code to site1.com.conf,

<VirtualHost *:80>
ServerName site1.com
ServerAlias www.site1.com
ServerAdmin info@site1.com
DocumentRoot /var/www/site1.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/var/www/site1.com">
    Options All
    AllowOverride All
    Require all granted
</Directory>
</VirtualHost>

Step 4: Then add 127.0.0.1 site1.com to /etc/hosts.txt

Step 5: Open terminal and run the commands,

sudo a2ensite site1.com

sudo /etc/init.d/apache2 restart

Step 6: Open browser and run http://site1.com/

Try this

OTHER TIPS

Here is how you can create virtural host on Apache/Ubuntu:

My 000-default.conf file:

<VirtualHost *:80>
    DocumentRoot /var/www/php/frbit/l4blog/public/
    <Directory /var/www/php/frbit/l4blog/public/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
    </Directory>
    ServerName l4blog
</VirtualHost>

Note that I created ServerName, which is the name of my new host.

And you can add new host name in /etc/hosts file like this:

127.0.0.1   your_host_name

In order not to type long url e.g. instead of

http://localhost/path/directory/file/...

You can just enter your_host_name in the address bar:

your_host_name

Your configuration files filenames in the sites-available directory must now end in ".conf", so in /etc/apache2/sites-available/ add your .conf file, named in the style of example.com.conf; model it on the following:

<VirtualHost *:80>
ServerAdmin you@example.com
    ServerName www.example.com
    DocumentRoot /var/www/example.com
    <Directory />
            Options FollowSymLinks
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
    require all granted
    </Directory>

    ErrorLog /var/log/apache2/example.com.error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog /var/log/apache2/example.com.access.log combined    
</VirtualHost>

Enable it in apache with:

$ sudo a2ensite example.com

(If you need to disable it later use $sudo a2dissite example.com)

You might also need to add a line to your /etc/hosts file:

127.0.0.1 example.com

Don't forget that although you've added the site to apache with a2ensite, you will also need to restart apache.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top