LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   Having trouble setting up Apache virtual hosts on Ubuntu 12.04 (http://www.linuxquestions.org/questions/linux-server-73/having-trouble-setting-up-apache-virtual-hosts-on-ubuntu-12-04-a-4175431510/)

gunnarflax 10-10-2012 11:19 AM

Having trouble setting up Apache virtual hosts on Ubuntu 12.04
 
Hello everyone! I'm having some trouble configuring apache to properly serve my two websites which I have on a personal server. I'm running Ubuntu 12.04.1 x64 Server Edition.

I have two sites in /var/www/ which I'll refer to as site1.com and site2.com. It all started out with me being able to view both site1 and site2 perfectly but when attempting to access my phpmyadmin installation through http://localhost/phpmyadmin I got permission denied errors.

I'm not entirely sure that my configuration is correct since I haven't configured this before, I've just dived into all the documentation I've been able to find. This is how it looks like today.

/var/www/:
Code:

--site1.com
----web -> /usr/share/wordpress
----uploads
--site2.com
----web -> /usr/share/wordpress
----uploads

with the permissions for each directory:
Code:

drwxrwxr-x 3 root www-data uploads
lrwxrwxrwx 1 root www-data web

I have set up a global configuration in httpd.conf (correct me if this is wrong) with basically the settings that were in the default-site bundled with lampp:
Code:

ServerSignature Off
ServerTokens Prod

NameVirtualHost *:80

<ifmodule mod_ssl.c>
        NameVirtualHost *:443
</ifmodule>

<Directory />
        Options -Indexes FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
</Directory>

<Directory /var/www/>
        Options -Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        Allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory /usr/lib/cgi-bin/>
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
</Directory>

Alias /doc/ /usr/share/doc/
<Directory /usr/share/doc/>
        Options -Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128       
</Directory>

The NameVirtualHost setting gives me an error on startup of apache but I don't know if it matters:
Code:

apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[Wed Oct 10 16:52:28] [warn] NameVirtualHost *:80 has no Virtualhosts

and the site specific configuration (the same for both sites except for the FQDN):
Code:

<VirtualHost *:80>
        ServerAdmin site1@gmail.com
        ServerName site1.com
        ServerAlias www.site1.com

        LogLevel warn
        ErrorLog /var/log/apache2/site1.com/error.log
        CustomLog /var/log/apache2/site1.com/access.log combined

        DocumentRoot /var/www/site1.com/web
</VirtualHost>

(Do the <Directory> options, like -Indexes, need to be specified here as well?)

My /etc/hosts configuration looks like this:
Code:

127.0.0.1        localhost
127.0.1.1        servername

#Virtualhosts
127.0.0.1        www.site1.com
127.0.0.1        site1.com
127.0.0.1        www.site2.com
127.0.0.1        site2.com

# The following lines are desirable for IPv6 capable hosts
::1    ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

All help is welcome, I look forward to learning how I can secure the server better!

gunnarflax 10-10-2012 12:40 PM

Nevermind, I got it working! I removed all the configuration done in httpd.conf and just set the standard parameters in /etc/apache2/conf.d/security which seemed to be best practice. Then I added the <Directory> configurations from /etc/apache2/sites-available/default to each site's configuration but changed <Directory /var/www/> to <Directory /var/www/site1.com/web/> which I hadn't done before and now both my sites + phpmyadmin works! Huzzah!


All times are GMT -5. The time now is 05:28 AM.