Home RASPBERRY PI How to set up a web server on the Raspberry Pi

How to set up a web server on the Raspberry Pi


In this article, I will show you how to set up a Web server at home using the Raspberry Pi. Using this, you can create your own personal Raspberry Pi Web server, which allows you to access your files from anywhere in the world using the Internet.

No need to worry about DDNS client, you can get it for free from no-ip.com. We will use Apache, PHP and MySQL to build this Raspberry Pi web server. So, let’s get started!

Requirements for this project

  • Raspberry Pi 3/2B+ Buy Here
  • WIFI router with access to the internet
  • WIFI dongle for Raspberry Pi or LAN cable
  • Rasbian OS loaded in Micro SD Card

Note: If you don’t know how to install Rasbian in Raspberry pi then Please visit this link below

How will it get to work in Raspberry Pi?

We will first install and test Apache, PHP and MySQL, then set your Raspberry Pi as a local server. When you do this, you can convert the local server to a web server using port forwarding technology.

After port forwarding, your raspberry pie will be accessible over the internet because your router will point to it. Check out this block diagram for a detailed step-by-step process to build your Raspberry Pi web server.

Configuration of Raspberry Pi

Remember, if you mess up along the way, just reformat your card, reload the disk image, and start over. No harm no foul.

After powering the Raspberry Pi with the SD card inserted, you will see that the system automatically lists information about the operating system and peripherals. You do not need to know what this project means, but I will never stop you from reading it and learn your raspberry pie for your own benefit!

After the boot Operating system should be loaded over there , you are prompted to use the raspi-config window. Here you should make the following changes:

  • Expand the root partition so that all space on the SD card is available.
  • Set the time zone.
  • Enable SSH server (found in Advanced Options)
  • Disable boot to the desktop, we just want to use the terminal environment to configure this program.
  • Update your Raspberry Pi (found in Advanced Options)
  • Restart your Raspberry Pi at this time.
  • Restart your raspberry pie with the following code:

sudo restart

  • I also do not recommend overclocking your Pi project, setting the perfect work by default, overclocking will reduce the overall hardware life. Or, to use this window any time after initial configuration, use the following command: sudo raspi-config

Boot Up Raspberry pi/ Access Shell

Sp after setting up run the following commands to ensure your OS is up to date (hit enter after each and wait until one runs to completion before starting another):

sudo apt-get update

sudo apt-get upgrade

Installing Apache Server

To install Apache and PHP, use the following command:

sudo apt-get install apache2 php5 libapache2-mod-php5

You will be prompted if you would like to continue, type y for yes and hit enter to continue. This process may take a few minutes.

If you get any errors, run the following commands:

sudo groupadd www-data
sudo usermod -g www-data www-data

Restart Apache server with the following command:

sudo service apache2 restart

So after entering the web browser of your choice, enter the IP address of the Raspberry Pi in the address bar. (If you do not remember the IP address, use the ifconfig command earlier in this tutorial.

You should see a web page that says “It works!” As shown below

Install SQL

How to set up a web server on the Raspberry Pi

Install MySQL with the following command:

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

So after it you will be asked if you want to continue, type y for yes and hit enter to continue.

How to set up a web server on the Raspberry Pi

During installation, you are prompted to set a new password for the MySQL root user. Enter the password of your choice and confirm the password again to continue the installation.


Use the following command to change the root password of the Raspberry Pi:

sudo passwd root

Add the user root as mod using the following command:

sudo usermod -L root

At this point, your server should function properly and you should be able to transfer files over the FTP using the server’s IP address and use port 21 to connect.

I’ll detail how to add an HTML resume to my Pi when I have another free time, but now you can at least install all the right components on your machine and start exploring the possibilities yourself!

You may also like to read these useful awesome articles,

Is Asus Tinker Board is Better than a Raspberry Pi?

All You Need to Know about Raspberry Pi Zero W

Hope my article “How to set up a web server on the Raspberry Pi” helps you to set up a web server on the Raspberry Pi. if you have any query, feel free to comment.