Need to find something?

Raspberry pi cover

Raspberry Pi Web Server – Apache, PHP, MySQL, phpMyAdmin & FTP

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!

raspberry-pi-web-server

Apache Installation

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

sudo apt-get update
sudo apt-get upgradeCode language: Bash (bash)

Then we need to install apache2 package for Apache web server

sudo apt-get install apache2 -yCode language: Bash (bash)

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 -ICode language: Bash (bash)

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 -yCode language: Bash (bash)

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 -yCode language: Bash (bash)

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-mysqldbCode language: Bash (bash)

phpMyAdmin Installation

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

sudo apt-get install phpmyadminCode language: Bash (bash)

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.confCode language: Bash (bash)

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

Include /etc/phpmyadmin/apache.confCode language: Bash (bash)

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

sudo /etc/init.d/apache2 restartCode language: Bash (bash)

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 proftpdCode language: Bash (bash)

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.confCode language: Bash (bash)

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

Server Name "192.168.1.88"Code language: Bash (bash)

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

# Use this to jail all users in their homes
DefaultRootCode language: Bash (bash)

Next, we restart proftpd service

sudo service proftpd restartCode language: Bash (bash)

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

update-rc.d proftpd defaultsCode language: Bash (bash)

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

sudo useradd realCode language: Bash (bash)

Set password the user with the following command

sudo passwd realCode language: Bash (bash)

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 log in using FTP client. Ignore the message that says the directory already exists

sudo usermod -m -d /var/www/html realCode language: Bash (bash)

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

cd /var/www
sudo chown real:real -R htmlCode language: Bash (bash)

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.confCode language: Bash (bash)

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 ${APACHE_RUN_USER}
# Group ${APACHE_RUN_GROUP}
User real
Group realCode language: Bash (bash)

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 😀

Last Updated: September 3, 2023

Al-Mamun Talukder

About Al-Mamun Talukder

WordPress Developer. Minimalist Designer. Tech Enthusiast. Music & Movie Freak. Loves Cars. Founder of WolfDevs.

Connect with me: Upwork, GitHub, Facebook, Twitter

2 comments

  • Good, I tried and all obviously works.
    On minor side, I think line:
    update-rc.d proftpd defaults
    works for me only when I start it with ‘sudo’.

  • Toufiq Ibna Mustafiz

    wow, joss

Leave your comment