User Tools

Site Tools


hosting_more_than_one_website_on_the_same_apache2_server

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
hosting_more_than_one_website_on_the_same_apache2_server [2016/07/24 19:15] – created walkeradminhosting_more_than_one_website_on_the_same_apache2_server [2023/03/09 22:35] (current) – external edit 127.0.0.1
Line 1: Line 1:
-====== Restart Apache2 Web Server ======+====== Hosting more than one website on the same Apache2 Server (Raspbian) ======
 \\  \\ 
 \\  \\ 
-From time to time it might be necessary to restart the Apache Web Servernormally this is required after configuration changeor if a site has stopped.+Setting up Apache2 to host a single website is fairly straightforward. However sometimes it is required to host 2 or more sites from a single Apache2 serverand for this a little extra configuration is required
 +\\  
 +\\  
 +In the folder //**/etc/apache2**// there is file called //**apache2.conf**//. We need to edit this file. 
 +\\  
 +\\  
 +        sudo nano /etc/apacde2.conf 
 +\\  
 +In the apache2.conf look for the section that points to the default site (which is normally /var/www) 
 +\\  
 +        <Directory /var/www/> 
 +                Options Indexes FollowSymLinks 
 +                AllowOverride All 
 +                Require all granted 
 +        </Directory> 
 +\\  
 +We need to copy and paste this section for each site we wish to create.\\  
 +\\  
 +In this example we will have two websites, site one and site2, and they are located in the following place: 
 +\\  
 +\\  
 +/home/pi/site1\\  
 +/home/pi/site2\\  
 +\\  
 +\\  
 +So we need to add two sections to the /etc/apache2.conf 
 +\\  
 +        <Directory /home/pi/site1/> 
 +                Options Indexes FollowSymLinks 
 +                AllowOverride All 
 +                Require all granted 
 +        </Directory> 
 + 
 +        <Directory /home/pi/site2/> 
 +                Options Indexes FollowSymLinks 
 +                AllowOverride All 
 +                Require all granted 
 +        </Directory> 
 +\\  
 +Save this file and exit back to the command line. 
 +\\  
 +\\  
 +now we need to navigate to the folder //**/etc/apache2/sites-enabled**// and edit the file //**000-default.conf**// 
 +\\  
 +        sudo /etc/apache2/sites-enabled/000-default.conf 
 +\\  
 +Use the hash # to comment out every line 
 +\\  
 +\\  
 +Now add the following: 
 +\\  
 +    <VirtualHost *:80> 
 +        ServerAdmin al@nwalker.co.uk 
 +        ServerName site1.alanwalker.eu --- (this has to match the url of your website) 
 +        DocumentRoot /home/pi/site1 --- (this is where your website is physically in linux) 
 +        DirectoryIndex index.html --- (this is the first page of your website) 
 +    </VirtualHost> 
 +    <VirtualHost *:80> 
 +        ServerAdmin al@nwalker.co.uk 
 +        ServerName site2.alanwalker.eu --- (this has to match the url of your website) 
 +        DocumentRoot /home/pi/site2 --- (this is where your website is physically in linux) 
 +        DirectoryIndex index.html --- (this is the first page of your website) 
 +    </VirtualHost> 
 +\\  
 +Don't forget to restart the apache web server: 
 +\\  
 +        sudo /etc/init.d/apache2 restart 
 +\\  
 +\\  
 +Now if I navigate to //**site1.alanwalker.eu**// I get: 
 +\\  
 +\\  
 +{{:site1.png|}} 
 +\\  
 +\\  
 +\\  
 +\\  
 +If I navigate to //**site.alanwalker.eu**// I get: 
 +\\  
 +\\  
 +{{:site2.png|}} 
 +\\  
 +\\  
 + 
hosting_more_than_one_website_on_the_same_apache2_server.1469384104.txt.gz · Last modified: 2023/03/09 22:35 (external edit)