Hướng dẫn cài đặt các package cho Amazon Linux 2 như gd, mbstring

27th Aug 2021
Table of contents

How can one install PHP 7.4,7.3 or 7.2 on an Amazon Linux 2 virtual machine. Amazon Linux is an operating system designed to provide a stable, secure, and high performance execution environment for applications running on Amazon EC2. This guide will show you how you can easily install PHP 7.x on Amazon Linux 2 instance running in AWS or your development environment.

Các bước tạo user và Exit the mysql client

mysql -u root -p

CREATE USER 'wordpress-user'@'localhost' IDENTIFIED BY 'your_strong_password';

CREATE DATABASE `wordpress-db`;

GRANT ALL PRIVILEGES ON `wordpress-db`.* TO "wordpress-user"@"localhost";

FLUSH PRIVILEGES;

exit

Confirm that the amazon-linux-extras package is installed

$ which amazon-linux-extras
/usr/bin/amazon-linux-extras

Check các package có avaiable không?

 $ sudo rpm -qa | grep php

Hoặc

$ sudo  amazon-linux-extras | grep php

Sau đó thử 

sudo yum install php-imagick

Add extension=imagick.so to the Dynamic Extensions section of the file.

sudo vi /etc/php.ini

Install PHP 7.4, 7.3, 7.2 on Amazon Linux 2

NOTE: The livepatch extra is in public preview, not meant for production use

 15  php7.2                   available    \
 17  lamp-mariadb10.2-php7.2  available    \
 31  php7.3                   available    \
 42  php7.4                   available    [ =stable ]

As we can see all PHP 7 topics, in this example we’ll enable php7.4 topic.

sudo amazon-linux-extras enable php7.4

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

Accept 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

Check default PHP version:

$ php --version
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

To install PHP 7.2, make sure you disable 7.4 and 7.3 then enable 7.2.

sudo amazon-linux-extras disable php7.4
sudo amazon-linux-extras disable php7.3
sudo amazon-linux-extras enable php7.2
sudo yum install php php-{pear,cgi,common,curl,mbstring,gd,mysqlnd,gettext,bcmath,json,xml,fpm,intl,zip,imap}

Confirm version of PHP.

$ php -v
PHP 7.2.31 (cli) (built: Jul  2 2020 23:17:00) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

Similar commands should be used when installing PHP 7.3 on Amazon Linux 2.

sudo amazon-linux-extras disable php7.4
sudo amazon-linux-extras disable php7.2
sudo amazon-linux-extras enable php7.3
sudo yum install php php-{pear,cgi,common,curl,mbstring,gd,mysqlnd,gettext,bcmath,json,xml,fpm,intl,zip,imap}
Bạn thấy bài viết này như thế nào?
0 reactions

Add new comment

Image CAPTCHA
Enter the characters shown in the image.
Câu nói tâm đắc: “Điều tuyệt với nhất trong cuộc sống là làm được những việc mà người khác tin là không thể!”

Related Articles

IntelliJ IDEA là một trình IDE dùng để lập trình Java (nó cũng được sử dụng để lập trình một số ngôn ngữ khác như Node.js, python…).

Nói một cách ngắn gọn, mệnh đề Where filter dữ liệu cho từng dòng riêng lẻ còn mệnh đề Having filter dữ liệu theo từng nhóm.

JOIN là một mệnh đề có nhiều biến thể trong SQL, JOIN có tính ứng dụng rất lớn khi cần kết hợp dữ liệu giữa các bảng.

Sau khi tạo xong database, các bạn muốn kiểm tra collation của database chúng ta sử dụng câu lệnh SQL sau:

Memory leaks can happen in any language, including PHP. These memory leaks may happen in small increments that take time to accumulate, or in larger jumps that manifest quickly. Either way, if your app has a memory leak, sooner or later it will cause problems