Hosting website using Raspberry Pi as Server

Hosting website using Raspberry Pi as Server
nisrasp.serveblog.netYour DNS Public IP

Step 1: Install LAMP

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 your public IP address (this can be found by googling whatsmyip, if it not click on modify and make modifications in the IPv4 Address box.

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 in the answer section:


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/

Paste the following

<head><title>Self-Hosting on Raspberry Pi</title></head>
<p>This is my self-hosting website using Raspberry Pi</p>

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/

Edit the file:

sudo nano /etc/apache2/sites-available/

to look like this:

<VirtualHost *:80>
DocumentRoot /var/www/html/
ErrorLog ${APACHE_LOG_DIR}/error.log	# Change ${APACHE_LOG_DIR} to you appropiate directory
CustomLog ${APACHE_LOG_DIR}/access.log combined	# Change ${APACHE_LOG_DIR} to you appropiate directory

Enable the website:

sudo a2ensite

Reload Apache:

sudo service apache2 reload

Now edit the /etc/hosts file:

sudo nano /etc/hosts

Add a line with your IP address and domain name:

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.