Cách cài đặt install php 7 centos 7

With EPEL and Remi already installed, let"s now proceed và install PHP 7 on CentOS 7.Bạn đang xem: Learn how lớn install php 7 on centos/rhel 7/6 & fedora 31/30

Install PHP 7.3 on CentOS 7

Let"s begin by installing PHP 7.3 which the latest version of PHP at the time of writing this. This is the latest version and ships with the latest nội dung management systems such as WordPress & Joomla and frameworks lượt thích Laravel.

Bạn đang xem: Cách cài đặt install php 7 centos 7

Step 1: Enable the PHP 7.3 Remi repository

To enable PHP 7.3 Remi repo run the following command:

$ sudo yum-config-manager --enable remi-php73

*

Step 2: Install PHP 7.3 & associated modules

With php 7.3 Remi enabled, now install PHP 7.3 & its modules as shown:

$ sudo yum install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysqlnd

*

*

Install PHP 7.2 on CentOS 7

For the installation of PHP 7.2 CentOS 7, ensure you follow the steps below:

Step 1: Enable the PHP 7.2 Remi repository

As we saw before, begin by enabling the Remi repository for PHP 7.2

$ sudo yum-config-manager --enable remi-php72

*

Step 2: Install PHP 7.2 và associated PHP modules

Next, install PHP 7.2 và associated modules as shown:

$ sudo yum install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysqlnd

*

Install PHP 7.1 on CentOS 7

Finally, we are going to install PHP 7.1. As we saw in the previous 2 versions, follow the steps below:

Step 1: Enable the PHP 7.1 Remi repository

As we saw before, begin by enabling the Remi repository for PHP 7.1

$ sudo yum-config-manager --enable remi-php71

Step 2: Install PHP 7.1 & its associated PHP modules

After enabling Remi repository, proceed and install PHP 7.1 using the command:

$ sudo yum install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysql

Configure PHP 7.x khổng lồ work with the Apache web Server

$ sudo systemctl restart httpd

Configure PHP 7.x khổng lồ work with the Nginx web Server

Unlike Apache, Nginx configuration with PHP 7.x is not as straightforward as you think it is. Nginx lacks supports for processing PHP files, and as such, we need to lớn install an extra mix of packages called PHP FPM that will process PHP files.

Xem thêm: idx là app gì

To install the PHP FPm package, run the command:

$ sudo yum install php-fpm

After the installation, head out to the configuration file located at /etc/php-fpm.d/www.conf

You"ll find that there"s a user called "apache" listening khổng lồ port 9000. We will change that user khổng lồ "nginx" & later adjust the lines as shown below.

...user = nginx...group = nginx...listen = /run/php-fpm/www.sock...listen.owner = nginxlisten.group = nginxNext phối the correct ownership khổng lồ the file /var/lib/php using chown command as shown:

$ sudo chown -R root:nginx /var/lib/phpThen enable và start php-fpm as shown:

$ sudo systemctl enable php-fpm$ sudo systemctl start php-fpm

If you have configured your Nginx block, you need to add the following configuration lines so that Nginx can process PHP files:

server # . . . Other codelocation ~ .php$ try_files $uri =404;fastcgi_pass unix:/run/php-fpm/www.sock;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;And finally, restart your web hệ thống for the changes to lớn come into effect

$ sudo systemctl restart nginx

Conclusion

And that"s it, folks! We have demonstrated how you can install different versions of PHP 7 on CentOS 7 & later how you can configure different website servers khổng lồ process PHP files. Apache is quite a piece of cake but you need to pay more attention lớn the Nginx web server. Thank you for your time.