Current Location: Home> Latest Articles> How to Install and Configure PHP on AWS Environment | Complete Guide

How to Install and Configure PHP on AWS Environment | Complete Guide

gitbox 2025-07-15

AWS Environment Setup

Before installing PHP, you need to prepare your AWS environment. This involves selecting the appropriate EC2 instance type, configuring security groups, and network settings.

Choosing the Right EC2 Instance

Choose an EC2 instance based on your application needs. For small applications, t2.micro is usually a good choice, as it is part of the AWS Free Tier.

Configuring Security Groups

Ensure that your EC2 instance is configured with the correct security group to allow HTTP (port 80) and HTTPS (port 443) traffic so your application can function properly.

Installing PHP and Related Components

After successfully launching your EC2 instance, SSH into it and execute the following commands to install PHP and the necessary extensions.

Update System Packages

Before installing PHP, make sure your system packages are up to date. Use the following command to update your system:

<span class="fun">sudo yum update -y</span>

Installing PHP

Next, use the following command to install PHP and common extensions:

<span class="fun">sudo yum install php php-cli php-fpm php-mysqlnd -y</span>

Verify PHP Installation

After installation, you can verify if PHP was successfully installed by running this command:

<span class="fun">php -v</span>

This will display the PHP version, ensuring the installation was successful.

Configuring PHP-FPM (Optional)

If you wish to use PHP's FastCGI Process Manager (FPM), follow the steps below to configure it.

Editing PHP-FPM Configuration File

Edit the PHP-FPM configuration file, ensuring that the user and group are set to 'ec2-user' or the appropriate user:

<span class="fun">sudo vi /etc/php-fpm.d/www.conf</span>

Starting PHP-FPM Service

Start the PHP-FPM service using the following command:

<span class="fun">sudo systemctl start php-fpm</span>

Setting Up Web Server

To run PHP applications, you will need to install a web server such as Apache or Nginx.

Installing Apache

Use the following command to install the Apache web server:

<span class="fun">sudo yum install httpd -y</span>

Starting Apache Service

After installation, start the Apache service and configure it to start automatically at boot time:

<span class="fun">sudo systemctl start httpd</span>
<span class="fun">sudo systemctl enable httpd</span>

Conclusion

With this guide, you can successfully install and configure PHP on AWS. Remember to regularly update your server and PHP version to maintain security and performance. Additionally, customize your PHP and web server configurations based on your specific application needs.