Step 2b Installing and configuring PHP, MySQL & phpmyadmin with Apache
Now Time to install PHP
To install PHP, we will need first to get the PHP package, so, let’s download the PHP7 module for apache. To do this enter the following.
sudo apt-get install php7.0 libapache2-mod-php7.0 -y
Now we can place PHP files in the html folder, and they will be processed and displayed. For example let’s make a file called example.php
sudo nano /var/www/html/example.php
In this file add the following:
<?php
echo "Today's date is ".date('Y-m-d H:i:s');
?>
There we have it a fully working Apache2 + PHP Raspberry Pi Web Server working. but we cannot see PHP admin or visual interface as there is no database or DB management tool for it. Hence we install MySQL and PHPmyadmin.
Installing Raspberry Pi MySQL
First let’s install the MySQL server onto the Raspberry Pi.
sudo apt-get install mysql-server
You will be prompted to enter a password for the root user. Make sure you write this down as we will need to use this to access the MYSQL server and connect PHPMyAdmin to it.

Installing Raspberry Pi PHPMyAdmin
You will find that installing Raspberry Pi PHPMyAdmin is very easy.
I will go on the assumption you have already set up your web server and setup PHP for it. Please note that these steps will differ a bit if you are using Apache or NGINX.
Now let’s install the PHPMyAdmin package, you can do this by entering the following command on your Raspberry Pi.
sudo apt-get install phpmyadmin
It will now begin to install. You will be presented with a screen asking the type of web server you want it to run off. Select apache2 even if you are using NGINX since this doesn’t hugely matter for us.
Next, we will need to configure PHPMyAdmin to connect to our SQL database server. (The one we set up previously in installing the Raspberry Pi MYSQL step or the web server). To do this select yes at the next prompt.

The setup tool will now ask for a password, enter the one you set for root when setting up your SQL Server, this is needed for phpMyAdmin to talk with the SQL Server and manage your databases.
Next, it will ask you to set a password for PHPMyAdmin itself. It is best to set this password to something different to your root SQL password. Make sure you remember it as this is the password you will need to access the interface.
With that done we can now proceed to configure our Apache for use with phpMyAdmin.
To begin setting up Apache for use with phpMyAdmin enter the following command into the terminal:
sudo nano /etc/apache2/apache2.conf
Now at the bottom of this file enter the following line:
Include /etc/phpmyadmin/apache.conf
Once done save & exit by pressing CTRL +X and then y.
Now restart the Apache service by entering the following command:
sudo /etc/init.d/apache2 restart
To access phpmyadmin use
http://XXX.XXX.XXX.XXX/phpmyadmin
where http://XXX.XXX.XXX.XXX is your ip address of raspberry pi
Comments
Post a Comment