How to deploy PHP apps into Cloud ?
Last Updated :
02 Aug, 2024
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.

Network Settings
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.

Open The Terminal to connect to Cloud Instance
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.

Enter the SSH command to connect to the Cloud instance.
Step 4: Now, Run the following commands:
sudo apt-get update

Update The Packages installed in Cloud Machine.
sudo apt-get install apache2

Install Apache2.
sudo apt-get install php libapache2-mod-php

Install PHP Library for Apache2 Server.
sudo service apache2 restart

Restart Apache2 Server.
Step 5: Now, PHP is ready to use, go to directory /var/www/html.

Traverse to Project Directory
Step 6: Run command the below command:
sudo rm index.html
This will delete the default HTML page of the apache.

Delete Default File.
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 arithmetic operations in PHP.
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.
Similar Reads
How to Deploy Web Apps in S3?
Amazon S3 is an Object storage service owned by AWS which offers high availability, security, scalability, and performance. Customers across all industries and sizes can use Amazon S3 to back up and restore, archive, create enterprise applications, connect IoT devices, and create big data analytics
5 min read
How To Deploy PHP Application On Kubernetes ?
Prologue to deploying a PHP applications on Kubernetes starts with understanding the containerization, where applications and their libraries are packaged into convenient, lightweight containers. Docker is generally utilized for this reason. Kubernetes then deals with these containers, abstracting a
9 min read
How To Deploy Python Application In AWS?
In this article, we will explore how one as a Python developer can deploy the application by harnessing the capabilities of AWS. AWS, a leading cloud computing platform, offers a wide range of services to help developers build, deploy, and manage applications at scale EC2. It provides scalable compu
4 min read
How to run PHP code in Brackets ?
Brackets is a platform where HTML, CSS, JavaScript coding can be done. Editing these types of codes is very easy in Brackets. Pre-requisite for implementing PHP codes in Brackets: Install any local server in your machine like - Wamp, Xampp, or Mamp.Install Brackets. Features: It is platform-independ
2 min read
How to Install php-devel on CentOS?
PHP is a highly used programming language. It is widely used for website development purposes. Using HTML a simple webpage can be implemented. But using PHP will be more interactive with the users. Nowadays, PHP has many more options to install on many platforms. In PHP some packages are there. Thes
2 min read
How to enable cURL in PHP?
Often, web applications require HTTP based UserID and Password authentication, cookies, and form uploads. Even, user authentication with Google or Facebook sign-in is done via HTTP. In these types of cases, we need to request a particular service server(Like Google's) for user validation and authent
3 min read
How to Install PHP on AWS EC2?
AWS or Amazon web services is a cloud service platform that provides on-demand computational services, databases, storage space, and many more services. EC2 or Elastic Compute Cloud is a scalable computing service launched on the AWS cloud platform. In simpler words, EC2 is nothing but a virtual com
2 min read
How to Install PHP on Android Device?
Php is an open-source programming language that is typically used for Web development but may also be used for other purposes (backend developing). To put it succinctly, PHP is a server-side scripting language that may be installed on any device (e.g. bits of code to add forms to your site).It opera
2 min read
How to Install PHP Composer on cPanel?
cPanel is a web hosting management system. cPanel provides a control panel that provides a nice user interface. It is the most reliable & site management system. Moreover, cPanel provides a dashboard where some web date files and MySQL files are present to help others out. A composer is a tool t
2 min read
How to Deploy Next.js App to Vercel ?
Introduction: Vercel is a deployment tool used by frontend developers to instantly deploy and host web applications without knowing complex configurations. Features of Vercel:Easy to use and has a lifetime free tier service which is beneficial for beginners who want to deploy their side-project with
3 min read