Register

Setup Multiple Sites Without a static IP

Site Admin
Posts: 1
Joined: Sun Apr 14, 2013 3:19 pm

Setup Multiple Sites Without a static IP

Postby boosargant » Thu Apr 25, 2013 11:18 am

this is mirrored from http://www.raspie.co.uk

his site seems to be down a lot so thought post it here.

credit goes to james.

In this tutorial I will hopefully teach you how to setup your pi as a LAMP server and host multiple sites.

Brief Overview/what will be covered:

This forum and website is hosted from my home on my raspberry pi, I do not have a static ip address as my ISP (TalkTalk) will not provide them.

You have no static ip? How am I here? - Its called Dynamic Dns. I use NO-IP, this is running on my router however it is possible to install this onto your Raspberry Pi if your router does not support it. :)

How do I get a website address? (domain name) E.G http://www.mysite.co.uk - You buy one, there are hundreds of providers! CrazyDomains seem to be the cheapest. Google them for more information.

How do I point the domain to my Raspberry Pi? - You use a DNS server, for this site I have used Hurricane Electric's free DNS hosting and have pointed the sites to the Dynamic Dns hostname Using CNAME records.

How does my Raspberry Pi understand what site it should show when I go to http://www.mydomain.com if I am hosting multiple sites? - Its called a virtual host, I won't go into much detail here as things get even more confusing! Google is your friend if you need more information.

Does wordpress run on a raspberry pi? - Yes, but not very well. The database requests are very CPU insensitive, you may have realized that the forum is much faster than the actual site. This proves this.

Ok now I have covered a few points lets continue to get this setup!

Installing LAMP:

LAMP is a combination of free, open source software. The acronym LAMP refers to the first letters of Linux, Apache HTTP Server, MySQL (database software), and PHP, Perl or Python - The necessarily software to run a fully functional webserver.

Please note this whole tutorial is based of the fact that you are running a Debian based distro.

Run the following to install LAMP:

Update your packages

apt-get update

Install apache

apt-get install apache2

Install PHP

apt-get install php5 libapache2-mod-php5

Install MySql

apt-get install mysql-server mysql-client php5-mysql

Restart the apache service

/etc/init.d/apache2 restart

If you got no errors that's LAMP installed!

Now you need a way to point your domains to your pi.

Setup no-ip:
Skip this if there is an option on your router for dyndns.

1) Sign up here: http://www.noip.com/
2) Create a host
3) on your raspberry pi run the following:

mkdir noip && cd noip . && wget http://www.no-ip.com/client/linux/noip-duc-linux.tar.gz

4) Compile NO-IP

make && make install

5) add your login details when it asks you for them.
6) Make NO-IP run at startup

echo '/usr/local/bin/noip2' >> /etc/rc.local

Have an issue? There's a more detailed guide here http://www.noip.com/support/guides/upda … lient.html

DNS Server:
Presuming you already have your domain you can continue to setup a DNS server.

I have found that the Hurricane Electric DNS server is best for the job! Sign up here: https://dns.he.net

Once you have signed up click add domain and type your domain name E.G. example.com

1) Login to your domain control panel E.G CrazyDomains and look for nameservers. Add the following:

ns1.he.net
ns2.he.net
ns3.he.net
ns4.he.net
ns5.he.net
ns6.he.net

2) Go back to your Hurricane Electric control panel and click "NEW CNAME" add one for www > example.no-ip.org and one for @ > example.no-ip.org
Replacing example.no-ip.org with the NO-IP hostname you setup earlier.

Repeat this for the domains you will be hosting (only if you are hosting multiple sites)

within 10 minutes - 24 hours the DNS will propagate across the internet. You can see if this has worked by visiting your domain. when it is working you should be greeted by:

"IT WORKS!

This is the default web page for this server.

The web server software is running but no content has been added, yet."

your webserver is now setup! If you only plan on hosting one website you can now add your content to /var/www

If you plan on hosting multiple sites continue to follow this guide.

Now we will setup the virtual hosts.

We need to make a few directories to store the sites you will be hosting

mkdir /home/www

Replace http://www.website1.com, http://www.website2.com etc with your domain names.

1st Domain


mkdir /home/www/www.website1.com

/home/www/www.website1.com/htdocs
/home/www/www.website1.com/cgi-bin
/home/www/www.website1.com/logs

2nd Domain


mkdir /home/www/www.website2.com

/home/www/www.website2.com/htdocs
/home/www/www.website2.com/cgi-bin
/home/www/www.website2.com/logs

Now its time to configure Vhosts.

Virtual Hosts:

First we need to Enable Virtual Hosts:

touch /etc/apache2/conf.d/virtual.conf

nano /etc/apache2/conf.d/virtual.conf

Then add the following:

# We're running multiple virtual hosts.
#
NameVirtualHost *

Once this is done we need to make the individual host configuration files.

1) Make the following files replacing http://www.website1.com with your domain name. You need to create one of these config files for each domain that you will be hosting.

touch /etc/apache2/sites-available/www.example.com && nano /etc/apache2/sites-available/www.example.com

You then need to edit the config file. Here is the one this site uses as an example:

<VirtualHost *>
ServerAdmin james@jmdawson.co.uk
ServerName http://www.raspie.co.uk]www.raspie.co.uk
ServerAlias raspie.co.uk

# Indexes + Directory Root.
DirectoryIndex index.php
DocumentRoot /home/www/www.raspie.co.uk/htdocs/

# CGI Directory
ScriptAlias /cgi-bin/ /home/www/www.raspie.co.uk/cgi-bin/
<Location /cgi-bin>
Options +ExecCGI
</Location>


Repeat step one for each site you will be hosting.

To enable these sites now run

a2ensite http://www.website1.com

Once you have done this for the multiple sites that you will be hosting type

/etc/init.d/apache2 reload

You can now add content to your domains in /home/www/www.website1.com/htdocs

I understand this is a very confusing guide. If it doesn't help you or you don't understand it then you probably shouldn't be reading it

Return to Server's

Who is online

Users browsing this forum: No registered users and 1 guest