Difference between revisions of "Apache"

Jump to navigation Jump to search
4,184 bytes added ,  17:28, 6 February 2012
Added "Host Multiple Sites"
m (Added php path)
(Added "Host Multiple Sites")
Line 11: Line 11:
| <code> /etc/php5/apache2 </code> || PHP config file
| <code> /etc/php5/apache2 </code> || PHP config file
|}
|}
= Configuration =
== Host Multiple Sites ==
There are various methods that can be used to enable you to host multiple websites on the same server.  This is but one, and allows you to host different domains on the same server.
You'll need a publicly accessible server running Apache, and the ability to create DNS entries for the domains you want to host.  In this example we're creating two websites, called ''web1'' and ''web2'', on a server with IP address ''123.10.10.2''
Before you configure the webserver, you need to set-up DNS correctly, for this example this could be done in one of two ways...
* A records only
** <code> web1.domain.com -- A record --> 123.10.10.2</code>
** <code> web2.domain.com -- A record --> 123.10.10.2</code>
* A and CNAME records
** <code> web.domain.com -- A record --> 123.10.10.2</code>
** <code> web1.domain.com -- CNAME record --> web.domain.com</code>
** <code> web2.domain.com -- CNAME record --> web.domain.com</code>
...how you choose to do it is up to you, and depends on what changes you might expect to make down the line.  If you have a small set-up its probably easiest to go with purely A-records, but where you have a larger number of websites and web-hosts, it can be easier to manage with all your web-hosts having A-records and all web-sites having CNAME-records pointing to the host that they're running from.
Either way, you should be able to ping the addresses of either website and get the correct IP address back.
Next you should check that you web server is working correctly.  If its a new install, you should be able to browse to the server's IP address and get a basic "It works!" page back.  This site, or any site that's using the root of your web-server will need to be (re)moved.
Now to create the web-sites...
# '''If you have an existing site that's served from the root of your webserver, this needs to be removed 1st.''' So to remove the default site that's installed with Apache...
## Disable the web-site by removing the link to its config from <code>sites-enabled</code>
##* <code> rm /etc/apache2/sites-enabled/000-default</code>
##* <code> service apache2 restart</code> (you may get a warning about ''no VirtualHosts'')
## Test by browsing to your web-server's IP address, no webpage should be returned
# '''Now create the required folders...'''
## Create sub-folders for your web-sites, eg
##* <code> mkdir /var/www/web1.domain.com </code>
##* <code> mkdir /var/www/web2.domain.com </code>
## Create sub-folders for your web-sites' logs, eg
##* <code> mkdir /var/log/apache2/web1.domain.com </code>
##* <code> mkdir /var/log/apache2/web2.domain.com </code>
# '''Now create the required configs...'''
## Create a config for web1, using the example file contents below
##* <code> vi /etc/apache2/sites-available/web1.domain.com </code>
## Create a config for web2, using the example file contents below, but edit so that web1 becomes web2
##* <code> vi /etc/apache2/sites-available/web2.domain.com </code>
# '''Now create some test content, and enable...'''
## Copy the default index.html to your new web-site folders, and edit so that they identify the web-site they're in
##* <code> cp /var/www/index.html /var/www/web1.domain.com/ </code> and edit
##* <code> cp /var/www/index.html /var/www/web2.domain.com/ </code> and edit
## Enable the websites
##* <code> cd /etc/apache2/sites-enabled </code>
##* <code> ln -s ../sites-available/web1.domain.com web1.domain.com</code>
##* <code> ln -s ../sites-available/web2.domain.com web2.domain.com</code>
## Restart the Apache service to apply
##* <code> service apache2 restart</code>
# '''Test - you should now have two separately accessible websites..!'''
<VirtualHost *:80>
        ServerAdmin info@domain.com
        ServerName  web1.domain.com
        # Indexes + Directory Root.
        DirectoryIndex index.php
        DocumentRoot /var/www/web1.domain.com/
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        # Logfiles
        ErrorLog  /var/log/apache2/web1.domain.com/error.log
        CustomLog /var/log/apache2/web1.domain.com/access.log combined
</VirtualHost


== Log Rotation ==
== Log Rotation ==
Line 40: Line 109:
#* <code> service apache2 restart </code>
#* <code> service apache2 restart </code>


== Troubleshooting ==
= Troubleshooting =
=== NameVirtualHost *:80 has no VirtualHosts ===
== NameVirtualHost *:80 has no VirtualHosts ==
On restarting Apache you get presented with the following warning
On restarting Apache you get presented with the following warning
  [Thu Jan 12 10:58:20 2012] [warn] NameVirtualHost *:80 has no VirtualHosts
  [Thu Jan 12 10:58:20 2012] [warn] NameVirtualHost *:80 has no VirtualHosts

Navigation menu