Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install PHP7.4 and Nginx in Centos

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces Centos how to install PHP7.4 and Nginx related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe you will have a harvest after reading this Centos how to install PHP7.4 and Nginx article, let's take a look.

Prepare for

1. Download the required installation package

Wget

Wget

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 compilation file

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\-- 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.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

two。 Modify 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; enable php error log after closing display_errors (path is configured in php-fpm.conf), default log_errors = on; character set, default default_charset = "utf-8"; file upload size, 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, which defaults to 8m, may not be enough if the form contains multiple images to upload. Beyond this size, the background will not receive the form data post_max_size = 8m; set the extended library path of php, which is annotated by default, and then a folder with the same name as the folder under your / 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; to enable opcache. Default is 0 [opcache]; determines if zend opcache is enabledopcache.enable=1

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

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

The content is modified as follows

Remove the semicolon to facilitate restart later. It is recommended to modify the value below default value: none;. The final directory is / usr/local/php/var/run/php-fpm.pid;. When enabled, you can smoothly restart the path of php-fpmpid = run/php-fpm.pid; setting error log, which can be defaulted. 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 defaulted; possible values: alert, error, warning, notice, debug; default value: noticelog_level = notice; background running, default yes, can default; default value: yes;daemonize = yes Import the configuration in the www.conf file. You can default to include=/usr/local/php/etc/php-fpm.d/*.conf.

4. Modify

Vim / usr/local/php/etc/php.ini

The content is modified as follows:

Set users and user groups. The default is nobody. You can set php snooping by the default value user = nginxgroup = nginx;; the following is the default value, which is not recommended. The default value is listen = 127.0.0.1 var/run/php-fpm/php-fpm.sock# 9000; slow logs are enabled according to the configuration in nginx.conf: fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;;listen = / slow. 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 check whether the configuration file is correct / usr/local/php/sbin/php-fpm # php-fpm start kill-int `cat / usr/local/php/var/run/php- fpm.pid` # php-fpm close kill-usr2 `cat / usr/local/php/var/run/php-f pm.pid` # php-fpm restart smoothly

Install nginx

1. Decompress-enter directory-generate compilation file

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, execute vim / usr/local/nginx/conf/nginx.conf

The content is modified as follows

# user nobody;worker_processes 1 error 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;}

two。 Add site profile

Vim / www/conf/vhosts/default.conf

The contents of the document 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 location 9000; try_files $uri = 404;}}

4. Test 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/sbin/nginx # startup / usr/local/nginx/sbin/nginx-s stop # shutdown / usr/local/nginx/sbin/nginx-s reload # smooth restart this article on "how Centos installs PHP7.4 and Nginx" ends here, thank you for reading! I believe you all have a certain understanding of "how to install PHP7.4 and Nginx in Centos". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report