一、环境准备
操作系统:CentOS_Server_7.5_x64_1804.iso
部署组件:yasm+libmcrypt+libvpx+tiff+libpng+freetype+jpeg+libgd+t1lib+libzip+php
二、操作步骤:
2.0.安装依赖组件
[root@localhost ~]# yum install -y apr* autoconf automake bison bzip2 bzip2* compat* cpp curl curl-devel fontconfig fontconfig-devel gettext gettext-devel glibc kernel kernel-headers keyutils keyutils-libs-devel krb5-devel libcom_err-devel libsepol-devel libselinux-devel libstdc++-devel libtool* libgomp libxml2 libxml2-devel libXpm* mpfr ntp patch perl php-common php-gd policycoreutils nasm nasm* wget libicu-devel glibc-devel glib2 glib2-devel krb5-devel libidn bison automake libevent libtool-ltdl* libxslt libxslt-devel readline readline-devel gmp gmp-devel libcurl libcurl-devel python-devel openssl openssl-devel
2.1.安装yasm库
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# tar -xzf yasm-1.3.0.tar.gz -C /usr/local/data/
[root@localhost src]# cd /usr/local/data/yasm-1.3.0/
[root@localhost yasm-1.3.0]# ./configure --prefix=/usr/local/data/yasm
[root@localhost yasm-1.3.0]# make
[root@localhost yasm-1.3.0]# make install
2.2.安装libmcrypt库
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# tar -xzf libmcrypt-2.5.8.tar.gz -C /usr/local/data/
[root@localhost src]# cd /usr/local/data/libmcrypt-2.5.8/
[root@localhost libmcrypt-2.5.8]# ./configure --prefix=/usr/local/data/libmcrypt
[root@localhost libmcrypt-2.5.8]# make
[root@localhost libmcrypt-2.5.8]# make install
[root@localhost libmcrypt-2.5.8]# cd libltdl/
[root@localhost libltdl]# ./configure --enable-ltdl-install
[root@localhost libltdl]# make
[root@localhost libltdl]# make install
2.3.安装libvpx库
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# tar -xzf libvpx-1.8.0.tar.gz -C /usr/local/data/
[root@localhost src]# cd /usr/local/data/libvpx-1.8.0/
[root@localhost libvpx-1.8.0]# ./configure --prefix=/usr/localo/data/libvpx --enable-shared --enable-vp9
[root@localhost libvpx-1.8.0]# make
[root@localhost libvpx-1.8.0]# make install
2.4.安装tiff库
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# tar -xzf tiff-4.0.9.tar.gz -C /usr/local/data/
[root@localhost src]# cd /usr/local/data/tiff-4.0.9/
[root@localhost tiff-4.0.9]# ./configure --prefix=/usr/local/data/tiff --enable-shared
[root@localhost tiff-4.0.9]# make
[root@localhost tiff-4.0.9]# make install
2.5.安装libpng库
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# tar -xzf libpng-1.6.37.tar.gz -C /usr/local/data/
[root@localhost src]# cd /usr/local/data/libpng-1.6.37
[root@localhost libpng-1.6.37]# ./configure --prefix=/usr/local/data/libpng --enable-shared
[root@localhost libpng-1.6.37]# make
[root@localhost libpng-1.6.37]# make install
2.6.安装freetype库
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# tar -xzf freetype-2.9.tar.gz -C /usr/local/data/
[root@localhost src]# cd /usr/local/data/freetype-2.9
[root@localhost freetype-2.9]# ./configure --prefix=/usr/local/data/freetype --enable-shared
[root@localhost freetype-2.9]# make
[root@localhost freetype-2.9]# make install
2.7.安装jpeg库
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# tar -xzf jpegsrc.v9c.tar.gz -C /usr/local/data/
[root@localhost src]# cd /usr/local/data/jpeg-9c/
[root@localhost jpeg-9c]# ./configure --prefix=/usr/local/data/jpeg9 --enable-shared --enable-static
[root@localhost jpeg-9c]# make
[root@localhost jpeg-9c]# make install
2.8.安装libgd库
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# tar -xzf libgd-2.2.5.tar.gz -C /usr/local/data/
[root@localhost src]# cd /usr/local/data/libgd-2.2.5/
[root@localhost libgd-2.2.5]#
./configure \
--prefix=/usr/local/data/libgd \
--enable-shared \
--with-jpeg=/usr/local/data/jpeg9 \
--with-png=/usr/local/data/libpng \
--with-freetype=/usr/local/data/freetype \
--with-fontconfig=/usr/local/data/freetype \
--with-xpm=/usr/ \
--with-tiff=/usr/local/data/tiff \
[root@localhost libgd-2.2.5]# make
[root@localhost libgd-2.2.5]# make install
2.9.安装t1lib库
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# tar -xzf t1lib_5.1.2.orig.tar.gz -C /usr/local/data/
[root@localhost src]# cd /usr/local/data/t1lib-5.1.2/
[root@localhost t1lib-5.1.2]# ./configure --prefix=/usr/local/data/t1lib --enable-shared
[root@localhost t1lib-5.1.2]# make without_doc
[root@localhost t1lib-5.1.2]# make install
2.10.安装libzip库
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# tar -xzf libzip-1.5.2.tar.gz -C /usr/local/data/
[root@localhost src]# cd /usr/local/data/libzip-1.5.2/
[root@localhost libzip-1.5.2]# mkdir build
[root@localhost libzip-1.5.2]# cd build/
[root@localhost build]# cmake ..
[root@localhost build]# make
[root@localhost build]# make install
2.11.函数库文件连接
[root@linuxprobe src]# ln -s /usr/lib64/libltdl.so /usr/lib/libltdl.so
[root@linuxprobe src]# cp -frp /usr/lib64/libXpm.so* /usr/lib/
2.12.PHP服务安装部署
2.12.1.创建PHP用户组和用户
[root@localhost ~]# groupadd www
[root@localhost ~]# useradd -r -g www www
2.12.2.添加配置文件
[root@localhost ~]# vim /etc/ld.so.conf
/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64
[root@localhost ~]# ldconfig
2.12.3安装php包
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# tar -xzf php-7.3.8.tar.gz -C /usr/local/data/
[root@localhost src]# cd /usr/local/data/php-7.3.8/
[root@localhost php-7.3.8]# export LD_LIBRARY_PATH=/usr/local/data/libgd/lib
[root@localhost php-7.3.8]#
./configure --prefix=/usr/local/data/php7 \
--with-config-file-path=/usr/local/data/php7/etc \
--with-mysqli=/usr/local/data/mysql/bin/mysql_config \
--with-mysql-sock=/tmp/mysql.sock \
--with-pdo-mysql=/usr/local/data/mysql \
--with-libxml-dir=/usr/local/data/libxml2 \
--with-gd=/usr/local/data/libgd \
--with-png-dir=/usr/local/data/libpng \
--with-jpeg-dir=/usr/local/data/jpeg9 \
--with-freetype-dir=/usr/local/data/freetype \
--with-xpm-dir=/usr/lib64 \
--with-zlib-dir=/usr/local/data/zlib \
--with-iconv \
--enable-libxml \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--enable-opcache \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--enable-ftp \
--with-openssl \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--without-pear \
--with-gettext \
--enable-session \
--with-curl \
--enable-ctype \
--enable-mysqlnd
[root@localhost php-7.3.8]# make
[root@localhost php-7.3.8]# make install
2.13.配置PHP文件
2.13.1.复制php配置文件到安装目录
[root@localhost php-7.3.8]# cp php.ini-development /usr/local/data/php7/etc/php.ini
[root@localhost php-7.3.8]# cp /usr/local/data/php7/etc/php-fpm.conf.default /usr/local/data/php7/etc/php-fpm.conf
[root@localhost php-7.3.8]# cp /usr/local/data/php7/etc/php-fpm.d/www.conf.default /usr/local/data/php7/etc/php-fpm.d/www.conf
2.13.2.修改PHP.ini配置文件
[root@localhost php-7.3.8]# vim /usr/local/data/php7/etc/php.ini
cgi.force_redirect = 1 修改为0
expose_php = On 修改为Off
short_open_tag = Off 修改为On
max_execution_time = 30 修改为300
max_input_time = 60 修改为300
memory_limit = 128M
post_max_size = 8M 修改为32M
date.timezone = Asia/Shanghai 添加
#设置OPcache缓存
[root@localhost php-7.3.8]# vim /usr/local/data/php7/etc/php.ini
[opcache]
zend_extension=/usr/local/data/php7/lib/php/extensions/no-debug-non-zts-20180731/opcache.so 添加此目录文件
opcache.enable_cli=0 修改为1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000 修改为4000
opcache.revalidate_freq=2 修改为1
opcache.fast_shutdown=1 添加
#设置php安全函数
[root@localhost php-7.3.8]# vim /usr/local/data/php7/etc/php.ini
disable_functions =
修改为:
disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname
或者通配使用:
disable_functions = passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru
2.13.3.修改www.conf配置文件
[root@localhost php-7.3.8]# vim /usr/local/data/php7/etc/php-fpm.d/www.conf
user = nginx 把www修改为nginx
group = nginx 把www修改为nginx
listen.backlog = 511 取消注释并修改为 -1
listen.owner = www 取消注释
listen.group = www 取消注释
listen.mode = 0660 取消注释
listen.allowed_clients = 127.0.0.1 取消注释
pm = dynamic
pm.max_children = 5 修改为180
pm.start_servers = 2 修改为50
pm.min_spare_servers = 1 修改为50
pm.max_spare_servers = 3 修改为180
request_slowlog_timeout = 0 修改为50
request_terminate_timeout = 0 修改为120
slowlog = var/log/slow.log
2.13.4.修改php-fpm.conf配置文件
[root@localhost php-7.3.8]# vim /usr/local/data/php7/etc/php-fpm.conf
pid = /usr/local/data/php7/var/run/php-fpm.pid 取消注释修改路径
error_log = /usr/local/data/php7/var/log/php-fpm.log 取消注释修改路径
2.13.5.创建system系统单元文件php-fpm启动脚本
[root@localhost php-7.3.8]# vim /usr/lib/systemd/system/php-fpm.service
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=simple
PIDFile=/usr/local/data/php7/var/run/php-fpm.pid
ExecStart=/usr/local/data/php7/sbin/php-fpm --nodaemonize --fpm-config /usr/local/data/php7/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
[Install]
WantedBy=multi-user.target
2.13.6.设置PHP环境变量
[root@localhost php-7.3.8]# vim /etc/profile
export PATH=/usr/local/data/php7/bin:/usr/local/data/php7/sbin:$PATH
[root@localhost php-7.3.8]# source /etc/profile
2.13.7.启动php-fpm服务并加入开机自启动
[root@localhost php-7.3.8]# systemctl enable php-fpm.service
[root@localhost php-7.3.8]# systemctl restart php-fpm.service
2.13.8.配置nginx.conf文件
[root@localhost ~]# vim /usr/local/data/nginx/conf/nginx.conf
#修改Nginx运行组为nginx nginx;必须与/usr/local/data/php/etc7/www.conf中的user,group配置相同,否则php运行出错;
#
user nginx nginx;
#找到以下行,将location到大括号,在index后面添加index.php;
#access_log logs/host.access.log main;
#
location / {
root html;
index index.html index.htm index.php;
}
#找到以下行,将location到大括号的#都删掉同时修改SCRIPT_FILENAME后面的路径。
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/data/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
2.13.9.创建php测试文件
[root@localhost php7]# vim /usr/local/data/nginx/html/index.php
<?php phpinfo(); ?>
[root@localhost php-7.3.8]# systemctl restart nginx
[root@localhost php-7.3.8]# systemctl restart php
2.13.10.通过浏览器访问服务器IP/index.php地址
http://IP/index.php