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.htmlThis will delete the default HTML page of the apache.

Step 7: Run Command the below command:
sudo chmod 777 /var/www/htmlThis 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 arithmetic operations in PHP.
<!DOCTYPE html>
<head>
<title>
Calculator App in PHP
</title>
</head>
<?php
$first= $_POST['first'];
$second= $_POST['second'];
$operator = $_POST['operator'];
$result = '';
if (is_numeric($first) && is_numeric($second)) {
switch ($operator) {
case "+":
$result = $first + $second;
break;
case "-":
$result = $first - $second;
break;
case "*":
$result = $first * $second;
break;
case "/":
$result = $first / $second;
}
}
?>
<body>
<div id="page-wrap">
<h1>Calculator in PHP</h1>
<form action=""
method="post"
id="calculator">
<p>
<input type="number"
name="first"
id="first"
required="required"
value="<?php echo $first; ?>" />
<b>Enter First Value</b>
</p>
<p>
<input type="number"
name="second"
id="second"
required="required"
value="<?php echo $second; ?>" />
<b>Enter Second Value</b>
</p>
<p>
<input readonly="readonly"
name="result"
value="<?php echo $result; ?>">
<b>Result</b>
</p>
<input type="submit"
name="operator"
value="+" />
<input type="submit"
name="operator"
value="-" />
<input type="submit"
name="operator"
value="*" />
<input type="submit"
name="operator"
value="/" />
</form>
</div>
</body>
</html>
Step 8: Enter the public IP Address or Public DNS of the EC2 instance and you will see the PHP app is deployed.