Command to install nginx / PHP7 / php-fpm on CentOS7

Package update

$ sudo yum update

wget installation

$ sudo yum -y install wget

epel, remi repository registration

$ sudo yum -y install epel-release
$ wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
$ sudo rpm -ivh remi-release-7.rpm

Set the time zone to Japan time

$ sudo timedatectl set-timezone Asia/Tokyo
#Confirmation
$ date

install nginx

$ sudo yum --enablerepo=epel install nginx

Create nginx config file

$ sudo vi /etc/nginx/conf.d/default.conf

default.conf


server {
  listen 80;
  server_name centos7;
  root /var/www;
  index index.php index.html index.htm;

  location / {
    try_files $uri $uri/ /index.php?$query_string;
  }

  location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    include fastcgi_params;
  }
}

Minimum settings in nginx config file

sudo vi /etc/nginx/nginx.conf

nginx.conf


user  nginx;
worker_processes  auto;
worker_rlimit_nofile 100000;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  2048;
    multi_accept on;
    use epoll;
}


http {
    server_tokens off;
    include       /etc/nginx/mime.types;
    default_type  text/html;
    charset UTF-8;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile       off;
    tcp_nopush     on;
    tcp_nodelay    on;


    keepalive_timeout 10;
    client_header_timeout 10;
    client_body_timeout 10;
    reset_timedout_connection on;
    send_timeout 10;

    limit_conn_zone $binary_remote_addr zone=addr:5m;
    limit_conn addr 100;

    gzip on;
    gzip_http_version 1.0;
    gzip_disable "msie6";
    gzip_proxied any;
    gzip_min_length 1024;
    gzip_comp_level 6;
    gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript application/json;
    open_file_cache off;

    client_max_body_size 20m;
    server_names_hash_bucket_size 64;
    include /etc/nginx/conf.d/*.conf;
}

Check the settings in the nginx configuration file

$ nginx -t

Enable nginx service

$ sudo systemctl enable nginx

Start nginx

$ sudo systemctl start nginx

Check the startup status of nginx

$ sudo systemctl status nginx

Install PHP7 (also install php-fpm)

$ sudo yum install --enablerepo=epel,remi-php72 php php-mbstring php-fpm php-mcrypt php-mysql php-pdo php-json php-xml

If the PHP path does not pass, pass it

PHP version check

$ php -v

php-fpm settings

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

www.conf


user = nginx
group = nginx

listen = /var/run/php-fpm.sock
listen.owner = nginx
listen.group = nginx

php-fpm service activation

sudo systemctl enable php-fpm

Launch php-fpm

sudo systemctl start php-fpm

Check the startup status of php-fpm

sudo systemctl status php-fpm

Please put phpinfo.php in the WEB folder and check the operation of PHP.

Recommended Posts

Command to install nginx / PHP7 / php-fpm on CentOS7
How to install beta php8.0 on CentOS8
Install nginx on centOS7
How to install MariaDB 10.4 on CentOS 8
Steps to install MySQL 8 on CentOS 8
Steps to install devtoolset-6 on CentOS 7
I want to install PHP 7.2 on Ubuntu 20.04.
Install Golang on CentOS 8
Install Neo4j 4.1.3 on centOS
Install Vertica 10.0 on CentOS 6.10
Install PostgreSQL 12 on Centos8
Install Python 3 on CentOS 7
Install kuromoji on CentOS7
Install Mattermost on CentOS 7
Install PostGIS 2.5.5 on CentOS7
Install jpndistrict on CentOS 7
Install Redmine 4.1.1 on CentOS 7
Smokeping Install on CentOS7
Install PostgreSQL 13 on CentOS 7.5
Install MySQL 5.6 on CentOS6 [How to specify the version]
Try RabbitMQ + PHP on CentOS
Install OpenFOAM v2006 on CentOS
Install Jenkins on Docker's CentOS
Install Apache on CentOS on VirtualBox
Install Ruby 2.7 on CentOS 7 (SCL)
Note: Install nginx from official repositories with dnf on CentOS 8
How to install GNOME as a desktop environment on CentOS 7
How to install PHP 7.4 and SQL Server drivers in CentOS 7.7
How to deploy Laravel on CentOS 7
How to install ImageMagick on Windows 10
Install Ruby 2.5 on CentOS 7 using SCL
Install Java Open JDK 8 on CentOS 7
Upgrade from MYSQL5.7 to 8.0 on CentOS 6.7
Install apache 2.4.46 from source on CentOS7
How to install WildFly on Ubuntu 18.04
Use the iostat command on CentOS 8
Install Java 9 on windows 10 and CentOS 7
Install Golang / MariaDB on CentOS8, connect to DB and execute SQL
Steps to install samba on CentOS 8 and connect from Windows 10 Explorer
Install samba4 from source code on CentOS8
Install imagick on macOS Catalina + php 7.4 Note
How to install Eclipse (Photon) on Mac
How to install production Metabase on Ubuntu
Install the webmail client Rainloop on CentOS 8
Install CentOS 7 on Raspberry pi 4 Model B
I tried to build AdoptOpenjdk 11 on CentOS 7
Installing and configuring ClipBucket and Nginx on CentOS 7
How to install kafkacat on Amazon Linux2
Install NextCloud on CentOS 7 with Alibaba Cloud ECS
Just install Laravel8 on docker in PHP8 environment
How to install network drivers on standalone Ubuntu
How to install NVIDIA driver on Ubuntu 18.04 (Note)
Install GitLab on CentOS 8 with no internet connection
How to install multiple JDKs on Ubuntu 18.04 LTS
Install CMS Made Simple v2.2.2 on LAMP on CentOS 7.3
Reference articles and books used to install CentOS
[Ruby on Rails] How to install Bootstrap in Rails
Install MariaDB (CentOS 8)
[CentOS] Install apache-loggen
OpenVPN on CentOS 8
nginx start command