Centos 7 安装 PHP 7

安装基础依赖

yum -y install wget vim pcre pcre-devel openssl openssl-devel libicu-devel gcc gcc-c++ cmake3 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 jemalloc-devel cmake boost-devel bison automake libevent libevent-devel gd gd-devel libtool* libmcrypt libmcrypt-devel mcrypt mhash libxslt libxslt-devel readline readline-devel gmp gmp-devel libcurl libcurl-devel openjpeg-devel  

下载依赖包源码

wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
wget https://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/download -O libmcrypt-2.5.8.tar.gz
wget http://download.osgeo.org/libtiff/tiff-4.0.9.tar.gz
wget https://nchc.dl.sourceforge.net/project/libpng/libpng16/1.6.35/libpng-1.6.35.tar.gz
wget http://ring.u-toyama.ac.jp/archives/graphics/freetype/freetype2/freetype-2.7.1.tar.gz
wget http://www.ijg.org/files/jpegsrc.v9a.tar.gz
wget https://github.com/libgd/libgd/releases/download/gd-2.2.5/libgd-2.2.5.tar.gz
wget https://libzip.org/download/libzip-1.5.1.tar.gz

解压

tar -xzvf *.tar.gz

安装

./configure --enable-shared
make && make install

其中libgd的安装为

./configure --prefix=/usr/local/libgd --enable-shared --with-jpeg=/usr/local/jpeg --with-png=/usr/local/libpng --with-freetype=/usr/local/freetype --with-fontconfig=/usr/local/freetype --with-xpm=/usr/ --with-tiff=/usr/local/tiff --with-webp=/usr/local/libwebp/
make && make install

其中libzip的安装为

mkdir build && cd build && cmake3 .. && make && make install

PHP安装准备工作

mkdir /usr/local/php
useradd -s /sbin/nologin www

下载PHP源码并安装

wget http://cn2.php.net/distributions/php-7.3.1.tar.gz
tar -xzvd php-7.3.1.tar.gz
cd php-7.3.1
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-pdo-mysql --with-pdo-mysql=mysqlnd --with-gd --with-iconv --with-zlib --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --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 --with-jpeg-dir --with-freetype-dir --enable-opcache --with-fpm-user=www --with-fpm-group=www
make -j2 && make install
cp php.ini-production /usr/local/php/php.ini
cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm

配置环境变量

echo "export PATH=\$PATH:/usr/local/php/bin:/usr/local/php/sbin" >> /etc/profile
source /etc/profile

优化

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

修改如下

cgi.fix_pathinfo=0
disable_functions=passthru,system,chroot,scandir,chgrp,chown,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
date.timezone =  PRC
expose_php = Off
short_open_tag = On

vim /usr/local/php/etc/php-fpm.d/www.conf

修改如下配置

listen = unix:/var/run/php-fpm.sock
listen.owner = www
listen.group = www
listen.mode = 0660

vim /usr/local/php/etc/php-fpm.conf

修改如下配置

daemonize = yes

设置开机启动

chkconfig php-fpm on

启动、停止PHP-FPM

service php-fpm start
service php-fpm stop

参考链接

https://www.cnblogs.com/Anwar/p/9744576.html

标签: none

添加新评论