The Raspberry Pi is a very neat device. I was very excited to get my own a few months back. My plan was to run it for Plex on my unused monitor. Later I purchased the Google ChromeCast which replaced the Pi and it has been collecting dust ever since. Now I decided to make use of the Raspberry Pi to run a web server for working on my projects locally. Let’s get started!


The Process

Apache Installation

First, we need to update & upgrade the system with the following codes

sudo apt-get update
sudo apt-get upgrade

Then we need to install apache2 package for Apache web server

sudo apt-get install apache2 -y

You can test your web server running from the Raspberry Pi’s browser typing “localhost”. You should see a placeholder page showing that the server works fine. For testing on a device on your connected network, you will need to visit the host IP of your Raspberry Pi. Check the IP typing the following code

hostname -I

PHP Installation

Now that the Apache Web Server is running, you can run basic static files. We need to install PHP for running dynamic web pages. Type the following command to install required packages for PHP

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

MySQL Installation

The next thing we need to install is MySQL server for the database. Here is the code to install it.

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

Be sure to remember the root password that you enter while installing MySQL Server, you will need that later.

For MySQL interacting with Python, we need to install another package

sudo apt-get install python-mysqldb

phpMyAdmin Installation

Now we are going to install phpMyAdmin. Better GUI for managing databases

sudo apt-get install phpmyadmin

You will be asked to enter the password for root of MySQL server. Enter that and also give a password for phpMyAdmin (it can be different or same as the other one)

Now we will need to make some changes on apache2.conf file for phpMyAdmin

sudo nano /etc/apache2/apache2.conf

Write the following line at the bottom of the file and save the file (Ctrl + X > Y > Enter).

Include /etc/phpmyadmin/apache.conf

Now Apache needs to be restarted to run everything in order to the changes.

sudo /etc/init.d/apache2 restart

Yes! phpMyAdmin should be accessible from “localhost/phpmyadmin” or “YOUR_RASPBERRY_PI_IP/phpmyadmin” on the browser.

FTP Server Installation

We are close to having all the things for a good web server. Now we need to install FTP. I used ProFTPD for FTP.

sudo apt-get install proftpd

This will ask you to choose init.d or standalone, choose any one of them but I used standalone for this tutorial.

Next, we are going to change the config of proftpd.

sudo nano /etc/proftpd/proftpd.conf

You need to change the following lines. The ServerName should be the IP of your Raspberry Pi. Here we used Yours can be different.

Server Name ""

Uncomment the # in front of DefaultRoot text. This is a good practice.

# Use this to jail all users in their homes

Next, we restart proftpd service

sudo service proftpd restart

To make sure that FTP service runs automatically at startup, enter the following code

update-rc.d proftpd defaults

Now we need to add a user for FTP. I am using “real” as the username. You can choose anything you like.

sudo useradd real

Set password the user with the following command

sudo passwd real

Assign the “/var/www/html/” directory to the user. This is the directory where the files will need to be added and the user will see this directory when they login using FTP client. Ignore message that says the directory already exists

sudo usermod -m -d /var/www/html real

Run the following commands to give permissions to the user on the html folder.

cd /var/www
sudo chown real:real -R html

FTP setup is done at this point. However, I found it is easier for me to do one extra step to avoid permissions. I edited apache2.conf file to make Apache use the user and group that we created.

sudo nano /etc/apache2/apache2.conf

Look for the following line and add # in front of User and Group lines. After editing, it should look like the following

# These need to be set in /etc/apache2/envvars
User real
Group real

[av_hr class=’short’ height=’50’ shadow=’no-shadow’ position=’center’ custom_border=’av-border-thin’ custom_width=’50px’ custom_border_color=” custom_margin_top=’30px’ custom_margin_bottom=’30px’ icon_select=’yes’ custom_icon_color=” icon=’ue808′ font=’entypo-fontello’ custom_class=”]

Now you can enjoy your very own web server running on a Raspberry Pi! Share your thoughts on the comment section. If you face any issues, let me know as well 😀