Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Virtual host on ubuntu 13.10 and apache 2.4.6

I have the following problem
My hosts file is as follows:

127.0.0.1       localhost 127.0.1.1       barbala4o-HP-ProBook-4530s 127.0.1.1       mysite.localhost 

My file in the /etc/apache2/sites-available/mysite.localhost.conf is as follows :

<VirtualHost *:80>         ServerAdmin webmaster@localhost         ServerName mysite.localhost          DocumentRoot /var/www/mysite          <Directory /var/www/mysite/>                 Options Indexes FollowSymLinks                 AllowOverride All                 Require all granted         </Directory>         ErrorLog /var/log/apache2/mysite-error.log         CustomLog /var/log/apache2/mysite-access.log common </VirtualHost> 

After do sudo a2ensite mysite.localhost.conf and restart apache on mysite.localhost/ and only on localhost i get the following (like listing a directory without index file in it):

Index of /  [ICO]   Name    Last modified   Size    Description [DIR]   apache_logs/    2013-09-24 10:15     -    [DIR]   mysql/  2013-10-22 10:05     -    [DIR]   tools/  2013-10-22 10:05 

And on any other folder in the /var/www/ directory like test when i enter localhost/test instead of loading the index.php file it shows:

Not Found  The requested URL /adlantic was not found on this server.  Apache/2.4.6 (Ubuntu) Server at localhost Port 80    

If I do sudo a2dissite mysite.conf and restart apache everything is loading ok. I guess the problem is somewhere in the mysite.localhost.conf but I can't find where. Any ideas? 10x

like image 265
Lachezar Raychev Avatar asked Oct 22 '13 13:10

Lachezar Raychev


People also ask

How do I find virtual hosts in Ubuntu?

On Ubuntu systems, Apache Virtual Hosts configuration files are located in /etc/apache2/sites-available directory. They can be enabled by creating symbolic links to the /etc/apache2/sites-enabled directory, which Apache read during the startup.

Is Apache a virtual server?

The Apache HTTP server supports virtual hosts, meaning that it can respond to requests that are directed to multiple IP addresses or host names that correspond to the same host machine. You can configure each virtual host to provide different content and to behave differently.


2 Answers

Ubuntu 13.10 and variants have moved to Apache 2.4. Apache 2.4 wants enabled virtual host config files to end in .conf by default.

Solution

Now to correct this problem there are two methods you can use to achieve the same result.

  1. The first solution and simple solution, is to add a .conf extension to all your virtual host. The new Apache 2.4 reads each virtual host in the sites-available directory with .conf extension outlined in the new Apache 2.4 configuration file.

  2. The second solution is to remove the .conf extension in Apache 2.4 configuration file located in /etc/apache2/apache2.conf

In the old Apache 2.2 file the .conf file had a Include sites-enabled/ whereas the new .conf file has

# Include the virtual host configurations: IncludeOptional sites-enabled/*.conf 

Change that line to read:

# Include the virtual host configurations: IncludeOptional sites-enabled/ 

The results: the command a2ensite yourdomain now runs as expected. If you are using the 2nd method; your virtual host files do not need to have the .conf extension.

Note: Configuration file is "/etc/apache2/apache2.conf" in new Apache, so please copy document root path and other configurations from "/etc/apache2/sites-available/000-default.conf" to  "/etc/apache2/apache2.conf" 
  • See more at: http://lyemium.com/content/virtual-host-issues-when-upgrading-apache-22-24#sthash.VVRCvEwS.dpuf
like image 75
Anjith K P Avatar answered Sep 22 '22 22:09

Anjith K P


I found the problem after 3h of experimenting. Apparently in the new Ubuntu 13.10 for some stupid reason the conf file for the virtual host has to look similar to this:

<VirtualHost mysite.localhost>         ServerAdmin [email protected]         ServerName  mysite.localhost         ServerAlias mysite.localhost          # Indexes + Directory Root.         DocumentRoot /var/www/mysite/public_html           <Directory /var/www/mysite/public_html/>                 DirectoryIndex index.php                 Options Indexes FollowSymLinks                 AllowOverride All                 Require all granted         </Directory>          # Logfiles         ErrorLog /var/log/apache2/mysite-error.log         CustomLog /var/log/apache2/mysite-access.log common </VirtualHost> 

Apparently the guys that developed Ubuntu 13.10 decided that it is no longer valuable to use

<VirtualHost *:80>  

when making a virtual host and instead it has to be

<VirtualHost mysite.localhost> 

mixed with specifically specifying DirectoryIndex. This fixed the problem i had and now things are working(hopefully as they should, something may come up eventually) Apparently the configuration file of apache is different.

like image 20
Lachezar Raychev Avatar answered Sep 24 '22 22:09

Lachezar Raychev