Install PHP MySQL on ubuntu ec2 instance. Here we will show you step-by-step on how to install PHP MySQL on ubuntu 18.04 AWS EC2.
Install PHP MySQL on Linux Ubuntu 18.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
In this step, open your ssh terminal and type the following command 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
In this step, install PHP with it’s common extensions. So open your ssh terminal and type the following command:
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