Install PHP 7 on CentOS 7
CentOS 7 boats with PHP form 5.4 which has been formally EOL for a long while and is not, at this point upheld.
By utilizing PHP 7 your applications will stack quicker and burn-through less framework assets.
In this instructional exercise, we will disclose how to introduce or move up to PHP 7.0. 7.1, 7.2 and 7.3 on a CentOS 7 framework. We'll additionally tell you the best way to incorporate PHP with Nginx and Apache.
Additionally before introducing a particular PHP 7.x variant ensure that it is upheld by your application.
Prerequisites
Prior to beginning with this instructional exercise, ensure you are signed into your worker with a client account with sudo advantages or with the root client. It is best practice to run authoritative orders as sudo client rather than root. On the off chance that you don't have sudo client on your framework you can make one by adhering to these guidelines .
Enabling Remi repository
PHP 7.x bundles are accessible in a few unique stores. We'll utilize the Remi store which gives fresher forms of different programming bundles including PHP.
The Remi archive relies upon the EPEL storehouse . Run the accompanying orders to empower both EPEL and Remi storehouses:
sudo yum install epel-release yum-utils
sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
Yum may incite you to import the archive GPG key. Type y and hit Enter.
In the accompanying segments, we will cover how to introduce PHP 7.x by empowering the suitable Remi storehouse. On the off chance that you as of now have PHP 5.4 introduced on your framework yum will refresh the PHP bundles.
Installing PHP 7.3 on CentOS 7
PHP 7.3 is the most recent stable arrival of PHP. Most present day PHP structures and applications including WordPress , Drupal, Joomla, and Laravel are completely supporting PHP 7.3.
Play out the means beneath to introduce PHP 7.3 on CentOS 7.
Start by empowering the PHP 7.3 Remi archive:
sudo yum-config-manager --enable remi-php73
Introduce PHP 7.3 and probably the most well-known PHP modules:
sudo yum install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysqlnd
Check the PHP establishment, by composing the accompanying order which will print the PHP rendition :
php -v
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 just in case you will introduce applications, for example, Magento 2 that isn't viable with PHP 7.2.
The accompanying advances portray how to introduce PHP 7.2 CentOS 7.
First empower the PHP 7.2 Remi store by running the accompanying order:
sudo yum-config-manager --enable remi-php72
When the storehouse is empowered introduce PHP 7.2 and few most regular PHP modules:
sudo yum install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysqlnd
Check the PHP establishment:
php -v
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 means underneath to introduce PHP 7.1.
Empower the PHP 7.1 store by composing:
sudo yum-config-manager --enable remi-php71
Introduce PHP 7.1 and few most regular PHP modules:
sudo yum install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysql
To confirm the establishment, run the accompanying order which will print the PHP adaptation:
php -v
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
In the event that you are utilizing Apache as your web worker, at that point simply restart the Apache administration utilizing the accompanying order and you are all set:
sudo systemctl restart httpd
Configuring PHP 7.x to work with Nginx
Dissimilar to Apache, Nginx doesn't have inherent help for preparing PHP records so we need to introduce a different application, for example, PHP FPM which will deal with the PHP documents.
To introduce the PHP FPM bundle run the accompanying order:
sudo yum introduce php-fpm
Of course PHP FPM will run as client apache on port 9000. We'll change the client to nginx and change from TCP attachment to Unix attachment. To do so alter the lines featured in yellow:
/etc/php-fpm.d/www.conf
...
user = nginx
...
group = nginx
...
listen = /run/php-fpm/www.sock
...
listen.owner = nginx
listen.group = nginx
Ensure the/var/lib/php index has the right possession :
chown -R root:nginx /var/lib/php
When you rolled out the improvements, empower and start the PHP FPM administration:
sudo systemctl enable php-fpm
sudo systemctl start php-fpm
Next, alter the Nginx virtual host order and add the accompanying area block so Nginx can handle PHP documents:
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 design to produce results, restart the Nginx administration :
sudo systemctl restart nginx
Conclusion
You have figured out how to introduce PHP 7 on your CentOS worker and how to arrange your web worker to have the option to deal with PHP records.
In the event that you have any inquiries or criticism, don't spare a moment to leave a remark.