How to install PHP7.4 and Nginx in Centos

12-19-2023

prepare

1. Download the required installation package.

wgetwget

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. Decompress-Enter Directory-Generate Compiled Files

tar -zxvf php-7.4.0.tar.gzcd 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 --ena ble-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.inicp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.confcp /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

Modify the contents as follows:

; Do not display errors, default display_errors = off; Open the php error log after closing display_errors (the path is configured in php-fpm.conf), and the default is log_errors = on; Character set, default_charset = "utf-8 "; File upload size, the default value is too small, it is recommended to modify 10mupload_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. Over this size, the form data post_max_size = 8m cannot be received in the background; Set the extension library path of php, which is annotated by default, and then a folder has the same name as the folder under you/usr/local/PHP/lib/PHP/extensions/. extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/"; Set the time zone of php date.timezone = prc; Open opcache, the default is 0[opcache]; determines if zend opcache is enabledopcache.enable=1

3. Modify the configuration file php-fpm.conf

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

Amend the contents as follows

; Remove the semicolon to facilitate later restart. Suggest revision; default value: none; The final directory of the following values is/usr/local/PHP/var/run/PHP-fpm.pid; After opening, you can restart php-fpmpid = run/php-fpm.pid smoothly; Set the path of the error log, which can be the default value; note: the default prefix is /usr/local/php/var; Default value: log/php-fpm.log, that is,/usr/local/PHP/var/log/PHP-fpm.logerror _ log =/var/log/PHP-fpm/error.log; Log level, which can be the default value; possible values: alert, error, warning, notice, debug; default value: noticelog_level = notice; Running in the background, yes by default, which can be the default value; default value: yes; daemonize = yes; The configuration in www.conf file can be imported, and the default value can be include =/usr/local/PHP/etc/PHP-fpm.d/*.conf.

Step 4 modify

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

Modify the contents as follows:

; Set users and user groups, which are nobody by default. You can default user = nginxgroup = nginx; Set php listening; The following are the default values, which are not recommended. You can default to listen = 127.0.0.1:9000; According to the configuration in nginx.conf, fastcgi _ passunix:/var/run/PHP-fpm/PHP-fpm.sock; ; Listen =/var/run/PHP-fpm/PHP-fpm.sock # # # # Start the slow log. You can default slowlog =/var/log/PHP-fpm/$ pool-slow.logrequest _ 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 closes kill-usr2` cat/usr/local/PHP/var/run/PHP-fpm.pid` # PHP-fpm restarts smoothly.

Install nginx

1. Decompress-Enter Directory-Generate Compiled Files

tar -zxvf nginx-1.17.6.tar.gzcd 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

makemake install

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

Nginx: configuration file/usr/local/nginx/conf/nginx.conf test is successful # test succeeded.

3. Configuration file

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

Amend the contents 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; # Display directory #autoindex on; # Display file size #autoindex_exact_size on; # Display file time #autoindex_localtime on; include /www/conf/vhosts/*.conf; }

2. Add a website profile

vim /www/conf/vhosts/default.conf

The document reads as follows

server{ listen 80; server_name localhost,www.test.com; root /www/web/default; Location/{# Open url to beautify 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 the configuration

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

5. nginx operation

/usr/local/nginx/sbin/nginx -t # Check whether the configuration file is correct/usr/local/nginx/start/usr/local/nginx/sbin/nginx-stop # Close/usr/local/nginx/sbin/nginx-.

Copyright Description:No reproduction without permission。

Knowledge sharing community for developers。

Let more developers benefit from it。

Help developers share knowledge through the Internet。

Follow us