Skip to content

Instantly share code, notes, and snippets.

@lechidung
Created April 15, 2020 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lechidung/4ecebce8c320d4f982e781689d96c8e0 to your computer and use it in GitHub Desktop.
Save lechidung/4ecebce8c320d4f982e781689d96c8e0 to your computer and use it in GitHub Desktop.
Install PHP 7.1/7.2/7.3/7.4 - Nginx - Configure Nginx to Process PHP Pages on Centos 7

Install Nginx

sudo yum install epel-release
sudo yum install nginx
sudo systemctl start nginx
sudo systemctl enable nginx

Install PHP (Multi version 7.1/7.2/ 7.3/ 7.4 )

Must be install epel-release

## Yum Repository
sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

## Install PHP 7.4 
yum --enablerepo=remi-php74 install php

## 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 php

Install module

### For PHP 7.4
yum --enablerepo=remi-php74 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt

### 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-mcrypt

Other modules

yum --enablerepo=remi-php72 install php-fpm php-fpm-nginx php-gmp php-imap php-intl php-mbstring php-mcrypt php-pecl-imagick php-pecl-xdebug php-soap

Update config Nginx and PHP

Update /etc/php.ini

cgi.fix_pathinfo=0

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

### 1 Update path php-fpm.sock
listen = /var/run/php-fpm/php-fpm.sock

### 2 Change ower file php-fpm.sock
listen.owner = nginx
listen.group = nginx 

### 3 Change apache to nginx
user = nginx
group = nginx

Restart services

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

Configure Nginx to Process PHP Pages

domain.conf

server {
    listen       80;
    server_name  server_domain_name_or_IP;

    # note that these lines are originally from the "location /" block
    root   /usr/share/nginx/html;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ =404;
    }
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment