Hosting website using Raspberry Pi as Server


Step 1: Install LAMP

Type the following command in the terminal:

sudo apt install apache2 mysql-server php libapache2-mod-php7.0 -y

Step 2: Get a free Domain

Usually domain names cost money to register, but you can get a free one on You should signup first.

Then you can type whatever name you want in the ” Hostname ” box and then choose your domain from the ” Domain ” dropdown menu.

Also, make sure the ” Record Type ” is ” A

Then click on ” Add Hostname “.

From the ” Dashboard ” you should see ” Active “. Click on it and you’ll see the domain name with the url it is assigned.

Make sure the ” URL ” is the same as you IP address (this can be found by googling ” whatsmyip “, if it not click on modify and make modifications in the ” IPv4 Address ” bix.

Step 3: Configure DNS

To use your own domain on your own web server you’ll have to configure Apache to accept web request for your domain.

Install dns utilities:

sudo apt-get install dnsutils

Your websites DNS should have an ” A ” record, to confirm type:


Something like this should appear:


It means that would be directed to the server with IP address

Step 4: Configure Apache

Now, we will make Apache accept web request from and from what directory to serve content when receiving requests.

Create a directory for

 sudo mkdir -p /var/www/html/

Create an example index.html file:

sudo nano /var/www/html/

Type: This is my self-hosting website using Raspberry Pi

Finally, give some filesystem permission:

 sudo chmod -R 755 /var/www/html/ 

Set up a Virtual Host file for Apache for our domain

 sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/ 
 sudo nano /etc/apache2/sites-available/ 

Edit the file to look like this:

ServerAdmin [email protected]
DocumentRoot /var/www/html/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

Reconfigure and reload Apache:

sudo a2ensite
sudo service apache2 reload

Now edit the /etc/hosts file by adding a line with your IP address and domain name:

sudo nano /etc/hosts

Add the line:

Step 5: Configure Router

I’ll explain this step in general as each router has its own kind performing the port forwarding.

Well you should create a forward rule

(format: "name" - TCP/UDP - start port - end port - 192.168.x.x (replace with that of your server)) 

For HTTP (use the above as a guide to understand):

"HTTP" - TCP - 80 - 80 - 192.168.x.x

If you can’t connect, consult your router’s instruction manual or Google search it.

Leave a Reply

Your email address will not be published.