How to Install PHP 8.3 on an EC2 Ubuntu 22.04 LTS Instance

Deploying PHP 8.3 on your Amazon EC2 instance with Ubuntu 22.04 LTS is a straightforward process. Here we’ll cover both setups for Apache and Nginx.

What to do

  1. Launch an EC2 instance with Ubuntu 22.04 LTS.
  2. Connect to your EC2 instance using SSH.
  3. Update package lists and upgrade existing packages.
  4. Add the ondrej/php repository to your package manager.
  5. Install PHP 8.3 and necessary extensions.
  6. Verify the PHP installation.
  7. Optionally, configure PHP settings according to your requirements.
  8. Restart the Apache or Nginx web server.
  9. Test PHP functionality to ensure everything is working correctly.

Step 1: Connect to Your EC2 Instance

First, securely connect to your EC2 instance via SSH:

Shell

Replace /path/to/your-key.pem with the actual path to your PEM file and your-ec2-ip with the public IP of your EC2 instance.

Step 2: Add the PHP Repository

Add the ppa:ondrej/php repository to get the latest PHP versions:

Shell

Step 3: Install PHP 8.3 and Common Extensions

Install PHP 8.3 along with popularly used extensions:

Shell

Step 4: Configure PHP 8.3 for Apache

If you’re using Apache as your web server, install the following package:

Shell

Once installed, restart Apache to apply changes:

Shell

To enable PHP 8.3, you may need to disable the previous version (if any) and enable the new one:

Shell

Step 5: Install PHP 8.3 FPM for Nginx

For those who prefer Nginx, you should install PHP-FPM (FastCGI Process Manager):

Shell

After installing, you need to configure Nginx to use PHP-FPM. Edit your site’s configuration file in /etc/nginx/sites-available:

Nginx

Make sure to replace /run/php/php8.3-fpm.sock with the correct path if it differs.

Reload Nginx to implement your changes:

Shell

Step 6: Verifying PHP 8.3 Installation

Check if PHP 8.3 is correctly installed and configured:

Shell

Expect output like this:

PHP

And that’s it! You have successfully installed PHP 8.3 on your AWS EC2 Ubuntu 22.04 LTS instance and configured it to work with either Apache or Nginx.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.