How to install PHP7.4 and Nginx on Centos

How to install PHP7.4 and Nginx on Centos

Prepare

1. Download the required installation package

wget https://www.php.net/distributions/php-7.4.0.tar.gz
wget http://nginx.org/download/nginx-1.17.6.tar.gz

2. Install the required extensions

yum install -y gcc gcc-c++ make cmake bison autoconf wget lrzsz libtool libtool-ltdl-devel freetype-devel libjpeg.x86_64 libjpeg-devel libpng-devel gd-devel python-devel patch sudo openssl* openssl openssl-devel ncurses-devel bzip* bzip2 unzip zlib-devel libevent* libxml* libxml2-devel libcurl* curl-devel readline-devel sqlite-devel libsodium-devel https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/o/oniguruma-5.9.5-3.el7.x86_64.rpm https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/o/oniguruma-devel-5.9.5-3.el7.x86_64.rpm

Install PHP

1. Unzip - enter the directory - generate compiled files

tar -zxvf php-7.4.0.tar.gz
cd php-7.4.0
./configure --prefix=/usr/local/php \
  --with-config-file-scan-dir=/usr/local/php/etc/ \
  --with-mhash --with-pdo-mysql \
  --with-openssl --with-mysqli \
  --with-iconv --with-zlib \
  --enable-inline-optimization \
  --disable-debug --disable-rpath \
  --enable-shared --enable-xml \
  --enable-bcmath --enable-shmop \
  --enable-sysvsem --enable-sysvshm --enable-mbregex \
  --enable-mbstring --enable-ftp \
  --enable-pcntl --enable-sockets \
  --with-xmlrpc --enable-soap \
  --without-pear --with-gettext \
  --enable-session --with-curl \
  --enable-opcache --enable-fpm \
  --without-gdbm --enable-fast-install \
  --disable-fileinfo --with-sodium

2. Compile and install

make && make install

3. Configuration File

1. Copy the configuration file to the installation directory

cp ~/php-7.4.0/php.ini-production /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

2. Modify the PHP configuration file php.ini

vim /usr/local/php/etc/php.ini

The content is modified as follows:

; Do not display errors, default display_errors = Off

; After turning off display_errors, turn on the PHP error log (the path is configured in php-fpm.conf), by default log_errors = On

; Character set, default_charset = "UTF-8"

;File upload size, the default value is too small, it is recommended to change to 10M
upload_max_filesize = 2M

;Maximum size of POST data that PHP will accept. The maximum value of the form is 8M by default. If the form contains multiple images to upload, the size may not be enough. If the size exceeds this, the backend will not receive the form data. post_max_size = 8M

; Set the PHP extension library path. It is commented by default. Then a folder will be created with the same name as the folder under /usr/local/php/lib/php/extensions/.
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/"

; Set PHP time zone date.timezone = PRC

; Enable opcache, default is 0
[opcache]
; Determines if Zend OPCache is enabled
opcache.enable=1

3. Modify the php-fpm configuration file php-fpm.conf

vim /usr/local/php/etc/php-fpm.conf

The content is modified as follows

; Remove the semicolon to facilitate restarting later. Suggested modification;Default Value: none
; The final directory of the value below is /usr/local/php/var/run/php-fpm.pid
; After enabling, php-fpm can be restarted smoothly
pid = run/php-fpm.pid

; Set the path of the error log, you can use the default value; Note: the default prefix is ​​/usr/local/php/var
; Default Value: log/php-fpm.log, i.e. /usr/local/php/var/log/php-fpm.log
error_log = /var/log/php-fpm/error.log

; Log level, can be the default value; Possible Values: alert, error, warning, notice, debug
; Default Value: notice
log_level = notice

; Run in the background, default is yes, can be the default value; Default Value: yes
;daemonize = yes

