Then choose your preferred server image, I want to install an Ubuntu server so I will proceed with this.
Then I will choose the free tier. What is the free tier now?
In this tier, for the first 12 months following your AWS sign-up date, you get up to 750 hours of micro instances each month. When your free usage tier expires or if your usage exceeds the free tier restrictions, you pay standard, pay-as-you-go service rates.
Click on Configure instance details I will leave everything default here.
Click on next to add storage. The default provided storage is 8 GB you can add more as per your need.
Then click on review and launch now.
You will be asked to choose a key pair for authorization purposes. Choose to create a new key-pair and enter the name of your Key Pair and then click on download Key Pair. You need to keep it safe.
You will see the newly created instance is running.
Choose your instance and click on connect, now we will be using SSH client in our case it will be putty.
if you're on windows then you can download putty
here and if you're Linux then you can install putty using your terminal. For Linux, these are the commands.
- sudo apt-get update
- sudo apt-get install -y putty
- putty
Now to connect you need to convert your keypairname.pem file to keypairname.ppk for authorization purposes. You can
read how to do it. So after converting launch Putty and follow the steps to connect.
Step 10
Open putty and enter the public IP of your EC2 instance, in my case, it is 3.19.62.96. In putty, go to SSH and click auth and locate your keypairnname.ppk.
This is my putty screen:
Click on open and a Putty security alert window will be prompted click on accept and wait for some time.
After this, you must see the login and you need to enter your username which is ubuntu by default. Enter your username and hit enter and wait for some time.
If everything looks good then you will see the below screen and finally, you're running your Ubuntu server in EC2.
Step 11: Now install the Apache server and PHP to run the PHP application
In order to run a PHP application, we need to install an apache server. So follow the command to install the apache server and PHP.
- sudo apt update
- sudo apt install apache2
- sudo apt install php libapache2-mod-php php-mysql
Now open your web browser and type your public IP in my case again it is 3.19.62.96 and you must see the below Apache2 Ubuntu Default Page. This means we have installed Apache on the Ubuntu server and it is working fine.
Now, whenever a user goes to your web app the Apache server will return HTML files; that means index.html. So we are going to change the configuration and make it look for index.php first and then index.html if index.php is not available. So for doing that below are the commands.
sudo nano /etc/apache2/mods-enabled/dir.conf
You will see something like this:
- <IfModule mod_dir.c>
- DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
- </IfModule>
Now move the index.php to the first position like below and press CTRL+O and CTRL+X.
- <IfModule mod_dir.c>
- DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
- </IfModule>
Now restart the apache server and check the status of the server. You must see active(running).
- sudo systemctl restart apache2
- sudo systemctl status apache2
Step 12: Create a PHP application that displays 'Hello World' and host.
Now we are going to write a simple PHP program that displays 'Hello World' and host it on our server. The following are the commands for that.
- cd /var/www/html
- sudo nano index.php
Now write this code and press CTRL+O and CTRL+X.
- <?php
- echo "Hello World";
- ?>
Now go to your web browser and enter your public IP and you must see "Hello World".
I hope this is helpful, if you have any query, feedback or suggestions please do let me know. Stay Safe.