Hướng dẫn install libphp7 so centos - cài đặt libphp7 so centos

Trong kho phần mềm chính thức của CentOS 7 thì PHP 5.4 đã cũ và không còn được các nhà phát triển hỗ trợ, duy trì và cập nhật bản vá lỗi.

Để hỗ trợ cho những tính năng mới cũng như tăng cường khả năng bảo mật, bạn cần phiên bản PHP mới hơn trên hệ thống CentOS 7.

Hướng dẫn install libphp7 so centos - cài đặt libphp7 so centos

Hiện tại, PHP 7.3 là phiên bản được phát hành mới nhất của PHP. Trong nội dung bài viết này, chúng tôi sẽ hướng dẫn bạn cài đặt các phiên bản PHP 7.x (bao gồm 7.0, 7.1, 7.2 và 7.3) lên hệ thống CentOS & Redhat 7.

Cài đặt PHP 7 trên CentOS

Để cài đặt PHP 7, bạn cần cài đặt và kích hoạt EPEL và Remi repository trên hệ thống CentOS 7 bằng câu lệnh sau:EPEL và Remi repository trên hệ thống CentOS 7 bằng câu lệnh sau:

  • Cài đặt EPEL

# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
  • Cài đặt Remi

# yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

Server của bạn đã được thiết lập để cài đặt PHP từ yum repository. Sử dụng một trong những lệnh bên dưới để cài đặt PHP 7.0, PHP 7.1, PHP 7.2 hoặc PHP 7.3:

## Install PHP 7.3 
# yum --enablerepo=remi-php73 install php

## Install PHP 7.2 
# yum --enablerepo=remi-php72 install php

## Install PHP 7.1 
# yum --enablerepo=remi-php71 install php

## Install PHP 7.0 
# yum --enablerepo=remi-php70 install php

Sau khi tiến trình cài đặt hoàn tất, để kiểm tra lại thông tin phiên bản PHP đang được kích hoạt lên server, bạn sử dụng lệnh:

# php -v

Hướng dẫn install libphp7 so centos - cài đặt libphp7 so centos

Cài đặt PHP Modules

Sau khi cài đặt một phiên bản PHP 7.x trên server, để cài đặt thêm một số PHP modules cần thiết cho các ứng dụng, bạn sử dụng lệnh bên dưới:

### For PHP 7.3
yum --enablerepo=remi-php73 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt

### For PHP 7.2
yum --enablerepo=remi-php72 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt

### For PHP 7.1
yum --enablerepo=remi-php71 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt 

### For PHP 7.0
yum --enablerepo=remi-php70 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt

Bạn có thể sử dụng lệnh bên dưới để tìm những PHP modules khác có sẵn trong yum repository đã được cấu hình:

# yum --enablerepo=remi-php73 search php | grep php73 [For PHP 7.3]

Chúc bạn thành công!

Gửi phản hồi về bài viết này

Cài đặt Tool, thư viên cho PHP 7.2

# yum install autoconf libtool re2c bison libxml2-devel bzip2-devel libcurl-devel libpng-devel libicu-devel gcc-c++ libmcrypt-devel libwebp-devel libjpeg-devel openssl-devel -y

Trên đây có các thư viên dùng tích hợp vào PHP khi biên dịch PHP ví dụ như: hỗ trợ file

## Install PHP 7.3 
# yum --enablerepo=remi-php73 install php

## Install PHP 7.2 
# yum --enablerepo=remi-php72 install php

## Install PHP 7.1 
# yum --enablerepo=remi-php71 install php

## Install PHP 7.0 
# yum --enablerepo=remi-php70 install php
7,
## Install PHP 7.3 
# yum --enablerepo=remi-php73 install php

## Install PHP 7.2 
# yum --enablerepo=remi-php72 install php

## Install PHP 7.1 
# yum --enablerepo=remi-php71 install php

## Install PHP 7.0 
# yum --enablerepo=remi-php70 install php
8 của
## Install PHP 7.3 
# yum --enablerepo=remi-php73 install php

## Install PHP 7.2 
# yum --enablerepo=remi-php72 install php

## Install PHP 7.1 
# yum --enablerepo=remi-php71 install php

## Install PHP 7.0 
# yum --enablerepo=remi-php70 install php
9

Kiểm tra tại

# php -v
0, tải về phiên bản Release mới. Bí dụ bản
# php -v
1 với link tải
# php -v
2

# curl -O -L https://github.com/php/php-src/archive/php-7.2.12.tar.gz

Giải nén

# tar -zxvf php-7.2.12.tar.gz
# cd php-src-php-7.2.12

Build PHP 7.2

Lưu ý: Nếu có sử dụng Apache thì thì phải cài đặt hoặc build Apache trước (nếu muốn tự build từ source xem Build Apache)

Giờ thực hiện với PHP, đầu tiên chạy

# ./buildconf --force

Tiếp theo chạy

# yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
0

Có thể nhập và chạy lệnh

# php -v
3 trên nhiều dòng, mỗi dòng cách nhau bằng
# php -v
4, cách này bạn lưu lệnh trên một file rồi paste vào terminal cho thuận tiện

# yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
1

Nếu muốn biết thêm các thiết lập chạy script

# php -v
5

Trong các thiết lập trên thì có một số thiết lập cần chỉ ra đường dẫn, thực tế trên máy của bạn có thể ở vị trí khác, nên bạn phải xác định nó nằm chính xác ở đâu như:

  • # php -v
    6 yêu cầu sinh ra file
    # php -v
    7 để tạo Handler gọi PHP từ Apache. Bạn phải xem Apache để
    # php -v
    8 ở đâu rồi thay vào
    # php -v
    9 - Tìm bằng lệnh
    ### For PHP 7.3
    yum --enablerepo=remi-php73 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt
    
    ### For PHP 7.2
    yum --enablerepo=remi-php72 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt
    
    ### For PHP 7.1
    yum --enablerepo=remi-php71 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt 
    
    ### For PHP 7.0
    yum --enablerepo=remi-php70 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt
    0
  • ### For PHP 7.3
    yum --enablerepo=remi-php73 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt
    
    ### For PHP 7.2
    yum --enablerepo=remi-php72 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt
    
    ### For PHP 7.1
    yum --enablerepo=remi-php71 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt 
    
    ### For PHP 7.0
    yum --enablerepo=remi-php70 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt
    1 cho phép
    ## Install PHP 7.3 
    # yum --enablerepo=remi-php73 install php
    
    ## Install PHP 7.2 
    # yum --enablerepo=remi-php72 install php
    
    ## Install PHP 7.1 
    # yum --enablerepo=remi-php71 install php
    
    ## Install PHP 7.0 
    # yum --enablerepo=remi-php70 install php
    9 chỉnh sửa được
    ## Install PHP 7.3 
    # yum --enablerepo=remi-php73 install php
    
    ## Install PHP 7.2 
    # yum --enablerepo=remi-php72 install php
    
    ## Install PHP 7.1 
    # yum --enablerepo=remi-php71 install php
    
    ## Install PHP 7.0 
    # yum --enablerepo=remi-php70 install php
    7. Tìm xem
    ### For PHP 7.3
    yum --enablerepo=remi-php73 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt
    
    ### For PHP 7.2
    yum --enablerepo=remi-php72 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt
    
    ### For PHP 7.1
    yum --enablerepo=remi-php71 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt 
    
    ### For PHP 7.0
    yum --enablerepo=remi-php70 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt
    4 nằm ở thư mục nào thì điền thư mục đó vào
    ### For PHP 7.3
    yum --enablerepo=remi-php73 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt
    
    ### For PHP 7.2
    yum --enablerepo=remi-php72 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt
    
    ### For PHP 7.1
    yum --enablerepo=remi-php71 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt 
    
    ### For PHP 7.0
    yum --enablerepo=remi-php70 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt
    5
  • ### For PHP 7.3
    yum --enablerepo=remi-php73 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt
    
    ### For PHP 7.2
    yum --enablerepo=remi-php72 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt
    
    ### For PHP 7.1
    yum --enablerepo=remi-php71 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt 
    
    ### For PHP 7.0
    yum --enablerepo=remi-php70 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt
    6 tương tự như trên (tìm từ
    ### For PHP 7.3
    yum --enablerepo=remi-php73 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt
    
    ### For PHP 7.2
    yum --enablerepo=remi-php72 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt
    
    ### For PHP 7.1
    yum --enablerepo=remi-php71 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt 
    
    ### For PHP 7.0
    yum --enablerepo=remi-php70 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt
    7)
  • ### For PHP 7.3
    yum --enablerepo=remi-php73 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt
    
    ### For PHP 7.2
    yum --enablerepo=remi-php72 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt
    
    ### For PHP 7.1
    yum --enablerepo=remi-php71 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt 
    
    ### For PHP 7.0
    yum --enablerepo=remi-php70 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt
    8 thiết lập thư mục cài đặt PHP

Tiếp theo chạy lệnh

# yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
2

Cài đặt

# yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
3

Copy file

### For PHP 7.3
yum --enablerepo=remi-php73 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt

### For PHP 7.2
yum --enablerepo=remi-php72 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt

### For PHP 7.1
yum --enablerepo=remi-php71 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt 

