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 SettingsStep 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 DirectoryStep 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 Deploy Angular App in S3?
Nowadays, application deployment in web development is one of the crucial aspects to ensure the work is done efficiently and in a cost-saving way to be in line with the development cycle. Amazon S3 (Simple Storage Service), or Angular, is commonly referred to as a double-edged weapon for a data stor
15 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 Deploy Angular App in AWS
Angular projects and applications are becoming more and more important as they are gaining popularity in the software industry, thus it becomes important to understand how we can deploy the angular apps that we create from the local system to the AWS cloud server, let us understand step by step how
8 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 Kubernetes on AWS?
Kubernetes, the open-supply box orchestration platform, has emerged as the solution for dealing with containerized applications. When deploying Kubernetes in the cloud, Amazon Web Services (AWS) gives a robust and scalable environment. In this manual, we can walk you through the manner of deploying
7 min read
How to Install and Deploy LEMP in Linux?
LEMP is a bundle or stack of software that, is used to run dynamic websites based on PHP. The LEMP stack includes a Linux Operating system, Nginx (Pronounced as Engine X) web server, MySQL database and PHP. Nginx is a web server that handles web requests and serves web content. MySQL database is use
9 min read
How To Deploy Flask APP On AWS EC2 Instance?
In this article, we will study how we can deploy our existing Flask application in AWS EC2. We will also see how to use the public IP of the EC2 instance to access the flask application. For this article, you should know about setting up EC2 in AWS. So, let's begin with the deployment.Primary Termin
5 min read