Raspberry Pi Tutorial Part 3 – LAMP Server – Installing MySQL Server + PHPMyAdmin

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:

sudo mysql_secure_installation

This setup script will prompt for the following:

  1. 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 – raspberry in all lowercase.
  2. Change root password – we can type n and click enter as we don’t need to change our root password.
  3. Remove Anonymous users – we recommend to type y and click enter as we do want to stop anonymous users from having access to our MySQL.
  4. Disallow root login remotely – we recommend you type y and click enter as, allowing root login remotely can open us up to more security threats.
  5. Remove Test Database – we can type y and click enter as we do not need the test database.
  6. Reload Privilege Tables – we need to type y and 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:

  1. 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.
  2. 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.
  3. MySQL application password for PHPMyAdmin – use the password for the account which we just created in Step 2 of this tutorial.
  4. 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:

Include /etc/phpmyadmin/apache.conf

With this line added, we can save and exit nano by clicking CTRL + X, type y to save and then click enter.

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:

http://(IpAddress)/phpmyadmin

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

By using this website you agree to accept our Privacy Policy and Terms & Conditions