How to Install PHP 8.2 on Amazon Linux 2 Instance

How to Install PHP 8.2 on Amazon Linux 2 Instance Featured

How to Install PHP 8.2 on Amazon Linux 2 Instance

Dear Reader, I hope you are doing well. PHP 8.2 is a major release version of PHP. It was released in Dec 2022 and so came the need to install this latest version. In today’s article, we’ll see how to install PHP 8.2 on Amazon Linux 2 EC2 instance.

So are you ready?

Alright !!!

You can also check out my other post to install Nginx, Apache, Java, Git, Ansible, PHP 8.1, Docker etc. on Amazon Linux 2.

Let’s get to a bit about Amazon Linux 2 and PHP 8.2.

Background on Amazon Linux 2 and PHP 8.2

Amazon Linux 2: 

  • Amazon Linux 2 is a widely used Amazon-provided free-tier eligible Linux AMI.
  • You can install software on Amazon Linux 2 using the Yum package manager.
  • Usually, the stable versions of the software are found on the Amazon Linux core repository and can be installed using the yum install package-name command.
  • looking for newly released software? Look for it in amazon-Linux-extras repository.
  • At the time of writing this post, PHP 8.2 is available in amazon-Linux-extras repository and we will be installing it from there only on Amazon Linux 2.

PHP 8.2: 

PHP(Hypertext Preprocessor) is a very popular server-side scripting language. It’s at the heart of the world’s biggest blogging system i.e. WordPress. Yes, that’s right !! PHP 8.2 is the major update of PHP language and it provides new features such as

  • Read-only classes
  • null, false, and true as stand-alone types
  • First-class callable syntax
  • deprecated dynamic properties
  • Performance improvement etc.

Don’t want to miss any posts from us? join us on our Facebook group, and follow us on Facebook, Twitter, LinkedIn, and Instagram. You can also subscribe to our newsletter below to not miss any updates from us.

A Bit of Background – PHP 8.2

PHP 8.2 was released in Dec 2022 and as expected it doesn’t get added instantly in the amazon-linux-extra repository. However, I was checking recently and found it to be available on the amazon-linux-extra repo. So thought to pen it down for you. Meanwhile, people were asking for the same in forums like StackOverflow.

So I feel it’s high time to write about it.

I am very happy that PHP 8.2 is already present in the amazon-linux-extra repository. And I don’t need to go the extra mile just to install it on my Amazon Linux 2 EC2 instance. So let’s go and install it on our Linux 2 system.

Prerequisite

Steps to Install PHP 8.2 on Amazon Linux 2 Instance

Roughly there are three steps to install PHP 8.2 on an Amazon Linux 2 instance. If you already have a running instance, you can connect to your instance and we can directly start from step 2.

  1. Create an Amazon Linux 2 EC2 Instance & Connect to It
  2. Install PHP 8.1 on the Amazon Linux 2
  3. Verify the PHP Installation

Step 1: Create an Amazon Linux 2 EC2 Instance & Connect to It

Create an Amazon Linux 2 EC2 instance. You can check out my post on launching an EC2 instance to achieve this.

Once your instance is up and running, select your instance and click connect as shown below.

How to Install PHP 8.2 on Amazon Linux 2 Instance 1

Select the EC2 Instance Connect tab, make sure the user name is ec2-user and then click Connect.

How to Install PHP 8.2 on Amazon Linux 2 Instance 2

A new browser window opens and you get connected to your EC2 instance as seen below.

Connect to EC2 instance using EC2 instance connect

That’s amazing. We are a step closer. Let’s go to 2nd step to install PHP 8.2 on our Amazon Linux 2 EC2 instance.

2. How To Install PHP 8.2 on Amazon Linux 2

PHP 8.2 is present in amazon-linux-extras repository. To install a package from the extras repository, you need to have amazon-linux-extras installed in your system.

Let’s check that in a moment. However, before installing any software on your EC2 instance, it’s always recommended to run a system update so that all the packages/software get updated with the latest version.

So let’s start with that step.

1. Run System Update

sudo yum update

2. Check If amazon-linux-extras is installed

Usually, Amazon Linux 2 system already comes installed with amazon-linux-extras and you can check it with the below command.

which amazon-linux-extras
How to Install PHP 8.2 on Amazon Linux 2 Instance 4

If you get a response like the above, that means it is installed and you can see the location also in the above screenshot.

However, by any chance, If it is not there, you can install it using the below command.

sudo yum install -y amazon-linux-extras

3. Find Available PHP packages/topics in amazon-linux-extras repo

You can run the list command on the amazon-linux-extras repo to find the available PHP packages.

amazon-linux-extras list | grep php

Once you run list command, it shows all the available versions of PHP in the repo as you can see below-

How to Install PHP 8.2 on Amazon Linux 2 Instance 5

Did you notice PHP 8.2 is already there?

Awesome !!!

4. Enable the php8.2 Topic in amazon-linux-extras

Before we can install php8.2 from the extras repository, we need to enable it. Run the below command to enable it.

sudo amazon-linux-extras enable php8.2

Once you run this command, you will see that php8.2 gets enabled.

How to Install PHP 8.2 on Amazon Linux 2 Instance 6

5. Install PHP 8.2 from amazon-linux-extras repo

As you see in the above screenshot, the CLI prompted the command to install PHP 8.2.

Let’s fire the command now.

sudo yum clean metadata && sudo yum install php-cli php-pdo php-fpm php-json php-mysqlnd

or type

sudo amazon-linux-extras install php8.2

Both the commands work equally well and after firing any of the above, you will get below output-

How to Install PHP 8.2 on Amazon Linux 2 Instance 7

Type y and hit enter.

your packages get installed on the system.

Note: You’ll have to use sudo(root privilege ) to run the above command. The reason is that whenever you try to install, remove or change any software, you must have root privilege to do such tasks.

Step 3: Verify the PHP Installation

php --version
How to Install PHP 8.2 on Amazon Linux 2 Instance 8

Congratulations !!!

You have successfully installed PHP 8.2 on your Linux 2 EC2 instance.

Conclusion

In this how-to guide, you learned how to Install PHP 8.2 on Amazon Linux 2 EC2 Instance. First of all, you learnt a bit about the Amazon extras repository where newly released software is added. And how to install a package using that on Amazon Linux 2.

Secondly, we launched an Amazon Linux 2 EC2 instance. Then we connected our EC2 instance using EC2 Instance Connect option.

Finally, we installed PHP 8.2 using sudo amazon-linux-extras install php8.2 command.

Were you able to install PHP 8.2 on Amazon Linux 2 using this tutorial? Let me know in the comment section.

Enjoyed the content?

Subscribe to our newsletter below to get awesome AWS learning materials delivered straight to your inbox.

Don’t forget to motivate us-

Suggested Read:

Leave a Reply

Your email address will not be published. Required fields are marked *