Blogs
Take a look at the things that interest us.
Install PHP 7.2, 7.3 or 7.4 on Amazon Ec2
In today's blog post we are going to install PHP into our Amazon Linux ec2 cloud server. This tutorial works for
- php 7.2
- php 7.3
- php 7.4
Amazon Linux is an operating system designed to provide a stable, secure, and high-performance execution environment for applications running on Amazon EC2.
Let's get started with confirming that the amazon-linux-extras packages are installed.
which amazon-linux-extras
output
/usr/bin/amazon-linux-extras
If this comment doesn't return any output, you can install the extra packages with the following command.
sudo yum install -y amazon-linux-extras
Now let's confirm that PHP is available on the ec2 Linux server.
sudo amazon-linux-extras | grep php
output
15 php7.2 available \
17 lamp-mariadb10.2-php7.2 available \
31 php7.3 available \
42 php7.4 available [ =stable ]
As we can see in the output, all PHP 7 packages are available. Now we can enable the PHP package that we want to install on our ec2 Amazon Linux server.
sudo amazon-linux-extras disable php7.2
sudo amazon-linux-extras disable php7.3
sudo amazon-linux-extras enable php7.4
// Make sure to disable the packages that you don't want
sudo yum clean metadata
sudo yum install php php-{pear,cgi,common,curl,mbstring,gd,mysqlnd,gettext,bcmath,json,xml,fpm,intl,zip,imap,devel}
Make sure to accept the installation of PHP 7 packages on Amazon Linux 2.
Dependencies Resolved
========================================================================================================================================================
Package Arch Version Repository Size
========================================================================================================================================================
Installing:
php x86_64 7.4.5-1.amzn2 amzn2extra-php7.4 3.2 M
php-bcmath x86_64 7.4.5-1.amzn2 amzn2extra-php7.4 68 k
php-cli x86_64 7.4.5-1.amzn2 amzn2extra-php7.4 4.9 M
php-common x86_64 7.4.5-1.amzn2 amzn2extra-php7.4 1.1 M
php-fpm x86_64 7.4.5-1.amzn2 amzn2extra-php7.4 1.7 M
php-gd x86_64 7.4.5-1.amzn2 amzn2extra-php7.4 180 k
php-intl x86_64 7.4.5-1.amzn2 amzn2extra-php7.4 221 k
php-json x86_64 7.4.5-1.amzn2 amzn2extra-php7.4 70 k
php-mbstring x86_64 7.4.5-1.amzn2 amzn2extra-php7.4 511 k
php-mysqlnd x86_64 7.4.5-1.amzn2 amzn2extra-php7.4 238 k
php-pear noarch 1:1.10.7-3.amzn2.0.1 amzn2-core 354 k
php-xml x86_64 7.4.5-1.amzn2 amzn2extra-php7.4 198 k
Installing for dependencies:
apr x86_64 1.6.3-5.amzn2.0.2 amzn2-core 118 k
apr-util x86_64 1.6.1-5.amzn2.0.2 amzn2-core 99 k
apr-util-bdb x86_64 1.6.1-5.amzn2.0.2 amzn2-core 19 k
generic-logos-httpd noarch 18.0.0-4.amzn2 amzn2-core 19 k
httpd x86_64 2.4.43-1.amzn2 amzn2-core 1.3 M
httpd-filesystem noarch 2.4.43-1.amzn2 amzn2-core 23 k
httpd-tools x86_64 2.4.43-1.amzn2 amzn2-core 87 k
libxslt x86_64 1.1.28-5.amzn2.0.2 amzn2-core 243 k
libzip x86_64 1.3.2-1.amzn2.0.1 amzn2-core 62 k
mailcap noarch 2.1.41-2.amzn2 amzn2-core 31 k
mod_http2 x86_64 1.15.3-2.amzn2 amzn2-core 146 k
oniguruma x86_64 5.9.6-1.amzn2.0.3 amzn2-core 127 k
php-pdo x86_64 7.4.5-1.amzn2 amzn2extra-php7.4 133 k
php-process x86_64 7.4.5-1.amzn2 amzn2extra-php7.4 88 k
Transaction Summary
========================================================================================================================================================
Install 12 Packages (+14 Dependent packages)
Total download size: 15 M
Installed size: 61 M
Is this ok [y/d/N]: y
After the installation of PHP has been completed, you can check the PHP version with the following command.
php --version
output
PHP 7.4.5 (cli) (built: Apr 23 2020 00:10:21) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
PHP has been installed and you are good to go.
There are no comments.