PHP编译安装–纯干货
1 安装环境依赖包
yum -y install \
libjpeg \
libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 \
libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel
2 编译安装
cd /opt
tar jxvf php-7.1.10.tar.bz2 '//将下载的软件包解压到/opt'
cd php-7.1.10
配置
./configure \
--prefix=/usr/local/php \
--with-mysql-sock=/usr/local/mysql/mysql.sock \
--with-mysqli \
--with-zlib \
--with-curl \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-openssl \
--enable-fpm \
--enable-mbstring \
--enable-xml \
--enable-session \
--enable-ftp \
--enable-pdo \
--enable-tokenizer \
--enable-zip
make && make install
3 配置PHP的三个配置文件
php有三个配置文件
- php.ini核心配置文件
- php-fpm.conf进程服务配置文件
- www.conf 扩展配置文件’
cp php.ini-development /usr/local/php/lib/php.ini
vim /usr/local/php/lib/php.ini
‘//找到以下两行的位置,修改这两行’
1170 mysqli.default_socket = /usr/local/mysql/mysql.sock
939 date.timezone = Asia/Shanghai '//找到后,前方的;注释要去掉'
/usr/local/php/bin/php -m/验证安装的模块
[root@localhost php-7.1.10]# /usr/local/php/bin/php -m
[PHP Modules]
Core
ctype
curl
date
dom
fileinfo
filter
ftp
gd
hash
iconv
json
libxml
mbstring
mysqli
mysqlnd
openssl
pcre
PDO
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zip
zlib
[Zend Modules]
4 配置及优化FPM模块
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
cd /usr/local/php/etc/php-fpm.d/
cp www.conf.default www.conf
cd /usr/local/php/etc/
vim php-fpm.conf
17行 pid = run/php-fpm.pid 前面“ ;“ 去掉
/usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini
创建软连接
ln -s /usr/local/php/bin/* /usr/local/bin/
ps aux | grep -c “php-fpm”
示例
[root@localhost etc]# ps aux | grep -c "php-fpm"
4
5 让nginx支持PHP功能
vim /usr/local/nginx/conf/nginx.conf //找到下面字段将注释去掉,并更改站点目录
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
cd /usr/local/nginx/html/
mv index.html index.html.bak
vim /usr/local/nginx/html/index.php
<?phpi phpinfo(); ?>systemctl restart nginx
在网页测试http://14.0.0.14/index.php
cd /usr/local/nginx/html/
mv index.html index.html.bak
vim /usr/local/nginx/html/index.php
<?phpi phpinfo(); ?>systemctl restart nginx
在网页测试http://14.0.0.14/index.php