How to Set Up PHP 8.4 on Amazon Linux 2023

Amazon Linux 2023 (AL2023) is the latest version of Amazon Linux, providing a modern and secure environment for running applications. If you’re looking to set up PHP 8.4 on AL2023, follow this step-by-step guide to get started.

Prerequisites

  1. Amazon Linux 2023 Instance: Ensure you have an AL2023 instance running on AWS EC2.
  2. SSH Access: Have SSH access to the instance with the necessary permissions.
  3. Root or Sudo Privileges: Ensure you have root access or are a sudo user.

Steps to Install PHP 8.4

Step 1: Update the System

Before installing PHP, ensure your system is up-to-date.

sudo dnf update -y

Step 2: Install required dependencies:

Install required dependencies:

sudo dnf install -y gcc make autoconf automake libtool bison libxml2-devel openssl-devel libcurl-devel libjpeg-devel libpng-devel libwebp-devel libicu-devel sqlite-devel
sudo dnf install -y oniguruma-devel

Step 3: Download PHP 8.4 source:

Download the PHP from the official source and extract

wget https://www.php.net/distributions/php-8.4.0.tar.gz
tar -xvzf php-8.4.0.tar.gz
cd php-8.4.0

Step 4: Install PHP 8.4

Now install PHP 8.4 along with commonly used extensions.

./configure --prefix=/usr/local/php --with-openssl --with-curl --with-libxml --enable-mbstring --enable-gd --with-webp --with-jpeg --with-zlib
make
sudo make install

Add PHP to system PATH:

sudo ln -s /usr/local/php/bin/php /usr/bin/php
sudo ln -s /usr/local/php/bin/phpize /usr/bin/phpize

Step 5: Verify the PHP Installation

Check the installed PHP version to ensure PHP 8.4 is properly set up.

php -v

You should see an output similar to:

PHP 8.4.x (cli) (built: YYYY-MM-DD) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.4.x, Copyright (c) Zend Technologies

Step 6: Configure PHP

Edit the PHP configuration file (php.ini) if necessary. The file is usually located at:

sudo nano /etc/php.ini

Make changes such as increasing the memory_limit, setting the upload_max_filesize, or configuring timezone.

Example:

memory_limit = 256M
upload_max_filesize = 50M
date.timezone = UTC

Step 7: Configure PHP-FPM (Optional)

If you plan to use PHP-FPM for serving PHP applications, configure its settings:

Edit the PHP-FPM configuration file:

sudo nano /etc/php-fpm.d/www.conf

Look for the user and group settings and adjust as needed:

user = nginx
group = nginx

Start and enable the PHP-FPM service:

sudo systemctl start php-fpm
sudo systemctl enable php-fpm

Step 8: Test PHP with a Web Server

Set up a web server like Apache or Nginx to serve PHP files.

Install Nginx:

sudo dnf install nginx -y

Configure Nginx to Use PHP:

Edit the default Nginx server block:

sudo nano /etc/nginx/conf.d/default.conf

Add the following lines to the server block:

location ~ \.php$ {
    root           /usr/share/nginx/html;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

Restart Nginx:

Step 9: Test Your Setup

Create a sample info.php file to test PHP processing:

echo "<?php phpinfo(); ?>" | sudo tee /usr/share/nginx/html/info.php

Visit the URL http://<your-instance-ip>/info.php in your browser. You should see the PHP info page.

Conclusion

You’ve successfully set up PHP 8.4 on Amazon Linux 2023! You can now build and deploy your PHP applications. Make sure to secure your instance by removing the info.php file and following AWS best practices for security.

For questions or further customization, drop a comment below!

Atiqur Rahman

I am MD. Atiqur Rahman graduated from BUET and is an AWS-certified solutions architect. I have successfully achieved 6 certifications from AWS including Cloud Practitioner, Solutions Architect, SysOps Administrator, and Developer Associate. I have more than 8 years of working experience as a DevOps engineer designing complex SAAS applications.

This Post Has 3 Comments

  1. Brian

    Unable to install PHP 8.4 in amazon linux 2023 using the above mentioned steps.

Leave a Reply