The following procedures help you install the Apache web server with PHP and MySQL support on your Amazon Linux instance. You can use this server to host a static website or deploy a dynamic PHP application that reads and writes information to a database.

1. Connect to your Linux instance using SSH

ssh -i /path/my-key-pair.pem ec2-user@ec2-198-51-100-1.compute-1.amazonaws.com

Or Connect to your Linux instance from Windows using PuTTY

2. To ensure that all of your software packages are up to date, perform a quick software update on your instance.

[ec2-user ~]$ sudo yum update -y

3. Now that your instance is current, you can install the Apache web server, MySQL, and PHP software packages.

[ec2-user ~]$ sudo yum install -y httpd24 php56 mysql55-server php56-mysqlnd

4. Start the Apache web server.

[ec2-user ~]$ sudo service httpd start

5. Test your web server. In a web browser, enter the public DNS address (or the public IP address) of your instance; you should see the Apache test page.

6. If you are not getting Apache test page, add rules to a security group for webserver

Add Rules to a Security Group

  • Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
  • In the navigation pane, choose Security Groups.
  • Choose the security group.
  • You can allow web servers to receive all inbound HTTP and HTTPS traffic. On the Inbound tab, choose Edit. In the dialog, choose Add Rule. Select HTTP from the Type list, and leave the source as Anywhere (0.0.0.0/0). Add a similar rule for the HTTPS protocol.

7. Set file permissions for /var/www/html folder for running web projects.

8. To secure the MySQL server

[ec2-user ~]$ sudo service mysqld start [ec2-user ~]$ sudo mysql_secure_installation

  • Enter the current root password. By default, the root account does not have a password set, so press Enter.
  • Type Y to set a password, and enter a secure password twice. Make sure to store this password in a safe place.
  • Type Y to remove the anonymous user accounts.
  • Type Y to disable remote root login.
  • Type Y to remove the test database.
  • Type Y to reload the privilege tables and save your changes.

[ec2-user ~]$ sudo service mysqld restart

9. Install phpMyAdmin

phpMyAdmin is a web-based database management tool that you can use to view and edit the MySQL databases on your EC2 instance.

[ec2-user ~]$ sudo yum install -y phpMyAdmin

if you can’t install phpMyAdmin using above command, use below command

[ec2-user ~]$ sudo yum –enablerepo=epel install phpmyadmin

10. Configure your phpMyAdmin installation to allow access from your local machine.

[ec2-user ~]$ sudo sed -i -e ‘s/127.0.0.1/your_ip_address/g’ /etc/httpd/conf.d/phpMyAdmin.conf

11. Restart Apache Web Server

[ec2-user ~]$ sudo service httpd restart

12. You should see the phpMyAdmin login page.

http://my.public.dns.amazonaws.com/phpmyadmin

Please refer below screen shots for more clarification.