Virtual host on ubuntu 13.10 and apache 2.4.6
Asked Answered
S

8

40

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

Sabina answered 22/10, 2013 at 13:12 Comment(2)
Have you checked the symlinks in .../site-enabled/ and made sure they are correct?Cornflakes
Yes.I played around a little bit with the mysite.localhost.cong file and i got it to work(more or less) but now other folders in the /var/www are not accesible if they are not on localhost and they give me like on localhost/test insted of loading index.php it gives me 404 not found.The current versionof mysite.localhost.conf is: <VirtualHost *:80> ServerAdmin [email protected] ServerName mysite.localhost ServerAlias mysite.localhost # Indexes + Directory Root. DirectoryIndex index.php DocumentRoot /var/www/mysite/public_html </VirtualHost>Sabina
I
56

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"
Instructions answered 23/10, 2013 at 4:22 Comment(5)
I have Apache 2.4.6 None of your provided suggestions are working/already configured as suggested.Monogamy
Which linux os are you using and what is the output getting after doing the above steps?Instructions
ran into this too. changing all my sites-enabled symlinks to .conf fixed it.Debit
If only Apache's error log had complained about the sites-enabled it was skipping, a lot of time would have been saved for people upgrading. Thanks for the heads-up.Crippen
THANK YOU @AnjithKP, adding "IncludeOptional sites-enabled/*.conf" was what fixed it for me after hours of trying to figure it out!Sadiras
S
14

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.

Sabina answered 22/10, 2013 at 14:53 Comment(3)
I think you are missing NameVirtualHost *:80 in your main config file. This will more or less disable name based virtual hosts (*:80).Cornflakes
When you updated to 13.10, did you keep the old apache config file? The NameVirtualHost has no effect and is deprecated in apache 2.4.Langer
You sir are a good person, thank you very much, even though this makes no sense to me cause I'm running debian, it fixes all of the persisted problems I had. Thank you again!Systematist
F
6

I had a same issue ,but None of these above postings worked for me . Later I read and reviewed each and every configuration files of Apache and PHP .

I could figure out that in apache2.conf( in ubuntu 13.10 ) there is a flag called

HostnameLookups off

By Default this will be set to off, I changed this to

HostnameLookups on

By doing so Apache started piking up my host entries and vhost config well .

Also Below is my actual Vhost file . which I used to make it working

Offcourse I too recommend adding Require all granted with in the Vhost directive .

<VirtualHost *:80>
    ServerName test.yoursite.domain.in
    DocumentRoot path_to_code_base/public
    <Directory path_to_code_base/public>
        Options -Indexes
        Require all granted
        DirectoryIndex index.php
        AllowOverride All
    </Directory>
    ErrorLog  /path_to_code_base/logs/error.log
    LogLevel warn
    CustomLog /path_to_code_base/logs/access.log  combined
</VirtualHost> 

I am posting this to help others who does not want to waste there time in downgrading Ubuntu to 13.04 from 13.10 .

I do-not see this any blogs , I also could not understand what actually the meaning of hostnameLookups is .

Hope this helps .

Feudatory answered 15/2, 2014 at 17:8 Comment(4)
I don't think HostnameLookup would help. According to the documentation above it in apache2.conf it controls if apache should look up the hostname of the CLIENTs.Slipper
@Slipper How can apache look host name on the client, when it is running in the server. Even I had the same illusion after reading the documentation, Looks like there is some thing wrong in the documentation there which is misleading every one. The configuration which I have posted here is the one which I am currently using and its working fine.Its my perception to switch that flag onFeudatory
It means that it looks up the host name OF the client, that is the reverse DNS of the clients IP. For me VirtualHosts work (with apache 2.4) without that option on.Slipper
After hours of chasing, this got me where I needed to be. I ran service apache2 restart just to make sure, and things just worked.Venlo
C
2

For Apache 2.4.6 in Ubuntu 13.10,

You will have

/etc/apache2/apache2.conf
/etc/apache2/sites-available/000-default.conf

And

/etc/apache2/sites-enabled/000-default.conf points to /etc/apache2/sites-available/000-default.conf

Now, edit apache2.conf and add

<Directory /home/my_site/public_html/>
    #YOUR SETTINGS
</Directory>

and edit sites-available/000-default.conf and change <VirtualHost *:80> to <VirtualHost localhost:80> to make apache listen localhost (on port 80) for your default settings.

Now to make mysite.localhost work, add this to sites-available/000-default.conf

<VirtualHost mysite.localhost:80>
    ServerName mysite.localhost

    ServerAdmin [email protected]

    DocumentRoot /home/my_new_site_public_html

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Now edit your /etc/hosts/ file and change the IP of mysite.localhost from 127.0.1.1 to 127.0.0.1

Now visit http://mysite.localhost & http://localhost

:)

Cuirbouilli answered 23/12, 2013 at 12:24 Comment(0)
M
1
<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>

In my case I just replaced <VirtualHost *:80> to <VirtualHost mysite.localhost:80> after much trial and error

I hope this helps.

Regards,

Monogamy answered 8/4, 2014 at 6:48 Comment(0)
B
0

Execute:
vim can be change with your favourite text editor like nano, pico and etc.

vim /etc/apache2/apache2.conf

Original file:

# Sets the default security model of the Apache2 HTTPD server. It does
# not allow access to the root filesystem outside of /usr/share and /var/www.
# The former is used by web applications packaged in Debian,
# the latter may be used for local directories served by the web server. If
# your system is serving content from a sub-directory in /srv you must allow
# access here, or in any related virtual host.
<Directory />
        Options FollowSymLinks
        AllowOverride None
        Require all denied
</Directory>

<Directory /usr/share/>
        AllowOverride None
        Require all granted
</Directory>

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

Change None to All

Edit file:

# Sets the default security model of the Apache2 HTTPD server. It does
# not allow access to the root filesystem outside of /usr/share and /var/www.
# The former is used by web applications packaged in Debian,
# the latter may be used for local directories served by the web server. If
# your system is serving content from a sub-directory in /srv you must allow
# access here, or in any related virtual host.
<Directory />
        Options FollowSymLinks
        AllowOverride All
        Require all denied
</Directory>

<Directory /usr/share/>
        AllowOverride All
        Require all granted
</Directory>

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>
Braunschweig answered 14/3, 2014 at 9:26 Comment(0)
A
0

For Kubuntu 14.04 & Apache 2.4.7

After trying the suggestions above, and still bumping on permissions issues, a "chmod 755 $HOME" worked for me. Not to be used on a multi-user system.

Armil answered 27/6, 2014 at 5:26 Comment(0)
A
0

Just a note for people pulling out their hair about this topic, you'll need to use sudo for all of these settings to take place if you're using an AWS instance.

sudo a2ensite example.com

Keep in mind you need to do this for even restarting apache. If you don't see your changes taking place, this is likely the culprit.

sudo service apache2 restart
Anesthesia answered 27/2, 2015 at 16:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.