How to deploy PHP apps into Cloud ?
PHP is a server-side scripting language that can be used for developing web applications or websites. In this article, we will see how to deploy the PHP applications in the Cloud. To deploy PHP apps on the cloud, we can use any cloud service provider. Here, we will be using the AWS EC2 Instance based on Ubuntu 18.04 LTS. Below are the required steps to deploy any PHP application in detail.
Steps to deploy PHP App on Cloud:
Step 1: Create and Launch Cloud Instance and Select Network access to Open i.e accessible by all and allow HTTP, and HTTPS traffic so we can use the PHP app on the web.
Step 2: Go to the folder where the downloaded key file is stored. (Downloaded when the instance was created) & Press Shift +Right Click, then select Open in Terminal.
Step 3: Type this command in the given format
< ssh -i "key.pem" user@dns >
The DNS and user details to connect can be found in Connect Menu of Instance.
Step 4: Now, Run the following commands:
sudo apt-get update
sudo apt-get install apache2
sudo apt-get install php libapache2-mod-php
sudo service apache2 restart
Step 5: Now, PHP is ready to use, go to directory /var/www/html.
Step 6: Run command the below command:
sudo rm index.html
This will delete the default HTML page of the apache.
Step 7: Run Command the below command:
sudo chmod 777 /var/www/html
This gives write and read full permissions to the current user.
Now, create file index.php using the command “cat > index.php” & paste the code of your PHP app into the terminal after running the command. Here, we are creating a simple Calculator-based PHP Application. After pasting the code in terminal, press Enter and then Ctrl + D, which will save the file.
Example: In this example, we have created a simple calculator app with basic arthimatic operations in PHP.
Step 8: Enter the public IP Address or Public DNS of the EC2 instance and you will see the PHP app is deployed.