1.下载php压缩包:
2.解压,进入解压后的目录:
tar -xzvf php_v7.2.31.tar.gz
3.安装扩展依赖:
yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel curl curl-devel openssl openssl-devel libevent-devel cc gcc autoconf gcc-c++ unixODBC-devel nginx
4.安装 php :
cd php-7.2.31/
./configure --prefix=/usr/local/php --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysqli --with-pdo-mysql --with-zlib --with-curl --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-openssl --enable-mbstring --enable-ftp --enable-zip --enable-pcntl --enable-sockets --enable-soap --enable-mysqlnd --enable-shmop --with-zlib --with-pear
make && make install
5.写入环境变量:
export PATH=$PATH:/usr/local/php/bin
6.配置 php :
cp ./php.ini-development /usr/local/php/lib/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/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/php-fpm.service /usr/lib/systemd/system/php-fpm.service
7.配置 php.ini 文件
配置以下项:
mysqli.default_socket = /var/lib/mysql/mysql.sock
pdo_mysql.default_socket = /var/lib/mysql/mysql.sock
post_max_size = 128M
upload_max_filesize = 20M
short_open_tag = On
8.配置时区,查找 date.timezone ,去掉;,并修改成:
date.timezone = Asia/Shanghai
9.启动 php-fpm 服务:
systemctl daemon-reload
systemctl start php-fpm
systemctl enable php-fpm
10.安装邮件解释和 sqlserver 扩展:
pecl install mailparse
pecl install event
pecl install pdo_sqlsrv
pecl install sqlsrv
一直按回车.使用默认设置即可
11.添加扩展到 /usr/local/php/lib/php.ini 文件:
extension=mailparse.so
extension=event.so
extension=pdo_sqlsrv.so
extension=sqlsrv.so
12.查看php版本
php -v
13.nginx网站目录添加php测试页面
cd /usr/share/nginx/html
useradd -M -s /sbin/nologin www
nginx配置文件(/etc/nginx/nginx.conf)添加如下内容
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;#php-fpm的默认端口是9000 fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params;
}
systemctl start nginx
vim index.php
输入以下内容
<?php
phpinfo();
?>
14.访问php测试页面.查看拓展是否添加成功
浏览器打开140.143.36.35