Linux下安装php环境并且配置Nginx支持php-fpm模块
Linux环境安装PHP7
查看Linux 、Apache 、 MySQL 、 PHP 版本的方法
Linux下PHP开发环境搭建(Apache2.4+PHP7.1+MySQL5.7)
添加php-fpm系统服务
1、安装
- find apache的apxs配置文件
/usr/sbin/apxs
安装apache
yum -y install httpd
开启
service httpd start
关闭
pkill -9 httpd
apache的错误日志
tail -f /etc/httpd/logs/error_log
配置文件
vim /etc/httpd/conf/httpd.conf
- ./configure
#./configure --prefix=/usr/local/php
--with-apxs2=/usr/sbin/apxs
--with-curl
--with-freetype-dir
--with-gd
--with-gettext
--with-iconv-dir
--with-kerberos
--with-libdir=lib64
--with-libxml-dir
--with-mysqli
--with-openssl
--with-pcre-regex
--with-pdo-mysql
--with-pdo-sqlite
--with-pear
--with-png-dir
--with-jpeg-dir
--with-xmlrpc
--with-xsl
--with-zlib
--with-bz2
--with-mhash
--enable-fpm
--enable-bcmath
--enable-libxml
--enable-inline-optimization
--enable-gd-native-ttf
--enable-mbregex
--enable-mbstring
--enable-opcache
--enable-pcntl
--enable-shmop
--enable-soap
--enable-sockets
--enable-sysvsem
--enable-sysvshm
--enable-xml
--enable-zip
# chmod 755 /usr/lib64/httpd/modules/libphp7.so
- 启动php-fpm
# /usr/local/php/sbin/php-fpm
# netstat -tunlp |grep 9000 //linux端口占用
- 文件php.ini的默认路径
/usr/local/php/lib/php.ini
- apache配置
安装
yum -y install httpd
开启
service httpd start
vim /etc/httpd/conf/httpd.conf
service httpd restart
防火墙
vim /etc/sysconfig/iptables
service iptables restart
打印错误日志
tail -f /etc/httpd/logs/error_log
- 修改80端口
[root@guowei-baidu-cloud init.d]# service httpd start
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
解决方法
#ServerName www.example.com:80
ServerName localhost:80
- 解决端口占用问题
[root@keyog-baidu-cloud conf]# netstat -lnp|grep 81
tcp 0 0 127.0.0.1:9999 0.0.0.0:* LISTEN 12814/php server.ph
tcp 0 0 :::781 :::* LISTEN 1409/./bcm-agent
tcp 0 0 :::81 :::* LISTEN 12230/httpd
udp 0 0 fe80::f816:3eff:fee8:452:123 :::* 1553/ntpd
[root@keyog-baidu-cloud conf]# pkill -9 httpd
- 配置apache支持php
[root@iZ2ze2n6ep53tcs3n7df8xZ ~]# find / -name libphp5.so
/usr/lib64/httpd/modules/libphp5.so
修改Apache的配置文件httpd.conf
DirectoryIndex index.html index.php #添加index.php
找到:
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
添加如下内容
AddType application/x-httpd-php-source .phps
AddType application/x-httpd-php .php
检查LoadModule php5_module modules/libphp5.so 是否已经添加 libphp5.so文件是否存在
编写测试文件index.php内容如下,放到Apache的默认的Web站点目录DocumentRoot #默认路径/var/www/html
<?php
phpinfo();
?>
- 查看php的版本
为了以后方便,可以编辑 /etc/profile 添加环境变量 ,添加到最后面
vim /etc/profile
PATH=$PATH:/usr/local/php/bin
export PATH
#source /etc/profile
#php -v
PHP 7.0.32 (cli) (built: Nov 4 2018 11:19:33) ( NTS )
- 查看php安装的依赖
#php -m
2、优化