yum -y remove php* cd /usr/src wget php-7.2.15.tar.bz2 http://cn2.php.net/distributions/php-7.2.15.tar.bz2 tar -xvf php-7.2.15.tar.bz2 cd php-7.2.15/ yum -y install wget vim pcre pcre-devel openssl openssl-devel httpd-devel libicu-devel gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel krb5-devel libidn libidn-devel openldap openldap-devel nss_ldap cmake boost-devel bison automake libevent libevent-devel gd gd-devel libtool* libxslt libxslt-devel readline readline-devel gmp gmp-devel libcurl libcurl-devel openjpeg-devel systemctl stop httpd
systemctl stop nginx find / -name 'apxs*' /usr/bin/apxs yum install httpd-devel ./configure \
--prefix=/usr/local/php \
--enable-fpm \
--with-apxs2=/usr/bin/apxs \
--with-config-file-path=/usr/local/php/etc \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--enable-pdo \
--with-iconv-dir \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir= \
--enable-xml \
--enable-session \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-mbstring \
--enable-intl \
--enable-pcntl \
--enable-ftp \
--with-gd \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--with-gettext \
--disable-fileinfo \
--enable-opcache \
--enable-maintainer-zts \
--with-xsl \
--enable-tokenizer make && make install cp 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 ; where MODE is the octal representation of the mode. Note that this
; does not overwrite the process's umask.
; http://php.net/session.save-path
session.save_path = "/usr/local/php/tmp" ; Decides whether PHP may expose the fact that it is installed on the server
; (e.g. by adding its signature to the Web server header). It is no security
; threat in any way, but it makes it possible to determine whether you use PHP
; on your server or not.
; http://php.net/expose-php
expose_php = Off ; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = PRC LoadModule php7_module /usr/lib64/httpd/modules/libphp7.so
SetHandler application/x-httpd-php
DirectoryIndex index.html index.php
id www id: www: no such user groupadd www useradd -g www -s /sbin/nologin www
#再次检查www用户
id www
#输出:
uid=1000(www) gid=1000(www) groups=1000(www) mkdir /usr/local/php/tmp && chown www:www /usr/local/php/tmp vim /usr/local/php/etc/php-fpm.d/www.conf ; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
user = www
group = www /usr/local/php/sbin/php-fpm ps aux | grep php-fpm root 72685 0.0 0.7 262756 7680 ? Ss 15:23 0:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
www 72686 0.0 0.7 264840 7572 ? S 15:23 0:00 php-fpm: pool www
www 72687 0.0 0.7 264840 7572 ? S 15:23 0:00 php-fpm: pool www
root 72692 0.0 0.0 112724 984 pts/0 R+ 15:25 0:00 grep --color=auto php-fpm vim /etc/nginx/server/default.conf server {
listen 80;
server_name [域名];
set $root [项目路径];
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
# PHP 脚本请求全部转发到 FastCGI处理. 使用FastCGI协议默认配置.
# Fastcgi服务器和程序(PHP,Python)沟通的协议.
location ~ \.php {
# 设置nginx的默认首页文件
fastcgi_index index.php;
# 设置监听端口
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^((?U).+.php)(/?.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
# 设置脚本文件请求的路径
fastcgi_param SCRIPT_FILENAME $root$fastcgi_script_name;
# 引入fastcgi的配置文件
include fastcgi_params;
}
location / {
root $root;
# 这里改动了 定义首页索引文件的名称
index index.html index.php;
if ( -f $request_filename) {
break;
}
if ( !-e $request_filename) {
rewrite ^(.*)$ /index.php/$1 last;
break;
}
}
location ~ /\.ht {
deny all;
}
} server {
listen 80; #监听80端口
server_name my.centos.com; #监听的域名
index index.html index.htm index.php;
root /var/www/web;
location / {
index index.php index.html index.htm;
if (!-e $request_filename) {
rewrite /admin.php(.*)$ /admin.php?s=$1 last;
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000; #fastcgi服务端口,将http请求代理到此端口
fastcgi_index index.php; #fastcgi服务默认页面
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #设置请求的脚本文件路径
include fastcgi_params;
}
}
touch /etc/profile.d/php.sh vim /etc/profile.d/php.sh
PATH=$PATH:/usr/local/php/bin
export PATH source /etc/profile php -v PHP 7.2.15 (cli) (built: Mar 17 2019 14:44:52) ( ZTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies systemctl restart httpd
systemctl restart nginx rm -rf php-7.2.15