### For PHP 7.0
yum --enablerepo=remi-php70 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt
9 vào vị trí (do thiết lập khi build ở trên nạp config từ
# yum --enablerepo=remi-php73 search php | grep php73 [For PHP 7.3]
0 nên bạn copy vào đúng vị trí đó:

# yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
4

Thiết lập biến môi trường để trỏ đến đường dẫn gọi PHP

# yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
5

Thêm vào cuối file đó các dòng:

# yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
6

Lưu lại và chạy lệnh sau để nạp lại biến môi trường

# yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
7

Giờ có thể kiểm tra PHP

# yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
8

Có PHP rồi, muốn Webserver Apache gọi nó theo cách nào thì thêm Handler cho phù hợp trong Apache, xem tại để biết các Handler trước tại PHP APACHE HANDLER

Thiết lập Handler mặc định

Nếu sử dụng Handler mặc định

# yum --enablerepo=remi-php73 search php | grep php73 [For PHP 7.3]
1 với module
# php -v
7 mới build được:

# yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
9

Mở

# yum --enablerepo=remi-php73 search php | grep php73 [For PHP 7.3]
3 thêm vào:

## Install PHP 7.3 
# yum --enablerepo=remi-php73 install php

## Install PHP 7.2 
# yum --enablerepo=remi-php72 install php

## Install PHP 7.1 
# yum --enablerepo=remi-php71 install php

## Install PHP 7.0 
# yum --enablerepo=remi-php70 install php
0

Lưu lại và khởi động lại Apache bằng lệnh

# yum --enablerepo=remi-php73 search php | grep php73 [For PHP 7.3]
4

Giờ Apache đã chạy file .php khi truy cập đến

Thiết lập trên cũng đã tích hợp thư viện để truy cập

# yum --enablerepo=remi-php73 search php | grep php73 [For PHP 7.3]
5 là thư viện
# yum --enablerepo=remi-php73 search php | grep php73 [For PHP 7.3]
6,
# yum --enablerepo=remi-php73 search php | grep php73 [For PHP 7.3]
7. Nếu cần MySQL Server trên Server này luôn thì cài vào theo
# yum --enablerepo=remi-php73 search php | grep php73 [For PHP 7.3]
8

SỬ DỤNG PHP-FPM

Trong cấu hình cài đặt ở trên có tham số kích hoạt build hỗ trợ

# yum --enablerepo=remi-php73 search php | grep php73 [For PHP 7.3]
9 với tham số
# yum install autoconf libtool re2c bison libxml2-devel bzip2-devel libcurl-devel libpng-devel libicu-devel gcc-c++ libmcrypt-devel libwebp-devel libjpeg-devel openssl-devel -y
0, đây là loại Handler rất nhanh, có thể khởi chạy nhiều thread PHP, giúp cho các trang có lượng truy cập lớn chạy nhanh hơn. Nếu muốn dùng nó thay cho Handler mặc định ở trên (Apache 2.0 Handler) thì cần một số thiết lập như sau, di chuyển vào thư mục mã nguồn PHP ở trên (bằng lệnh CD):

## Install PHP 7.3 
# yum --enablerepo=remi-php73 install php

## Install PHP 7.2 
# yum --enablerepo=remi-php72 install php

## Install PHP 7.1 
# yum --enablerepo=remi-php71 install php

## Install PHP 7.0 
# yum --enablerepo=remi-php70 install php
1

Mở file

# yum install autoconf libtool re2c bison libxml2-devel bzip2-devel libcurl-devel libpng-devel libicu-devel gcc-c++ libmcrypt-devel libwebp-devel libjpeg-devel openssl-devel -y
1 và cập nhật nội dung thành

## Install PHP 7.3 
# yum --enablerepo=remi-php73 install php

## Install PHP 7.2 
# yum --enablerepo=remi-php72 install php

## Install PHP 7.1 
# yum --enablerepo=remi-php71 install php

## Install PHP 7.0 
# yum --enablerepo=remi-php70 install php
2

Cập nhật file thiết lập

# yum install autoconf libtool re2c bison libxml2-devel bzip2-devel libcurl-devel libpng-devel libicu-devel gcc-c++ libmcrypt-devel libwebp-devel libjpeg-devel openssl-devel -y
2

## Install PHP 7.3 
# yum --enablerepo=remi-php73 install php

## Install PHP 7.2 
# yum --enablerepo=remi-php72 install php

## Install PHP 7.1 
# yum --enablerepo=remi-php71 install php

## Install PHP 7.0 
# yum --enablerepo=remi-php70 install php
3
## Install PHP 7.3 
# yum --enablerepo=remi-php73 install php

## Install PHP 7.2 
# yum --enablerepo=remi-php72 install php

## Install PHP 7.1 
# yum --enablerepo=remi-php71 install php

## Install PHP 7.0 
# yum --enablerepo=remi-php70 install php
4

Mở

# yum --enablerepo=remi-php73 search php | grep php73 [For PHP 7.3]
3 hủy Handler PHP cũ đi và thêm vào Handler PHP-FPM gọi PHP qua Proxy:

## Install PHP 7.3 
# yum --enablerepo=remi-php73 install php

## Install PHP 7.2 
# yum --enablerepo=remi-php72 install php

## Install PHP 7.1 
# yum --enablerepo=remi-php71 install php

## Install PHP 7.0 
# yum --enablerepo=remi-php70 install php
5

Lưu lại và khởi động lại Apache

## Install PHP 7.3 
# yum --enablerepo=remi-php73 install php

## Install PHP 7.2 
# yum --enablerepo=remi-php72 install php

## Install PHP 7.1 
# yum --enablerepo=remi-php71 install php

## Install PHP 7.0 
# yum --enablerepo=remi-php70 install php
6

Giờ PHP đã được Apache gọi thông qua PHP-FPM