Step-by-Step Guide
Connect to Your EC2 Instance
Use SSH to connect to your EC2 instance.
ssh -i /path/to/your-key.pem ubuntu@your-ec2-instance-public-dns
Update Package List
Update the package list to ensure you have the latest information about available packages.
sudo apt-get update
Install PHP and Required Extensions
Ensure that PHP and the necessary extensions are installed. If you already have PHP installed, you can skip this step.
sudo apt-get install php php-mbstring php-zip php-gd php-json php-curl php-mysql
Install phpMyAdmin
Install phpMyAdmin using the package manager.
sudo apt-get install phpmyadmin
During the installation, you will be prompted to select the web server that should be automatically configured to run phpMyAdmin. Select apache2 by pressing Space and then Enter.
You will also be asked to configure a database for phpMyAdmin with dbconfig-common. Choose Yes and provide a password for the phpMyAdmin application to register with the database.
Configure Apache
Ensure the phpMyAdmin configuration is included in your Apache configuration. Open the Apache configuration file:
sudo nano /etc/apache2/apache2.conf
Add the following line at the end of the file to include the phpMyAdmin configuration:
apache
Include /etc/phpmyadmin/apache.conf
Save and close the file (Ctrl+X, Y, Enter).
Enable Required Apache Modules
Enable the necessary Apache modules.
sudo a2enmod rewrite
sudo phpenmod mbstring
Restart Apache
Restart Apache to apply the changes.
sudo systemctl restart apache2
Secure phpMyAdmin (Optional)
To secure phpMyAdmin, you can create an .htaccess file to add basic authentication.
sudo nano /usr/share/phpmyadmin/.htaccess
Add the following content:
apache
AuthType Basic
AuthName "Restricted Files"
AuthUserFile /etc/phpmyadmin/.htpasswd
Require valid-user
Save and close the file. Then create the password file and add a user.
sudo htpasswd -c /etc/phpmyadmin/.htpasswd yourusername
Follow the prompts to set a password for the user.
Access phpMyAdmin
You should now be able to access phpMyAdmin by navigating to http://your-ec2-instance-public-dns/phpmyadmin in your web browser. Log in using your MySQL username and password.