Python Installing On Linux Server
January 24, 2020
What is CCNA?
January 24, 2020
Show all

Install PHP 7

How-to-install-PHP-7.2-on-CentOS-7-3


The installation of PHP on a server is very simple. It is not a big task only when you know some things that you have to install the dependency. So for installing PHP first, you need to install a dependency.

In this, we can install php7 and PHP 7.1,php7.2, php7.3   on fresh  VPS-server. If you have all ready  PHP 5.4 and other PHP installed then you have to delete the dependency of old PHP version and install a new one so you can easily install the PHP 7 and any other of them .otherwise the dependency of current PHP will conflict the new one.

I will write in another post how to remove the current PHP version and install a new one.

Also prior to installing a specific PHP 7.x version make sure that it is supported by your application.

So let start one by one step:————–

yum install epel-release yum-utils -y yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

if you want 7.0 version then
yum-config-manager –enable remi-php70

if you want 7. 1version then
yum-config-manager –enable remi-php71

if you want 7. 3version then
yum-config-manager –enable remi-php73

if you want 7. 2version then
yum-config-manager –enable remi-php72

Perform the steps below to install PHP 7.3 on CentOS 7.

  1. Start by enabling the PHP 7.3 Remi repository:

sudo yum-config-manager –enable remi-php73

  1. Install PHP 7.3 and some of the most common PHP modules:

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

  1. Verify the PHP installation, by typing the following command which will print the PHP version:

php –v

{OUTPUT}

PHP 7.3.1 (cli) (built: Jan  8 2019 13:55:51) ( NTS )

Copyright (c) 1997-2018 The PHP Group

Zend Engine v3.3.1, Copyright (c) 1998-2018 Zend Technologies

with Zend OPcache v7.3.1, Copyright (c) 1999-2018, by Zend Technologies

Installing PHP 7.2 on CentOS 7

Use PHP 7.2 only if you’re going to install applications such as Magento 2 that is not compatible with PHP 7.2.

The following steps describe how to install PHP 7.2 CentOS 7.

  1. First enable the PHP 7.2 Remi repository by running the following command:

sudo yum-config-manager –enable remi-php72

  1. Once the repository is enabled install PHP 7.2 and few most common PHP modules:

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

  1. Verify the PHP installation:

php –v

{OUTPUT}

PHP 7.2.9 (cli) (built: Aug 15 2018 09:19:33) ( NTS )

Copyright (c) 1997-2018 The PHP Group

Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

with Zend OPcache v7.2.9, Copyright (c) 1999-2018, by Zend Technologies

Installing PHP 7.1 on CentOS 7

Follow the steps below to install PHP 7.1.

  1. Enable the PHP 7.1 repository by typing:

sudo yum-config-manager –enable remi-php71

  1. Install PHP 7.1 and few most common PHP modules:

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

  1. To verify the installation, run the following command which will print the PHP version:

php -v

{OUTPUT}

PHP 7.1.21 (cli) (built: Aug 15 2018 17:56:55) ( NTS )

Copyright (c) 1997-2018 The PHP Group

Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies

with Zend OPcache v7.1.21, Copyright (c) 1999-2018, by Zend Technologies

Configuring PHP 7.x to work with Apache

If you are using Apache as your web server then just restart the Apache service using the following command and you are good to go:

sudo systemctl restart httpd

Configuring PHP 7.x to work with Nginx

Unlike Apache, Nginx doesn’t have built-in support for processing PHP files so we need to install a separate application such as PHP FPM which will handle the PHP files.

To install the PHP FPM package run the following command:

sudo yum install php-fpm

By default PHP FPM will run as user apache on port 9000. We’ll change the user to nginx and switch from TCP socket to Unix socket. To do so edit the lines highlighted in yellow:

/etc/php-fpm.d/www.conf

user = nginx

group = nginx

listen = /run/php-fpm/www.sock

listen.owner = nginx

listen.group = nginx

Make sure the /var/lib/php directory has the correct ownership:

chown -R root:nginx /var/lib/php

Once you made the changes, enable and start the PHP FPM service:

sudo systemctl enable php-fpmsudo systemctl start php-fpm

Next, edit the Nginx virtual host directive and add the following location block so that Nginx can process PHP files:

server {

# . . . other code

location ~ \.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;

}

}

For the new configuration to take effect, restart the Nginx service:

sudo systemctl restart nginx

Leave a Reply

Your email address will not be published. Required fields are marked *