*安装前准备
groupadd www #创建www用户组
useradd -g www www -s /bin/false #创建www用户并加入www用户组,不允许www用户登陆系统
依赖包
yum -y install libxml2
yum -y install libxml2-devel
yum -y install openssl
yum -y install openssl-devel
yum -y install curl-devel
yum -y install libjpeg-devel
yum -y install libpng-devel
yum -y install freetype-devel
yum -y install bison
yum -y install autoconf
PHP语法分析器re2c
wget -c https://sourceforge.net/projects/re2c/files/1.0.1/re2c-1.0.1.tar.gz/download
tar zxvf re2c-1.0.1.tar.gz
./configure --prefix=/usr/local/re2c
make
make install
加密支持扩展库libmcrypt
wget -c https://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/download
tar zxvf libmcrypt-2.5.8.tar.gz #解压
cd libmcrypt-2.5.8 #进入安装目录
./configure #配置
make #编译
make install #安装
加密方式扩展库mhash
wget -c https://acelnmp.googlecode.com/files/mhash-0.9.9.9.tar.gz
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure
make
make install
加密方式扩展库mcrypt
wget -c https://lcmp.googlecode.com/files/mcrypt-2.6.8.tar.gz
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
ln -s /usr/local/bin/libmcrypt_config /usr/bin/libmcrypt_config #添加软连接
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH #添加环境变量
./configure
make
make install
安装
wget -c http://hk1.php.net/get/php-7.2.14.tar.gz/from/this/mirror
tar -xvf mirror
cd php-7.2.14
./configure \
--prefix=/usr/local/php \
--exec-prefix=/usr/local/php \
--bindir=/usr/local/php/bin \
--sbindir=/usr/local/php/sbin \
--includedir=/usr/local/php/include \
--libdir=/usr/local/php/lib/php \
--mandir=/usr/local/php/php/man \
--with-config-file-path=/usr/local/php/etc \
--with-mysql-sock=/tmp/mysql.sock \
--with-mhash \
--with-openssl \
--with-mysqli=shared,mysqlnd \
--with-pdo-mysql=shared,mysqlnd \
--with-gd \
--with-iconv \
--with-zlib \
--enable-zip \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-mbregex \
--enable-mbstring \
--enable-ftp \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-soap \
--without-pear \
--with-gettext \
--enable-session \
--with-curl \
--with-jpeg-dir \
--with-freetype-dir \
--enable-opcache \
--enable-fpm \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--without-gdbm \
--enable-fast-install \
--disable-fileinfo;
make
make install
配置PHP
cp php.ini-production /usr/local/php/etc/php.ini #复制php配置文件到安装目录
rm -rf /etc/php.ini
ln -s /usr/local/php/etc/php.ini /etc/php.ini #删除系统自带配置文件
ls -l /etc/php.ini #添加软链接到 /etc目录
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf #复制模板文件为php-fpm配置
ln -s /usr/local/php/etc/php-fpm.conf /etc/php-fpm.conf #添加软件链接到 /etc目录
vim /usr/local/php/etc/php-fpm.conf #pid = run/php-fpm.pid 如果这个选项在配置文件存在就取消掉注释使用,如果不存在可以忽略,请勿手动添加,否则PHP启动会报错。
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
vim /usr/local/php/etc/php-fpm.d/www.conf #将user=nginx group=nginx 中的nginx改为www用户
##设置php-fpm开机自启动
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
ls -l /etc/init.d/php-fpm
chmod 755 /etc/init.d/php-fpm
ls -l /etc/init.d/php-fpm
vim /usr/local/php/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
找到:date.timezone =
修改为:date.timezone = PRC #设置时区
找到:expose_php = On
修改为:expose_php = Off #禁止显示php版本的信息
找到:short_open_tag = Off
修改为:short_open_tag = On #支持php短标签
找到opcache.enable=0
修改为opcache.enable=1 #php支持opcode缓存
找到:opcache.enable_cli=1 #php支持opcode缓存
修改为:opcache.enable_cli=0
在最后一行添加:zend_extension=opcache.so #开启opcode缓存功能 (在文本按Shift+G就能跳到最后一行)
**/
配置nginx支持php
vim /usr/local/nginx/conf/nginx.conf
/**
user www www; #首行user去掉注释,修改Nginx运行组为www www;必须与/usr/local/php/etc/php-fpm.d/www.conf中的user,group配置相同,否则php运行出错
location / {
root html;
index index.html index.htm index.php; #添加index.php
}
#取消FastCGI server部分location的注释,注意fastcgi_param行的参数,改为$document_root$fastcgi_script_name,或者使用绝对路径
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
**/
设置开机自启动
chkconfig php-fpm on
chkconfig --level 35 php-fpm on
service php-fpm restart
设置环境变量
echo "export PATH=$PATH:/usr/local/php/bin">>/etc/profile
source /etc/profile //让PATH变量修改立即生效