Step-by-Step Guide
1. Launch an EC2 Instance
- Go to the AWS Management Console.
- Launch a new EC2 instance using an Amazon Linux 2 AMI, Ubuntu, or another preferred distribution.
- Select an instance type (t2.micro is a good start for testing purposes).
- Configure instance details, add storage, and configure security groups:
- Allow HTTP (port 80) and SSH (port 22) access in the security group.
2. Connect to Your EC2 Instance
- Connect to your EC2 instance using SSH:Replace ec2-user with ubuntu if you are using an Ubuntu AMI, and adjust the public DNS accordingly.
3. Update the System
sudo yum update -y # For Amazon Linux sudo apt update && sudo apt upgrade -y # For Ubuntu
4. Install Apache Web Server
sudo yum install httpd -y # For Amazon Linux sudo apt install apache2 -y # For Ubuntu
5. Start and Enable Apache
sudo systemctl start httpd # For Amazon Linux sudo systemctl enable httpd sudo systemctl start apache2 # For Ubuntu sudo systemctl enable apache2
6. Install PHP and Required Extensions
sudo yum install php php-mysqlnd php-fpm -y # For Amazon Linux sudo apt install php libapache2-mod-php php-mysql -y # For Ubuntu
7. Restart Apache to Load PHP
sudo systemctl restart httpd # For Amazon Linux sudo systemctl restart apache2 # For Ubuntu
8. Install and Configure MariaDB (or MySQL)
sudo yum install mariadb-server -y # For Amazon Linux sudo apt install mariadb-server -y # For Ubuntu sudo systemctl start mariadb sudo systemctl enable mariadb sudo mysql_secure_installation
Follow the prompts to secure your MariaDB installation.
9. Download and Install phpMyAdmin
sudo yum install wget -y # For Amazon Linux sudo apt install wget -y # For Ubuntu cd /var/www/html sudo wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.tar.gz sudo tar xvzf phpMyAdmin-latest-all-languages.tar.gz sudo mv phpMyAdmin-*-all-languages phpmyadmin sudo rm phpMyAdmin-latest-all-languages.tar.gz
10. Configure phpMyAdmin
- Create a phpMyAdmin configuration file:
- Edit the configuration file:Add a blowfish secret for cookie authentication:You can generate a random secret string using an online tool.
11. Adjust Permissions
sudo chown -R apache:apache /var/www/html/phpmyadmin # For Amazon Linux sudo chown -R www-data:www-data /var/www/html/phpmyadmin # For Ubuntu
12. Access phpMyAdmin
- Open your web browser and navigate to:
- Log in using your MariaDB or MySQL credentials.
Security Considerations
- Restrict Access to phpMyAdmin: Edit your Apache configuration to restrict access to phpMyAdmin by IP address or use Apache's built-in authentication.
- Use HTTPS: Set up SSL/TLS to secure your phpMyAdmin installation.
- Disable Root Login: Disable root login from phpMyAdmin to enhance security.
bash
http://your-ec2-instance-public-dns/phpmyadmin
php
$cfg['blowfish_secret'] = 'your_random_secret_string'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
sudo nano /var/www/html/phpmyadmin/config.inc.php
sudo cp /var/www/html/phpmyadmin/config.sample.inc.php /var/www/html/phpmyadmin/config.inc.php
ssh -i /path/to/your-key.pem ec2-user@your-ec2-instance-public-dns
0 More Answers