PHP高级工程师|全栈工程师|WX: Aben_Ring

centos7 搭建 php7 + nginx (2)

  • 安装php

php下载地址

# 避免出错,先安装下面
yum install libzip libzip-devel libxml2-devel openssl openssl-devel bzip2 bzip2-devel curl-devel libjpeg-devel libpng libpng-devel freetype-devel gmp-devel readline-devel libxslt-devel

# 下载
wget https://www.php.net/distributions/php-7.3.11.tar.gz

# 解压
tar -zxvf  php-7.3.11.tar.gz

cd /data/source/php-7.3.11

# 编译
./configure \
 --prefix=/usr/local/php7\
 --with-config-file-path=/usr/local/php7/conf\
 --enable-fpm\
 --with-fpm-user=www\
 --with-fpm-group=www\
 --disable-rpath\
 --enable-soap\
 --with-libxml-dir\
 --with-xmlrpc\
 --with-openssl\
 --with-mhash\
 --with-pcre-regex\
 --with-zlib\
 --enable-bcmath\
 --with-bz2\
 --enable-calendar\
 --with-curl\
 --enable-exif\
 --with-pcre-dir\
 --enable-ftp\
 --with-gd\
 --with-openssl-dir\
 --with-jpeg-dir\
 --with-png-dir\
 --with-zlib-dir\
 --with-freetype-dir\
 --enable-gd-jis-conv\
 --with-gettext\
 --with-gmp\
 --with-mhash\
 --enable-mbstring\
 --with-onig\
 --with-mysqli=mysqlnd\
 --with-pdo-mysql=mysqlnd\
 --with-zlib-dir\
 --with-readline\
 --enable-shmop\
 --enable-sockets\
 --enable-sysvmsg\
 --enable-sysvsem \
 --enable-sysvshm \
 --with-libxml-dir\
 --with-xsl\
 --enable-zip\
 --with-pear\
 --enable-wddx

# 编译的时候,可能会有各种未知错误出现。直接百度就好,基本都很容易找到解决方案

# 安装
make && make install

  • 配置php

# 将源码包配置文件拷贝到安装目录
mkdir -p /usr/local/php7/conf
cp php.ini-development /usr/local/php7/conf/php.ini

# 拷贝php-fpm配置文件
cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf

# 添加用户
groupadd www
useradd -g www www
  • 设置php-fpm开机启动

vi /lib/systemd/system/php-fpm.service

内容如下,路径改成自己的php路径

[Unit]
Description=php-fpm
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/php7/sbin/php-fpm
PrivateTmp=true
[Install]
WantedBy=multi-user.target
# 设置开机启动
systemctl enable php-fpm.service

# 停止开机自启动
systemctl disable php-fpm.service         

# 启动nginx服务
systemctl start php-fpm.service          
 
# 停止服务
systemctl stop php-fpm.service           
 
# 重新启动服务
systemctl restart php-fpm.service        
 
# 查看所有已启动的服务
systemctl list-units --type=service     
 
# 查看服务当前状态
systemctl status php-fpm.service          
  • 配置nginx解析php

vi /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  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

# 重启nginx就可以了
posted @ 2019-11-04 14:49  懒牛拉车  阅读(323)  评论(0编辑  收藏  举报