Deploying a php application on AWS using EB command line interface(eb cli)
Published: 2023-05-22 04:57:56

### Hi my Name is Noble Mutuwa Mulaudzi,AWS DevOps Engineer and  a Linux enthusiast.

In this article i am going to show you how you can quickly deploy a php application on AWS using EB cli (without having to login to the AWS management console.

Source code: (https://github.com/Mutuwa99/Ebcli)


### Introduction

Deploying a PHP application on Amazon Web Services (AWS) can be a seamless process with the help of the Elastic Beanstalk Command Line Interface (EB CLI). AWS Elastic Beanstalk provides a platform-as-a-service (PaaS) for deploying and managing applications. In this article, i will walk you through the steps to deploy your PHP application on AWS using the EB CLI, enabling you to easily scale and manage your application infrastructure.

### Prerequisites:
Before we begin, make sure you have the following prerequisites in place:

- An AWS account: Sign up for an AWS account if you don't have one already.

- AWS CLI: Install the AWS Command Line Interface (CLI) on your local machine.

- EB CLI: Install the Elastic Beanstalk Command Line Interface (EB CLI) on your local machine.

- A PHP application: Have a PHP application ready for deployment.(You can download mine on my githu repo)
[](https://github.com/Mutuwa99/Ebcli)

#### Step 1: Set Up AWS CLI and EB CLI:
First, you need to configure the AWS CLI with your AWS account credentials. Open your terminal and run the following command:


```
aws configure

```
Provide your AWS Access Key ID, Secret Access Key, default region, and output format when prompted.

Next, install the EB CLI by running the following command:

```
pip install awsebcli --upgrade --user

```

### Step 2: Initialize the EB CLI:
In your terminal, navigate to your PHP application's directory and initialize the EB CLI by running:


```
eb init

```

#### Step 3: Setting up configs  for our application:

When a user accesses laravel  application via a web browser, the server looks directly into the "public" folder to handle the incoming request. In that case we will have to predefine the document root of our application and set it to /public

Create a folder called .ebextentions/01setup.config on your project root  and paste the following:

```
option_settings:
  - namespace: aws:elasticbeanstalk:container:php:phpini
    option_name: document_root
    value: /public
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/def5pjxm1wxd8n0xqyau.png)




### Follow the prompts to select your region, application name, and platform. Choose PHP as the platform for your application.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6vjsafit82sl8udckg13.png)

### Step 4: Create an Environment:
To create an environment for your PHP application, run the following command:

```
eb create environment-name

```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/51gciaco54qu4svgejrf.png)

Replace "environment-name" with a suitable name for your environment. This process may take a few minutes to provision the necessary AWS resources.

### Step 5: Deploy Your Application:
Once the environment is created, you can deploy your PHP application by running:

```
eb deploy

```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sg69dpuvlknnovn2dlax.png)

### step 6: Checking env health:
Once you have deployed your application you can check your app env health by running:

```
eb status

```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/80wxp8q4q9roi99fl9uh.png)

### Step 7: Access Your Application:

After the deployment is complete, you can access your application using the environment URL provided by Elastic Beanstalk. Run the following command to open the application in your default browser:

```
eb open
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nxl1669pao0lge9hmu7n.png)

### yeey we have sucessfully deployed our php application on AWS through EB CLI(without logging in to the management console)

Thank you

Noble Mutuwa Mulaudzi