phpMyAdmin is a popular web-based database management tool for MySQL and MariaDB. Below is a detailed guide to installing and configuring phpMyAdmin on a Linux server.
This is the third article in the series on setting up web hosting on Google Cloud (GCP) for free.
You can find the first article here and the second article here.
Step 1: Install phpMyAdmin
To begin, run the following command to install phpMyAdmin:
sudo apt install phpmyadmin
During the installation process, you will encounter two prompts:
- Server Selection Prompt: Do not select any web server; simply press
OK
to proceed. - Password Prompt: Provide your MySQL root password. This will allow phpMyAdmin to connect to your MySQL server and create the required database.
Step 2: Resolve Installation Errors (Optional)
If you encounter an error due to the validate_password
component, follow these steps:
- Abort the Installation: If the installation fails, cancel it.
- Log into MySQL:
mysql -u root -p
- Uninstall the
validate_password
Component:UNINSTALL COMPONENT 'file://component_validate_password';
- Exit MySQL and Reinstall phpMyAdmin:
exit
sudo apt install phpmyadmin
- Re-enable the
validate_password
Component (Optional): If needed, you can re-enable it using:INSTALL COMPONENT 'file://component_validate_password';
Step 3: Create a Symbolic Link
To make phpMyAdmin accessible from your default web directory, create a symbolic link:
sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin
Step 4: Access phpMyAdmin
You can now access phpMyAdmin by navigating to the following URL in your browser:
http://<server_ip>/phpmyadmin
Log in using the following credentials:
- Username:
root
- Password: The root password you set earlier for your MySQL account.
Step 5: Configure a Server Block for phpMyAdmin
To make phpMyAdmin accessible through a custom domain or subdomain:
- Add a DNS Record: In your domain’s DNS management, create an
A
record pointing to your server’s IP address. Usedatabase
as the subdomain (e.g.,database.example.com
). - Create an Nginx Configuration File:
- Open a new configuration file for your domain:
sudo nano /etc/nginx/sites-available/<domain_name>.conf
- Paste the following code into the file:
server { listen 80; listen [::]:80; server_name database.<domain_name>; root /var/www/html/phpmyadmin/; index index.php index.html index.htm index.nginx-debian.html; access_log /var/log/nginx/phpmyadmin_access.log; error_log /var/log/nginx/phpmyadmin_error.log; location / { try_files $uri $uri/ /index.php; } location ~ \.php$ { fastcgi_pass unix:/run/php/php8.4-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; include snippets/fastcgi-php.conf; } location ~ /\.ht { deny all; } }
- Replace
<domain_name>
with your domain name, e.g.,example.com
.
- Open a new configuration file for your domain:
- Enable the Configuration and Restart Nginx: Run the following commands to enable your configuration, test for errors, and restart Nginx:
sudo ln -s /etc/nginx/sites-available/<domain_name>.conf /etc/nginx/sites-enabled/ sudo nginx -t sudo systemctl restart nginx
If these commands run successfully, you can now access phpMyAdmin using:
http://database.<domain_name>
Conclusion
You have successfully installed and configured phpMyAdmin for managing your databases. In the next tutorial, we will cover securing your server and applications with Let’s Encrypt SSL certificates.