Preparation
1. Download the required installation package
wget
wget
2. Install the required extension
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 the compiled file
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:
;不显示错误,默认 display_errors = off ;在关闭display_errors后开启php错误日志(路径在php-fpm.conf中配置),默认 log_errors = on ;字符集,默认 default_charset = "utf-8" ;文件上传大小,默认值太小,建议修改10m upload_max_filesize = 2m ;maximum size of post data that php will accept. 表单最大值,默认是8m,如果表单含有多图上传,大小可能不够。超过该大小后台收不到 表单数据 post_max_size = 8m ;设置php的扩展库路径,默认被注释了,之后一个文件夹 于 你/usr/local/php/lib/php/extensions/ 下的文件夹同名。 extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/" ;设置php的时区 date.timezone = prc ;开启opcache,默认是0 [opcache] ; determines if zend opcache is enabled opcache.enable=1
3. Modify the configuration file php-fpm of php-fpm. conf
vim /usr/local/php/etc/php-fpm.conf
The contents are modified as follows
; 去掉里分号,方便以后重启。建议修改 ;default value: none ; 下面的值最终目录是/usr/local/php/var/run/php-fpm.pid ; 开启后可以平滑重启php-fpm pid = run/php-fpm.pid ; 设置错误日志的路径,可以默认值 ; note: the default prefix is /usr/local/php/var ; default value: log/php-fpm.log, 即/usr/local/php/var/log/php-fpm.log error_log = /var/log/php-fpm/error.log ; log等级,可以默认值 ; possible values: alert, error, warning, notice, debug ; default value: notice log_level = notice ; 后台运行,默认yes,可以默认值 ; default value: yes ;daemonize = yes ; 引入www.conf文件中的配置,可以默认值 include=/usr/local/php/etc/php-fpm.d/*.conf
4. Modification
vim /usr/local/php/etc/php.ini
The content is modified as follows:
; 设置用户和用户组,默认都是nobody。可以默认值 user = nginx group = nginx ; 设置php监听 ; 下面是默认值,不建议使用。可以默认值 listen = 127.0.0.1:9000 ; 根据nginx.conf中的配置fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; ;listen = /var/run/php-fpm/php-fpm.sock ######开启慢日志。可以默认值 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检测配置文件是否正确 /usr/local/php/sbin/php-fpm # php-fpm启动 kill -int `cat /usr/local/php/var/run/php-fpm.pid` # php-fpm关闭 kill -usr2 `cat /usr/local/php/var/run/php-fpm.pid` #php-fpm平滑重启
Install nginx
1. Unzip - enter the directory - generate the compiled file
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 #测试成功
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; #显示目录 #autoindex on; #显示文件大小 #autoindex_exact_size on; #显示文件时间 #autoindex_localtime on; include /www/conf/vhosts/*.conf; }
2. Add website configuration file
vim /www/conf/vhosts/default.conf
File content As follows
server{ listen 80; server_name localhost,www.test.com; root /www/web/default; location / { #开启 url 美化 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 whether there are errors in the execution steps
5 , nginx operation
/usr/local/nginx/sbin/nginx -t # 检测配置文件是否正确 /usr/local/nginx/sbin/nginx # 启动 /usr/local/nginx/sbin/nginx -s stop # 关闭 /usr/local/nginx/sbin/nginx -s reload #平滑重启
The above is the detailed content of How to install PHP7.4 and Nginx on Centos. For more information, please follow other related articles on the PHP Chinese website!

NGINXUnit improves application performance and manageability with its modular architecture and dynamic reconfiguration capabilities. 1) Modular design includes master processes, routers and application processes, supporting efficient management and expansion. 2) Dynamic reconfiguration allows seamless update of configuration at runtime, suitable for CI/CD environments. 3) Multilingual support is implemented through dynamic loading of language runtime, improving development flexibility. 4) High performance is achieved through event-driven models and asynchronous I/O, and remains efficient even under high concurrency. 5) Security is improved by isolating application processes and reducing the mutual influence between applications.

NGINXUnit can be used to deploy and manage applications in multiple languages. 1) Install NGINXUnit. 2) Configure it to run different types of applications such as Python and PHP. 3) Use its dynamic configuration function for application management. Through these steps, you can efficiently deploy and manage applications and improve project efficiency.

NGINX is more suitable for handling high concurrent connections, while Apache is more suitable for scenarios where complex configurations and module extensions are required. 1.NGINX is known for its high performance and low resource consumption, and is suitable for high concurrency. 2.Apache is known for its stability and rich module extensions, which are suitable for complex configuration needs.

NGINXUnit improves application flexibility and performance with its dynamic configuration and high-performance architecture. 1. Dynamic configuration allows the application configuration to be adjusted without restarting the server. 2. High performance is reflected in event-driven and non-blocking architectures and multi-process models, and can efficiently handle concurrent connections and utilize multi-core CPUs.

NGINX and Apache are both powerful web servers, each with unique advantages and disadvantages in terms of performance, scalability and efficiency. 1) NGINX performs well when handling static content and reverse proxying, suitable for high concurrency scenarios. 2) Apache performs better when processing dynamic content and is suitable for projects that require rich module support. The selection of a server should be decided based on project requirements and scenarios.

NGINX is suitable for handling high concurrent requests, while Apache is suitable for scenarios where complex configurations and functional extensions are required. 1.NGINX adopts an event-driven, non-blocking architecture, and is suitable for high concurrency environments. 2. Apache adopts process or thread model to provide a rich module ecosystem that is suitable for complex configuration needs.

NGINX can be used to improve website performance, security, and scalability. 1) As a reverse proxy and load balancer, NGINX can optimize back-end services and share traffic. 2) Through event-driven and asynchronous architecture, NGINX efficiently handles high concurrent connections. 3) Configuration files allow flexible definition of rules, such as static file service and load balancing. 4) Optimization suggestions include enabling Gzip compression, using cache and tuning the worker process.

NGINXUnit supports multiple programming languages and is implemented through modular design. 1. Loading language module: Load the corresponding module according to the configuration file. 2. Application startup: Execute application code when the calling language runs. 3. Request processing: forward the request to the application instance. 4. Response return: Return the processed response to the client.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 English version
Recommended: Win version, supports code prompts!

WebStorm Mac version
Useful JavaScript development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 Linux new version
SublimeText3 Linux latest version