Centos How to Install PHP 7.4 and Nginx
- 2021-07-10 21:32:26
- OfStack
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
Installing PHP
1. Unzip-Enter Directory-Generate 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
Amend the content as follows:
; Do not display errors, default
display_errors = Off
; Closing display_errors Rear opening PHP Error log (path in php-fpm.conf Configuration in), the default
log_errors = On
; Character set, default
default_charset = "UTF-8"
; File upload size, the default value is too small, it is recommended to modify it 10M
upload_max_filesize = 2M
;Maximum size of POST data that PHP will accept. The maximum value of the form, which defaults to 8M If the form contains multiple graph uploads, the size may not be enough. Beyond this size, the background cannot receive Form data
post_max_size = 8M
; Settings PHP The extension library path of is annotated by default, and then 1 Folders In You /usr/local/php/lib/php/extensions/ The folder under has the same name.
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/"
; Settings PHP Time zone of
date.timezone = PRC
; Open opcache The default is 0
[opcache]
; Determines if Zend OPCache is enabled
opcache.enable=1
3. Modify the configuration file php-fpm. conf for php-fpm
vim /usr/local/php/etc/php-fpm.conf
Amend the content as follows
; Remove the inner semicolon for later restart. Suggested modifications
;Default Value: none
; The final directory of the following values is /usr/local/php/var/run/php-fpm.pid
; Smooth restart after opening php-fpm
pid = run/php-fpm.pid
; Set the path of the error log, which can be set by default
; 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 Grade, which can be defaulted
; Possible Values: alert, error, warning, notice, debug
; Default Value: notice
log_level = notice
; Running in the background, default yes Can be the default value
; Default Value: yes
;daemonize = yes
; Introduce www.conf The configuration in the file can be defaulted
include=/usr/local/php/etc/php-fpm.d/*.conf
4. Modification of www. conf
vim /usr/local/php/etc/php.ini
Amend the content as follows:
; Set up users and user groups, both of which are by default nobody . You can default
user = nginx
group = nginx
; Settings PHP Eavesdropping
; The following are defaults and are not recommended. You can default
listen = 127.0.0.1:9000
; According to nginx.conf Configuration in fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
;listen = /var/run/php-fpm/php-fpm.sock
###### Open slow log. You can default
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 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 Shut down
kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid` #php-fpm Smooth restart
Installing nginx
1. Unzip-Enter Directory-Generate 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 & & Installation
make
make install
Under Test 1/usr/local/nginx/sbin/nginx-t
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful # Successful test
3. Configuration file
1. Configure nginx. conf and execute vim/usr/local/nginx/conf/nginx. conf
Amend the content as follows
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
0
2. Add a Web site profile
vim /www/conf/vhosts/default.conf
The contents of the document are as follows
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
1
4. Test the configuration
Run the/usr/local/nginx/sbin/nginx-t, and if the test fails, return to check for errors in the execution steps
5. nginx operation
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
Summarize