How to install PHP 7.2 on CentOS 7/RHEL 7 - nixCraft
How to install PHP 7.2 on CentOS 7/RHEL 7 - nixCraft
Source: https://www.cyberciti.biz/faq/how-to-install-php-7-2-on-centos-7-rhel-7/
and: https://cloudwafer.com/blog/installing-phpmyadmin-with-nginx-on-centos-7/
Updating System Packages on CentOS
It is always recommended that you update the system to the latest packages before beginning any major installations. This is done with the command below:
sudo yum update
Installing Nginx
Install Nginx using the CentOS package manager yum
as shown below:
sudo yum install nginx
Checking Nginx Version
After installation, you can check the installed version of the Nginx web server on your CentOS 7 server by issuing the following command:
sudo nginx -v
Step 2: Install phpMyAdmin
Install phpMyAdmin
using the CentOS package manager yum
as shown below:
sudo yum -y install phpmyadmin php
Step 3: Configure phpMyAdmin
After successfully installing phpMyAdmin, we are going to create a virtual host configuration as phpMyAdmin does not automatically create one itself.
Create a virtual host file named phpMyAdmin.conf
in the /etc/nginx/conf.d
.
sudo nano /etc/nginx/conf.d/phpMyAdmin.conf
Add the following making changes to the domain name. You can replace it with your own domain name or your server's IP Address.
server {
listen 80;
server_name php.cloudwaferlabs.com.ng;
root /usr/share/phpMyAdmin;
location / {
index index.php;
}
## Images and static content is treated differently
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
access_log off;
expires 30d;
}
location ~ /\.ht {
deny all;
}
location ~ /(libraries|setup/frames|setup/libs) {
deny all;
return 404;
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/phpMyAdmin$fastcgi_script_name;
}
}
Ensure to save before closing the file.
Next, restart the services:
sudo systemctl restart nginx
Install PHP-FPM Install php-fpm
as shown below:
sudo yum install php-fpm
Next, restart php-fpm
as shown below:
sudo systemctl restart php-fpm
Next, access phpMyAdmin
from the browser on your domain name or server's IP address.
How do I Install PHP 7.2 on CentOS 7 server? How can I setup and install PHP 7.2 on RHEL 7 server along with Nginx web server? How do I configure PHP-fpm version 7.2 with Nginx server running on a CentOS / Red Hat Enterprise Linux version 7?
PHP is a recursive acronym for PHP: Hypertext Preprocessor. It is server-side scripting. One can write dynamically generated web pages in PHP or embedded PHP directly into HTML. PHP offers built-in database integration for several commercial and non-commercial database management systems. By default, CentOS 7/RHEL 7 comes with PHP version 5.4 only. This page shows how to install PHP 7.2 on CentOS 7 or RHEL 7 server using yum command.
Installing PHP version 7.2
The procedure to install PHP 7.2 on CentOS 7 or RHEL 7 is as follows:
- Turn on EPEL repo, enter:
sudo yum -y install epel-release - Turn on Remi repo i.e.remi-php72:
sudo yum-config-manager --enable remi-php72 - Refresh repository:
sudo yum update - Install php version 7.2, run:
sudo yum install php
Let us see examples and syntax is details.
How to install PHP 7.2 on CentOS 7
Turn on EPEL repo on a CentOS and RHEL 7.x sever by typing the following command:$ sudo yum install epel-release
Turn remi repo too:$ sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
Install yum-utils packages too:$ sudo yum install yum-utils
Enable remi repo, run:$ sudo yum-config-manager --enable remi-php72
$ sudo yum update
Search for PHP 7.2 packages and modules with more command/grep command/egrep command:$ sudo yum search php72 | more
$ sudo yum search php72 | egrep 'fpm|gd|mysql|memcache'
Sample outputs
Finally install php 7.2 on CentOS 7.2:$ sudo yum install php72
You must install “PHP FastCGI Process Manager” called php72-php-fpm along with commonly used modules:$ sudo yum install php72-php-fpm php72-php-gd php72-php-json php72-php-mbstring php72-php-mysqlnd php72-php-xml php72-php-xmlrpc php72-php-opcache
How to install PHP 7.2 on RHEL 7
The steps are as follows to enable and install PHP 7.2 on RHEL 7 using yum command:$ sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
$ sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
$ sudo yum install yum-utils
$ sudo subscription-manager repos --enable=rhel-7-server-optional-rpms
$ sudo yum-config-manager --enable remi-php72
$ sudo yum update
$ sudo yum search php72 | more
$ sudo yum install php72 php72-php-fpm php72-php-gd php72-php-json php72-php-mbstring php72-php-mysqlnd php72-php-xml php72-php-xmlrpc php72-php-opcache
Verification
Check PHP version:$ php --version
List installed modules$ php72 --modules
Sample outputs:
[PHP Modules] bz2 calendar Core ctype curl date dom exif fileinfo filter ftp gd gettext hash iconv json libxml mbstring mysqli mysqlnd openssl pcntl pcre PDO pdo_mysql pdo_sqlite Phar readline Reflection session SimpleXML sockets SPL sqlite3 standard tokenizer wddx xml xmlreader xmlrpc xmlwriter xsl Zend OPcache zlib [Zend Modules] Zend OPcache
Turn on PHP fpm for nginx
Use systemctl command:$ sudo systemctl enable php72-php-fpm.service
Sample outputs:
Created symlink from /etc/systemd/system/multi-user.target.wants/php72-php-fpm.service to /usr/lib/systemd/system/php72-php-fpm.service.
Commands to control PHP fpm:
Start PHP fpm service
$ sudo systemctl start php72-php-fpm.service
Stop PHP fpm service
$ sudo systemctl stop php72-php-fpm.service
Restart PHP fpm service
$ sudo systemctl restart php72-php-fpm.service
Get status of PHP fpm service
$ sudo systemctl status php72-php-fpm.service
Configure Nginx for using with PHP 7.2
Make sure latest version of Nginx server installed on CentOS 7 or RHEL 7. Find out nginx server user and group names using egrep command$ egrep '^(user|group)' /etc/nginx/nginx.conf
Sample outputs:
user nginx;
Edit vi /etc/opt/remi/php72/php-fpm.d/www.conf:$ sudo vi /etc/opt/remi/php72/php-fpm.d/www.conf
Set user and group to nginx:user = nginx
group = nginx
Save and close the file. Restart php-fpm service:$ sudo systemctl restart php72-php-fpm.service
Update your nginx config$ sudo vi /etc/nginx/conf.d/default.conf
Edit/add as follows in server section:
Save and close the file. Restart the nginx server:$ sudo systemctl restart nginx
Create a test script called foo.php at /usr/share/nginx/html/$ sudo vi /usr/share/nginx/html/foo.php
Append the following code:
Save and close the file. Fire a browser and type url:http://your-domain-name/foo.php
http://10.21.136.134/foo.php
Sample outputs:
Comments
Post a Comment