In this tutorial, I’m going to show you how to set up a full LAMP server on your Raspberry Pi. LAMP stands for – Linux, Apache Web Server, MySQL and PHP. In the previous part of the series, we installed PHP and Apache onto our Raspberry Pi. In this tutorial, we will finish off the LAMP Web stack by installing MySQL and PHPMyAdmin. This tutorial is complemented by the following YouTube video:
Step 1 – Install MySQL on your Raspberry Pi (0:55)
The first part of the installation process is to install MySQL. To do this we will run the following command:
sudo apt-get install mysql-server
This command will download all the dependencies for the MySQL installation. Once done, we need to set up MySQL; fortunately, there is a built-in script to do this. We can run the following command to walk us through the setup process:
This setup script will prompt for the following:
- Enter root password – here we enter the password to the main account for our Pi. If you haven’t changed this from the default then it will be –
raspberryin all lowercase.
- Change root password – we can type
nand click enter as we don’t need to change our root password.
- Remove Anonymous users – we recommend to type
yand click enter as we do want to stop anonymous users from having access to our MySQL.
- Disallow root login remotely – we recommend you type
yand click enter as, allowing root login remotely can open us up to more security threats.
- Remove Test Database – we can type
yand click enter as we do not need the test database.
- Reload Privilege Tables – we need to type
yand enter to make sure all our changes have been made.
And that’s it, MySQL is now installed and setup.
Step 2 – Set up a MySQL user for PHP to use (1:51)
When we setup PHPMyAdmin, it will ask for a MySQL user to run as. By default, PHPMyAdmin will not allow us to choose the root user as this can open us up to security threats. Therefore we are required to create a new MySQL user. To set up this new account we need to enter into the MySQL command line. To do this we run the following command:
sudo mysql -u root -p
It will prompt for your Pi’s password, enter it and then you’ll be in the MySQL command line. With this open, we can now create our new account with the following command. Making sure to change “user” for a username of choice and “password” with the password you wish to use:
GRANT ALL PRIVILEGES ON mydb.* TO 'user'@'localhost' IDENTIFIED BY 'password';
With this command run, our new SQL user is setup – we can now type
quit to exit the MySQL console.
Step 3 – Install PHPMyAdmin (2:36)
With MySQL all setup, we can now install our MySQL administration tool – PHPMyAdmin which can be installed with the following command:
sudo apt-get install phpmyadmin
Running this command will automatically start the setup process which will ask a few questions:
- Web server to configure automatically – we want to choose apache. Use your arrow keys to move up and down and enter to select the correct option. This will take around 5 minutes until the next prompt appears.
- Configure database for PHPMyAdmin with dbconfig-common – This is asking if we want to link PHPMyAdmin with the MySQL data we just setup. Click yes and then proceed.
- MySQL application password for PHPMyAdmin – use the password for the account which we just created in Step 2 of this tutorial.
- Password confirmation – Re-enter the password
Once these prompts are complete the installation will soon finish – PHPMyAdmin is now installed.
Step 4 – Change Apache Configs (3:57)
For PHPMyAdmin to work correctly with Apache, we need to change the Apache config files. The command we will run to do this is:
sudo nano /etc/apache2/apache2.conf
This will open up a nano terminal of our config file. We need to use our arrow keys to scroll to the bottom of the file and then add the following line:
With this line added, we can save and exit nano by clicking
CTRL + X, type
y to save and then click
For these changes to take place we now need to restart the Apache server with the following command:
sudo /etc/init.d/apache2 restart
Step 5 – Check PHPMyAdmin is working (4:54)
To check the PHPMyAdmin is installed and working, we need to open up our web browser and enter the following address:
Of course, replacing (IPAddress) with the IP Address of your Raspberry Pi. In the video above I use –
http://192.168.1.124/phpmyadmin . The page should load up with a username and password prompt:
We can sign into this with the username and password which we set up in Step 2. Once logged in you will see a page like:
If you see a page like above then it is all set up and working. You can use this admin portal to manage all the databases on your MySQL Installation.
Step 6 – Complete LAMP Server
That’s all, the LAMP web stack server is now complete! If you have any issues or comments feel free to comment below or on the YouTube video and we’ll try our best to reply to them all! If you have any larger queries or questions then contact us here.