Upgrade Downgrade phiên bản PHP trong Cestos
Tác giả: Dương Nguyễn Phú Cường
Ngày đăng: 1 tuần trước
Lượt xem: 32
Hôm nay tôi tiếp tục chia sẽ đến các bạn cách nâng cấp phiên bản PHP mặc định của Vestacp đó là phiên bản PHP 5.6 lên phiên bản PHP 7.x, Các bạn có biết rằng hiệu suất của WordPress 3.6+ trở lên khi chạy trên PHP 7 đã được cải thiện đáng kể so với WordPress trên PHP 5.6, như thời gian phản hồi, xử lý các request đồng thời..v.v
- Đầu tiên việc bạn cần làm là kết nối SSH dưới tài khoản quản trị cao nhất root và kiểm tra cập nhật các gói phần mềm hiện tại đầu tiên bằng command lênh:
sudo yum update
- Sau việc cập nhật hoàn tất bạn kiểm tra xem phiên bản PHP hiện tại đang cài đặt trên máy chủ của bạn bằng command lệnh:
php -v
- Việc tiếp theo bạn cần làm là cài đặt gói yum-utils bằng command lệnh sau, yêu cầu cài đặt sẽ hỏi bạn có muốn cài không thì bạn gõ y nhấn Enter:
sudo yum install yum-utils
- Việc tải và cài đặt gói yum-utils thành công thì đến đây bạn cần kích hoạt remi để tiến hành nâng cấp bằng command lệnh sau:
sudo yum-config-manager --enable remi-php70– Hoặc remi-php71 nếu bạn muốn nâng cấp lên PHP 7.1
sudo yum-config-manager --enable remi-php71– Hoặc remi-php72 nếu bạn muốn nâng cấp lênh PHP 7.2
sudo yum-config-manager --enable remi-php72
- Như vậy là việc kích hoạt remi đã thành công và tất cả còn lại là chạy lệnh cập nhật để tiến hành update phiên bản PHP, nếu có thông báo hỏi bạn muốn cập nhật/cài đặt bản mới không thì bạn gõ y và nhấn Enter:
sudo yum update
- Khi việc cài đặt thành công bạn cần khởi động lại dịch vụ web server để phiên bản mới thực sự được cập nhật, bằng command lệnh sau:
sudo service httpd restart
– Nếu Máy chủ bạn cài đặt Vestacp NGINX + PHP-FPM thì bạn dùng command lệnh:
sudo service php-fpm restart
- Cuối cùng bạn cần kiểm tra lại phiên bản PHP cài đặt đã ok chưa bằng command lệnh:
php -vVí dụ sau khi cài đặt thành công và sử dụng lệnh php -v để kiểm tra như sau:
PHP 7.0.22 (cli) (built: Aug 2 2017 09:39:55) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
- Công việc đến đây có vẽ như là hoàn thành rồi, tuy nhiên bạn cũng đừng quên khóa tính năng cập nhật cho phiên bản PHP cũ đã cài lên máy chủ bằng các dòng lệnh sau:
sudo yum-config-manager --disable remi-php56 sudo yum-config-manager --disable remi-php55 sudo yum-config-manager --disable remi-php56-debuginfo sudo yum-config-manager --disable remi-php55-debuginfo sudo yum clean all sudo yum update
Installing PHP 7.3.3 on CentOS 7.6
Install EPEL Repository
To install the latest PHP 7.3.3 on CentOS 7.6, you need to first install EPEL repositories.yum install epel-release
Install Remi Repository
Remi is a third party repository that provides the latest versions of PHP.yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
Disable Remi PHP 5.4 repository
By default, the repository for PHP 5.4 is enabled and hence, to install the latest version of PHP, you need to disable this repo. The repositories can be enabled or disabled using theyum-config-manager
command. This command is provided with the yum-utils
package.
yum install -y yum-utils yum-config-manager --disable remi-php54
Enable Remi PHP 7.3 repository
To enable Remi PHP 7.3 repository, run the command below.yum-config-manager --enable remi-php73
Installing PHP 7.3.3 on CentOS 7.6
Now that we got the repositories to power this process, you can now install PHP 7.3.3 on CentOS 7.6.yum install phpOnce the installation, check the version by executing the command below;
php -vPHP 7.3.3
(cli) (built: Mar 5 2019 13:50:38) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.3, Copyright (c) 1998-2018 Zend TechnologiesIf you need to install PHP extensions, you can search and install them by running the command below;
yum list php-* yum install php-<extension_name>Well, that is it about installing PHP 7.3.3 on CentOS 7.6. We hope this was informative. Enjoy
Just run
yum install yum-utils -y yum-config-manager --disable remi-php5* yum-config-manager --disable remi-php74 yum-config-manager --disable remi-test yum-config-manager --enable remi-php73 yum remove php php-* yum install roundcube phpmyadmin -y service httpd restart or service php-fpm restart
1.
CODE: SELECT ALL
2.
yum remove php*
CODE: SELECT ALL
3.
yum install php71-php-imap php71-php-process php71-php-pspell php71-php-xml php71-php-xmlrpc php71-php-pdo php71-php-ldap php71-php-pecl-zip php71-php-common php71-php php71-php-mcrypt php71-php-gmp php71-php-mysqlnd php71-php-mbstring php71-php-gd php71-php-tidy php71-php-pecl-memcache --enablerepo=remi
CODE: SELECT ALL
4.
ln -s /usr/bin/php71 /usr/bin/php
CODE: SELECT ALL
5.
yum install yum-utils -y
CODE: SELECT ALL
6.
yum-config-manager --disable remi-php5*
yum-config-manager --disable remi-php74
yum-config-manager --disable remi-test
yum-config-manager --enable remi-php73
CODE: SELECT ALL
7. go to /etc/httpd/conf.d/ and edit "phpMyAdmin.conf and put this configuration.
yum install phpmyadmin -y
CODE: SELECT ALL
Now you can restart your apache "service httpd restart"
#tested on Centos7 Google Cloud
1. Installing VestaCP
<Directory /usr/share/phpMyAdmin/>
Order Deny,Allow
Deny from All
Allow from All
</Directory>
<Directory /usr/share/phpMyAdmin/scripts/>
Order Deny,Allow
Deny from All
Allow from All
</Directory>
# This directory does not require access over HTTP - taken from the original
# phpMyAdmin upstream tarball
#
<Directory /usr/share/phpMyAdmin/libraries/>
Order Deny,Allow
Deny from All
Allow from None
</Directory>
CODE: SELECT ALL
2. VestaCP installed with PHP 7.4.0 RC3, in this condition phpMyAdmin have a lot of errors
curl -O http://vestacp.com/pub/vst-install.sh
bash vst-install.sh --nginx yes --apache yes --phpfpm no --named yes --remi yes --vsftpd yes --proftpd no --iptables yes --fail2ban no --quota no --exim no --dovecot no --spamassassin no --clamav no --softaculous no --mysql yes --postgresql no
CODE: SELECT ALL
3. now after step 2, i successfully downgrade to PHP 7.3.10 and phpMyAdmin show no errors, but i can't access phpMyAdmin (forbidden 403)
yum install yum-utils -y
yum-config-manager --disable remi-php5*
yum-config-manager --disable remi-php74
yum-config-manager --disable remi-test
yum-config-manager --enable remi-php73
yum remove php php-*
yum install php roundcube phpmyadmin -y
CODE: SELECT ALL
4. after restart httpd service or reboot, all my problem is fixed :D
#edit phpMyAdmin config
nano /etc/httpd/conf.d/phpMyAdmin.conf
#overwrite all with this
# phpMyAdmin - Web based MySQL browser written in php
#
# Allows only localhost by default
#
# But allowing phpMyAdmin to anyone other than localhost should be considered
# dangerous unless properly secured by SSL
Alias /phpMyAdmin /usr/share/phpMyAdmin
Alias /phpmyadmin /usr/share/phpMyAdmin
<Directory /usr/share/phpMyAdmin/>
Order Deny,Allow
Deny from All
Allow from All
</Directory>
<Directory /usr/share/phpMyAdmin/scripts/>
Order Deny,Allow
Deny from All
Allow from All
</Directory>
# This directory does not require access over HTTP - taken from the original
# phpMyAdmin upstream tarball
#
<Directory /usr/share/phpMyAdmin/libraries/>
Order Deny,Allow
Deny from All
Allow from None
</Directory>
<Directory /usr/share/phpMyAdmin/setup/>
<IfModule mod_authz_core.c>
# Apache 2.4
Require local
</IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
Order Deny,Allow
Deny from All
Allow from 127.0.0.1
Allow from ::1
</IfModule>
</Directory>
# These directories do not require access over HTTP - taken from the original
# phpMyAdmin upstream tarball
#
<Directory /usr/share/phpMyAdmin/libraries/>
Order Deny,Allow
Deny from All
Allow from None
</Directory>
<Directory /usr/share/phpMyAdmin/setup/lib/>
Order Deny,Allow
Deny from All
Allow from None
</Directory>
<Directory /usr/share/phpMyAdmin/setup/frames/>
Order Deny,Allow
Deny from All
Allow from None
</Directory>
# This configuration prevents mod_security at phpMyAdmin directories from
# filtering SQL etc. This may break your mod_security implementation.
#
#<IfModule mod_security.c>
# <Directory /usr/share/phpMyAdmin/>
# SecRuleInheritance Off
# </Directory>
#</IfModule>
Setup Yum Repository
First of all, you need to enable Remi and EPEL yum repositories on your system. Use the following command to install EPEL repository on your CentOS and Red Hat 7/6 systems Use this command to install EPEL yum repository on your systemsudo yum install epel-releaseand now execute one of the following commands as per your operating system version to install the Remi repository.
sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
Install PHP 7 on CentOS
Your system is prepared for the PHP installation from yum repositories. Use one of the following commands to install PHP 7.3 or PHP 7.2 or PHP 7.1 on your system based on your requirements.## 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 phpI have installed the latest version PHP 7.3 on my system. Now running the following command to check the current active PHP version on my system.
php -v PHP 7.3.0 (cli) (built: Dec 4 2018 16:12:20) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.0-dev, Copyright (c) 1998-2018 Zend Technologies
Install PHP Modules
You may also need to install additional PHP modules based on your application requirements. The below command will install some more useful PHP modules.### 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-mcryptYou can run the following command to search other available PHP modules under configured yum repositories. Below example command search for all modules for PHP 7.3. yum --enablerepo=remi-php73 search php | grep php73
php73.x86_64 : Package that installs PHP 7.3 php73-php.x86_64 : PHP scripting language for creating dynamic web sites php73-php-bcmath.x86_64 : A module for PHP applications for using the bcmath php73-php-brotli.x86_64 : Brotli Extension for PHP php73-php-cli.x86_64 : Command-line interface for PHP php73-php-common.x86_64 : Common files for PHP php73-php-componere.x86_64 : Composing PHP classes at runtime php73-php-dba.x86_64 : A database abstraction layer module for PHP applications php73-php-dbg.x86_64 : The interactive PHP debugger php73-php-devel.x86_64 : Files needed for building PHP extensions php73-php-embedded.x86_64 : PHP library for embedding in applications php73-php-enchant.x86_64 : Enchant spelling extension for PHP applications php73-php-fpm.x86_64 : PHP FastCGI Process Manager php73-php-gd.x86_64 : A module for PHP applications for using the gd graphics ... ...