PHP安装
1、安装PHP7
1.1部署相关依赖
1.1.1安装Libmcrypt
[root@localhost php]# tar -zxvf libmcrypt-2.5.8.tar.gz
[root@localhost php]# cd libmcrypt-2.5.8
[root@localhost libmcrypt-2.5.8]# ./configure && make && make install
1.1.2安装mhash
[root@localhost php]# tar -zxvf mhash-0.9.9.9.tar.gz
[root@localhost php]# cd mhash-0.9.9.9
[root@localhost mhash-0.9.9.9]# ./configure && make && make install
1.1.3安装mcrypt
[root@localhost php]# tar -zxvf mcrypt-2.6.8.tar.gz
[root@localhost php]# cd mcrypt-2.6.8
[root@localhost mcrypt-2.6.8]# ./configure && make && make install
#第一种报错
提示出错,首先提示
*** Could not run libmcrypt test program, checking why…
*** The test program failed to compile or link. See the file config.log for the
*** exact error that occured. This usually means LIBMCRYPT was incorrectly installed
*** or that you have moved LIBMCRYPT since it was installed. In the latter case, you
*** may want to edit the libmcrypt-config script: no
configure: error: *** libmcrypt was not found
#解决方法 ln -s /usr/local/bin/libmcrypt_config /usr/bin/libmcrypt_config
#第二种报错
*** Could not run libmcrypt test program, checking why…
*** The test program compiled, but did not run. This usually means
*** that the run-time linker is not finding LIBMCRYPT or finding the wrong
*** version of LIBMCRYPT. If it is not finding LIBMCRYPT, you’ll need to set your
*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point
*** to the installed location Also, make sure you have run ldconfig if that
*** is required on your system
***
*** If you have an old version installed, it is best to remove it, although
*** you may also be able to get things to work by modifying LD_LIBRARY_PATH
***
configure: error: *** libmcrypt was not found
#解决办法 export LD_LIBRARY_PATH=/usr/local/lib: LD_LIBRARY_PATH
1.2解压并安装php7
[root@localhost php]# tar -xvf php-7.2.0.tar.gz
[root@localhost php]# cd php-7.2.0
#第一种编译方法
./configure \
--prefix=/usr/local/php7 \
--with-config-file-path=/etc \
--enable-fpm
#第二种编译方法
./configure \
--prefix=/usr/local/php7 \
--with-config-file-path=/etc \
--with-bz2 \
--with-curl \
--with-gd \
--with-openssl \
--with-gettext \
--with-xsl \
--with-zlib-dir \
--enable-pcntl \
--enable-sockets \
--enable-calendar \
--enable-exif \
--enable-ftp \
--enable-mbstring \
--enable-fpm \
--enable-zip \
--with-mcrypt \
--with-pdo-mysql=/usr/bin/mysql \
--with-mysql=—with-mysqli=/usr/bin/mysql_config
####出现(Thank you for using PHP.即为成功)
1.2.1安装php7
[root@localhost php]# make && make install
####(如果看到Don’t forget to run ‘make test’ 编译成功)
1.3配置环境变量
#将 PHP放入环境变量才能执行 php xxx.php 否则执行php为 /usr/local/php7/bin/php test.php
[root@localhost php]# export NGINX_HOME=/usr/local/nginx
[root@localhost php]# export PATH=$PATH:$NGINX_HOME/sbin
[root@localhost php]# export PATH=$PATH:/usr/local/php7/bin
#保存后
source /etc/profile
[root@localhost php]# php -v
[root@localhost php]# php -m
#重启nginx
systemctl restart nginx
1.4配置php
[root@localhost php-7.2.0]# cp php.ini-production /usr/local/php7/etc/php.ini
[root@localhost php7]# vi /usr/local/php7/etc/php.ini
zend_extension=/usr/local/php7/lib/php/extensions/no-debug-non-zts-20160303/opcache.so
#复制php-fpm.conf
[root@localhost php7]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
[root@localhost php7]# vim /usr/local/php7/etc/php-fpm.conf
#把pid 改成 /run/php-fpm.pid
#编辑php-fpm配置www.conf会加载在php-fpm.conf中
[root@localhost php7]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
[root@localhost php-7.2.0]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-7.2.0]# chmod +x /etc/init.d/php-fpm
1.5将php-fpm加入管理器到systemctl
[root@localhost php7]# vim /usr/lib/systemd/system/php-fpm.service
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=simple
PIDFile=/run/php-fpm.pid
ExecStart=/usr/local/php7/sbin/php-fpm —nodaemonize —fpm-config /usr/local/php7/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID
[Install]
WantedBy=multi-user.target
#php-fpm相关命令
systemctl enable *.service #开机运行服务
systemctl disable *.service #取消开机运行
systemctl is-enabled *.service #服务是否开机运行
systemctl start *.service #启动服务
systemctl stop *.service #停止服务
systemctl restart *.service #重启服务
systemctl reload *.service #重新加载服务配置文件
systemctl status *.service #查询服务运行状态
systemctl —failed #显示启动失败的服务
1.6修改php.ini
[root@localhost php7]# vim /usr/local/php7/etc/php.ini
expose_php=Off
##为了防止黑客获取服务器中php版本的信息,可以关闭该信息斜路在http头中
error_reporting=E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE