How to Install MySQL, PHP, and phpMyAdmin on Ubuntu: A Step-by-Step Guide

Setting up a web server environment on Ubuntu requires the installation of essential software components like MySQL, PHP, and phpMyAdmin. This guide will walk you through each step of the process, ensuring your server is ready to handle databases and dynamic web applications. Let's dive in.

Step-by-Step Guide to Installing MySQL, PHP, and phpMyAdmin on Ubuntu


Introduction

When setting up a web server on Ubuntu, having MySQL, PHP, and phpMyAdmin installed is crucial. MySQL is a powerful relational database management system, PHP is a server-side scripting language, and phpMyAdmin is a user-friendly web interface to manage MySQL databases. This guide will help you install and configure these tools, ensuring your server is fully operational.


Step 1: Installing MySQL

The first step in setting up your server environment is to install MySQL. MySQL is essential for managing databases that store and retrieve data for your web applications.


Installing MySQL on Ubuntu

Start by installing MySQL on your Ubuntu server:

$ sudo apt install mysql-server -y


Verifying MySQL Installation

Ensure that the MySQL service is running:

$ systemctl status mysql

p>If the service is active, you will see the following status:

p style="background-color: #000000;color: #FFFFFF;">Active: active (running)

p>You can also check the MySQL version to confirm the installation:

p style="background-color: #000000;color: #FFFFFF;">$ mysql --version

p>The console will display something like:

p style="background-color: #000000;color: #FFFFFF;"> mysql Ver 8.0.36-0 ubuntu 0.22.04.1 for Linux on x86_64 ((Ubuntu))

p>Note: This guide uses MySQL version 8.0.36.


h3>Securing MySQL Installationp>Next, run a security script to configure MySQL:

p style="background-color: #000000;color: #FFFFFF;">$ sudo mysql_secure_installation

Log into MySQL to set a password for the root user:

$ mysql


Managing MySQL Users

Check the list of existing users:

Mysql > SELECT User, Host FROM mysql.user;

The console will display:

+------------------+-----------+
| User             | Host      |
+------------------+-----------+
| debian-sys-maint | localhost |
| mysql.infoschema | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
| root             | localhost |
+------------------+-----------+
5 rows in set (0.00 sec)

Focus on the root user and change the password:

Mysql > ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'my_pass_123';

Remember to replace my_pass_123 with a strong password of your choice.

Exit MySQL:

Mysql > exit

In the future, log into MySQL using the following command:

$ mysql -u root -p

The console will prompt for the password you just set.


Step 2: Installing PHP

PHP is required for running phpMyAdmin and other web applications. In this step, we'll install PHP on your Ubuntu server.


Adding PHP Repository

First, add a new remote repository to the APT package manager:

$ sudo add-apt-repository ppa:ondrej/php


Installing PHP

Next, install PHP along with the FastCGI Process Manager (FPM) and a MySQL module:

$ sudo apt install php8.3-fpm php8.3-mysql -y


Verifying PHP Installation

Check the PHP version to ensure successful installation:

$ php -v

The console will display:

PHP 8.3.4 (cli) (built: Mar 16 2024 08:40:08) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.4, Copyright (c) Zend Technologies
  with Zend OPcache v8.3.4, Copyright (c), by Zend Technologies

Note: This guide uses PHP version 8.3.4.


Step 3: Installing phpMyAdmin

phpMyAdmin provides a web interface for managing MySQL databases, making it easier to handle complex tasks. Here's how to install it on Ubuntu.


Downloading phpMyAdmin

Download phpMyAdmin from the official website. Choose the latest version available in a .tar.gz archive, then use the wget command:

$ wget -c https://files.phpmyadmin.net/phpMyAdmin/5.2.1/phpMyAdmin-5.2.1-english.tar.gz


Unpacking and Setting Up phpMyAdmin

Unpack the downloaded archive:

$ tar -xzvf phpMyAdmin-5.2.1-english.tar.gz

You can delete the archive itself after unpacking:

$ rm phpMyAdmin-5.2.1-english.tar.gz

Move the unpacked directory to a specific directory for phpMyAdmin:

$ sudo mv phpMyAdmin-5.2.1-english /usr/share/phpmyadmin

Create a symbolic link associated with the localhost's web directory:

$ ln -s /usr/share/phpmyadmin /var/www/html


Configuring Nginx Web Server

Now, proceed to configure the Nginx web server to complete the phpMyAdmin setup.


Conclusion

By following these steps, you’ve successfully installed and configured MySQL, PHP, and phpMyAdmin on your Ubuntu server. This setup is now capable of managing databases, running dynamic web applications, and providing a user-friendly interface for database management. With these tools in place, your server environment is well-equipped to handle various web development tasks efficiently.

Comments

We Serve clients globally in diverse industries

Stay Upto Date With Our Newsletter.