Install PHP MySQL on ubuntu ec2 instance; In this tutorial, i am going to show you step-by-step on how to install PHP MySQL on ubuntu 18.04 / 20.04 AWS EC2.
How to Install PHP MySQL on Linux Ubuntu 18.04/20.04 AWS EC2
Use the following steps to install PHP MySQL on linux ubuntu 18.04 / 20.04 aws ec2:
- Connect Your AWS EC2 Instance from SSH
- Install MySQL on AWS EC2 Ubuntu
- Install PHP Amazon EC2 Ubuntu
- Restart Apache Web Server
Step 1 – Connect Your AWS EC2 Instance from SSH
First of all, you need to connect your aws ec2 instance from ssh. If you are new to connect aws ec2 instance with windows, ubuntu and mac system. So you can read this tutorial “How to Connect to ec2 Instance From Putty and SSH Terminal“ to connect your ec2 instance from ssh.
Step 2 – Install MySQL on AWS EC2 Ubuntu
Run the following command on command line or terminal to install MySql Server:
sudo apt-get install mysql-server
Then, secure MySql server by using the following command. So, you will need to set the root password of the database and secure it using the following command :
When you run this command. Then the questions given below in the prompt will appear:
- You will be presented with a screen where MySQL asks whether you would like to activate the VALIDATE PASSWORD PLUGIN. For now, keeping things simple, type no.
- In the next type the root password of your choice. Confirm it again.
- In the next screen MySql will ask whether to remove anonymous users. Type yes
- Disallow root login remotely? Type No
- Remove test database and access to it? Type Yes
- Reload privilege tables now? Type Yes
- After the password has been set you can check the whether MySQL is working correctly by logging into the database with the command :
sudo mysql -u root -p
The above command will ask for the password. Enter the password what you enter while the securing the MySQL and hit enter will login into MySQL:
Now, Type exit on ssh terminal to get out of MySql:
Step 3 – Install PHP Amazon EC2 Ubuntu
Run following command on command line or terminal to install PHP in amazon ec2 ubuntu:
sudo apt-get install php libapache2-mod-php php-mysql php-curl php-gd php-json php-zip php-mbstring
After successfully installed PHP on ubuntu amazon ec2 instance. Now, you need to configure
dir.conf file by using the following sudo nano command:
sudo nano /etc/apache2/mods-enabled/dir.conf
It will look like this:
<IfModule mod_dir.c> DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm </IfModule>
Move the PHP index file to the first position after the
DirectoryIndex specification, like this:
<IfModule mod_dir.c> DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm </IfModule>
Step 4 – Restart Apache Web Server
After successfully installed PHP MySQL and configure these on ubuntu amazon ec2 instance.
Finally, You need to restart Apache 2 server by using the following command:
sudo service apache2 restart