본문 바로가기
Wordpress

Update PHP on AWS EC2 (Amazon-linux2)

by NewbieDeveloper 2023. 3. 19.

If you followed AWS's official tutorial: Installing LAMP on Amazon Linux2 to install Wordpress on AWS EC2, you should have PHP7.2 installed on Amazon Linux2. But PHP 7.2 is now out of date. You must update your PHP version to at least 7.4. In this article, we share the update process in detail!

 

When you go to the Wordpress admin page and the following warning message pops up, it means that you need a PHP update.

Wordpress-Admin-Page-PHP-Update-Recommended-Warning-Is-Shown
Wordress-PHP-Update-Recommended

The reasons for updating, not simply because Wordpress guides you, are as follows. 

  • Your website will be faster. (The performance of 7.4 and later versions is better.)
  • Your website will be more secure. (The latest version has more security.)

If you have 15 minutes, go ahead!

Before the update

Before update the php, make sure you are ready to do it.

  • Backup your wordpress site 
  • PHP compatibility: PHP Compatibility Checker plugin helps compatibilities checks for your themes and plugins 
  • Fix PHP compatibility issues: If PHP compatibility checker found issues, contact developer of the thems and plugins to investigate it. If not, find another themes and plugins which are capable of similar functions.

Let's start the update : step by step guide

1. Login to your EC2 instance via SSH tool or AWS connect to instance option

2. Update Yum

$ sudo yum update

3. Check the current version of PHP

$ php -v

Enter-PHP--v-then-your-PHP-version-will-be-shown
PHP-version-check


4. Check amazon-linux-extras package is installed.

$ which amazon-linux-extras

If the package is installed, you'll see /usr/bin/amazon-linux-extras. Otherwise, install it.

$ sudo yum -y install amazon-linux-extras

5. Confirm desires versions (>7.4) are available in Amazon Linux2

$ sudo amazon-linux-extras | grep php

Available-PHP-version-will-be-listed
Check-available-PHP-versions-on-Amazon-Linux2

6. Disable existing PHP (<7.4) and lamp-mariadb10.2-php7.2

$ sudo amazon-linux-extras disable php7.2
$ sudo amazon-linux-extras disable lamp-mariadb10.2-php7.2

7. Enable PHP 8.0

I would like to install PHP8.0 but you can choose your desired version of PHP which is available.

$ sudo amazon-linux-extras enable php8.0

8. Check available PHP version

Just make sure only desired PHP version is enabled.

Available-PHP-version-will-be-shown.-Only-one-version-would-be-enabled
Available-PHP-Version-Check-on-Amazon-Linux2

(Optional) If you update PHP from 7.2 to 8.0, remove php-json to avoid dependency confliction. (php-json is included in PHP8.0 or PHP8.1)

$sudo yum remove php-json

9. Install new PHP version

$ sudo yum clean metadata
$ sudo yum install php php-{cli,pdo,pear,cgi,common,curl,mbstring,gd,mysqlnd,gettext,bcmath,json,xml,fpm,intl,zip,mysqlnd}

10. Check php version once update is finished.

Once-update-is-finished&#44;-PHP-version-should-be-the-desired-one.
Check-PHP-Version-After-The-Update

11. Restart the web server to be sure you are using latest PHP

$ sudo systemctl restart httpd

If you've made it this far, congratulations! If you have any problems, leave a comment and I'll check it out.

 

Reference:

https://wordpress.org/support/update-php/#before-you-update-your-php-version

댓글