; Introduce the configuration in the www.conf file, the default value include=/usr/local/php/etc/php-fpm.d/*.conf

4. Modify www.conf

vim /usr/local/php/etc/php.ini

The content is modified as follows:

; Set the user and user group, the default is nobody. The default value user = nginx
group = nginx

; Set PHP listening; The following are default values ​​and are not recommended. The default value is listen = 127.0.0.1:9000
; According to the configuration fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock in nginx.conf;
;listen = /var/run/php-fpm/php-fpm.sock

#######Turn on slow log. You can use the default value slowlog = /var/log/php-fpm/$pool-slow.log
request_slowlog_timeout = 10s

4. php-fpm operation

/usr/local/php/sbin/php-fpm -t # php-fpm checks whether the configuration file is correct /usr/local/php/sbin/php-fpm # php-fpm starts kill -INT `cat /usr/local/php/var/run/php-fpm.pid` # php-fpm shuts down kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid` # php-fpm restarts smoothly

Install nginx

1. Unzip - enter the directory - generate compiled files

tar -zxvf nginx-1.17.6.tar.gz
cd nginx-1.17.6
./configure \
  --prefix=/usr/local/nginx \
  --with-http_stub_status_module \
  --with-http_ssl_module \
  --with-http_realip_module \
  --with-http_sub_module \
  --with-http_gzip_static_module \
  --with-pcre

2. Compile && Install

make
make install

Test /usr/local/nginx/sbin/nginx -t

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful #Test success

3. Configuration File

1. Configure nginx.conf and execute vim /usr/local/nginx/conf/nginx.conf

The content is modified as follows

#user nobody;
worker_processes 1;
error_log /www/logs/nginx/error.log;
error_log /www/logs/nginx/error_notice.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
  worker_connections 1024;
}
http {
  include mime.types;
  default_type application/octet-stream;
  #access_log logs/access.log main;
  sendfile on;
  #tcp_nopush on;
  #keepalive_timeout 0;
  keepalive_timeout 65;
  #gzip on;
  #Show directory #autoindex on;
  #Show file size #autoindex_exact_size on;
  #Show file time #autoindex_localtime on;
  include /www/conf/vhosts/*.conf;
}

2. Add website configuration file

vim /www/conf/vhosts/default.conf

The file contents are as follows

server{
  listen 80;
  server_name localhost,www.test.com;
  root /www/web/default;
  location / {
    # Enable url beautification if (!-e $request_filename){
      rewrite ^/(.*) /index.php last;
    }
    index index.html index.php;
  }
  location ~ \.php$ {
    include fastcgi.conf;
    fastcgi_pass 127.0.0.1:9000;
    try_files $uri = 404;
  }
}

4. Test configuration

Run /usr/local/nginx/sbin/nginx -t. If the test fails, return to check if there are any errors in the execution steps.

5. nginx operation

/usr/local/nginx/sbin/nginx -t # Check if the configuration file is correct /usr/local/nginx/sbin/nginx # Start /usr/local/nginx/sbin/nginx -s stop # Close /usr/local/nginx/sbin/nginx -s reload # Smooth restart

Summarize

The above is the operation method of installing PHP7.4 and Nginx on Centos introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • Detailed tutorial for installing nginx on centos8 (picture and text)
  • Solve the problem of "Welcome to nginx on Fedora!" after installing nginx on Centos7, and there is no default.conf file in the conf.d directory
  • How to install Nginx in CentOS7 and configure automatic startup
  • Detailed tutorial on installing PHP and Nginx on Centos7
  • Detailed explanation of Centos7 source code compilation and installation of Nginx1.13
  • Detailed process of installing nginx1.9.1 on centos8

<<:  Detailed explanation of how to use the vue verification code component

>>:  MySQL 5.7.17 installation and configuration method graphic tutorial

Recommend

Specific use of pthread_create in linux to create threads

pthread_create function Function Introduction pth...

Creating a Secondary Menu Using JavaScript

This article example shares the specific code of ...

Four modes of Oracle opening and closing

>1 Start the database In the cmd command windo...

Several situations that cause MySQL to perform a full table scan

Table of contents Case 1: Case 2: Case 3: To summ...

How to regularly clean up docker private server images

Using CI to build docker images for release has g...

MySQL 8.0.2 offline installation and configuration method graphic tutorial

The offline installation method of MySQL_8.0.2 is...

Example of how to change the domestic source in Ubuntu 18.04

Ubuntu's own source is from China, so the dow...

Detailed analysis of MySQL 8.0 memory consumption

Table of contents 1. innodb_buffer_pool_size 2. i...

Should nullable fields in MySQL be set to NULL or NOT NULL?

People who often use MySQL may encounter the foll...

CSS3 achieves various border effects

Translucent border Result: Implementation code: &...

MySQL 8.0.22 installation and configuration method graphic tutorial

This article records the installation and configu...

How to deploy code-server using docker

Pull the image # docker pull codercom/code-server...

JavaScript to achieve product query function

This article example shares the specific code of ...

Mysql transaction isolation level principle example analysis

introduction You must have encountered this in an...