Home Operation and Maintenance Nginx How to install PHP7.4 and Nginx on Centos

How to install PHP7.4 and Nginx on Centos

May 26, 2023 pm 04:41 PM
php centos nginx

Preparation

1. Download the required installation package

wget
wget

2. Install the required extension

1

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

Copy after login

Install php

1. Unzip - enter the directory - generate the compiled file

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

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

Copy after login

2. Compile and install

make && make install

3. Configuration file

1. Copy the configuration file to the installation directory

1

2

3

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

Copy after login

2. Modify the php configuration file php.ini

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

The content is modified as follows:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

;不显示错误,默认

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

Copy after login

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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

; 去掉里分号,方便以后重启。建议修改

;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

Copy after login

4. Modification

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

The content is modified as follows:

1

2

3

4

5

6

7

8

9

10

11

12

13

; 设置用户和用户组,默认都是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

Copy after login

4. php-fpm operation

1

2

3

4

/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平滑重启

Copy after login

Install nginx

1. Unzip - enter the directory - generate the compiled file

1

2

3

4

5

6

7

8

9

10

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

Copy after login

2. Compile && Install

1

2

make

make install

Copy after login

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

1

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful #测试成功

Copy after login

3. Configuration file

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

The content is modified as follows

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

#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;

}

Copy after login

2. Add website configuration file

vim /www/conf/vhosts/default.conf

File content As follows

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

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;

  }

}

Copy after login

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

1

2

3

4

/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  #平滑重启

Copy after login

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP's Purpose: Building Dynamic Websites PHP's Purpose: Building Dynamic Websites Apr 15, 2025 am 12:18 AM

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

How to optimize CentOS HDFS configuration How to optimize CentOS HDFS configuration Apr 14, 2025 pm 07:15 PM

Improve HDFS performance on CentOS: A comprehensive optimization guide to optimize HDFS (Hadoop distributed file system) on CentOS requires comprehensive consideration of hardware, system configuration and network settings. This article provides a series of optimization strategies to help you improve HDFS performance. 1. Hardware upgrade and selection resource expansion: Increase the CPU, memory and storage capacity of the server as much as possible. High-performance hardware: adopts high-performance network cards and switches to improve network throughput. 2. System configuration fine-tuning kernel parameter adjustment: Modify /etc/sysctl.conf file to optimize kernel parameters such as TCP connection number, file handle number and memory management. For example, adjust TCP connection status and buffer size

PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

Centos stops maintenance 2024 Centos stops maintenance 2024 Apr 14, 2025 pm 08:39 PM

CentOS will be shut down in 2024 because its upstream distribution, RHEL 8, has been shut down. This shutdown will affect the CentOS 8 system, preventing it from continuing to receive updates. Users should plan for migration, and recommended options include CentOS Stream, AlmaLinux, and Rocky Linux to keep the system safe and stable.

PHP: Handling Databases and Server-Side Logic PHP: Handling Databases and Server-Side Logic Apr 15, 2025 am 12:15 AM

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

Centos shutdown command line Centos shutdown command line Apr 14, 2025 pm 09:12 PM

The CentOS shutdown command is shutdown, and the syntax is shutdown [Options] Time [Information]. Options include: -h Stop the system immediately; -P Turn off the power after shutdown; -r restart; -t Waiting time. Times can be specified as immediate (now), minutes ( minutes), or a specific time (hh:mm). Added information can be displayed in system messages.

How to check CentOS HDFS configuration How to check CentOS HDFS configuration Apr 14, 2025 pm 07:21 PM

Complete Guide to Checking HDFS Configuration in CentOS Systems This article will guide you how to effectively check the configuration and running status of HDFS on CentOS systems. The following steps will help you fully understand the setup and operation of HDFS. Verify Hadoop environment variable: First, make sure the Hadoop environment variable is set correctly. In the terminal, execute the following command to verify that Hadoop is installed and configured correctly: hadoopversion Check HDFS configuration file: The core configuration file of HDFS is located in the /etc/hadoop/conf/ directory, where core-site.xml and hdfs-site.xml are crucial. use

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

See all articles