LNMP之PHP源码编译安装

LNMP之PHP源码编译安装

Php官网

http://php.net/

实验使用:php5.5

写博客时:最新版本:Current Stable PHP 7.4.12,可以尝试,CentOS8

php编译安装脚本

yum -y install epel-release

yum -y install  gcc gcc-c++ make pcre pcre-devel zlib zlib-devel openssl openssl-devel libxml2 libxml2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel openldap openldap-devel libmcrypt libmcrypt-devel

cd /usr/local/src/

wget 'http://hk1.php.net/distributions/php-5.6.40.tar.gz'

tar -zxf php-5.6.40.tar.gz

cd php-5.6.40

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-ctype --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --with-gettext --enable-fpm


安装最新版的会遇到依赖软件版本不符合要求的情况:yum update升级

configure: error: Package requirements (sqlite3 > 3.7.4) were not met:

在Centos8环境中配置php7.4.8出现如上错误是因为缺少sqlite相关庫:

 解决方法如下:

yum -y install  sqlite-devel

类似思路解决:

yum -y install oniguruma

yum -y install oniguruma-devel

更多解决办法参考:linux系列的设置技巧汇总及问题解决办法汇总

https://blog.csdn.net/lm19770429/article/details/105627287

 


make && make install

cp php.ini-production /usr/local/php/etc/php.ini

php编译安装说明

--prefix指定php的安装目录

--with-config-file-path指定php的配置文件位置

--with-mysql、--with-mysqli让php可以操作mysql

--enable-fpm主要是nginx要来调用php语言得使用php-fpm

启动php-fpm

环境变量:export PATH=$PATH:/usr/local/php/sbin/:/usr/local/php/bin/

检查配置文件:php-fpm -t

使用默认配置文件:mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

在执行php-fpm -t仍然出错:

按照提示,采用cp php-fpm.d/www.conf.default php-fpm.d/www.conf可以解决

查看php-fpm的listen配置:cat  php-fpm.d/www.conf

listen = 127.0.0.1:9000
 

验证php-fpm的启动

  1. 进程
  2. 端口
  3. 日志

使用systemctl管理php-fpm,/usr/lib/systemd/system/php-fpm.service

[Unit]

Description=php-fpm

After=network.target

[Service]

Type=forking

ExecStart=/usr/local/php/sbin/php-fpm

[Install]

WantedBy=multi-user.target

nginx的默认配置无法处理php程序/usr/local/nginx/html/test.php

<?php

  echo "taobao zabbix";

?>

nginx+php-fpm结合的配置

location / {

            root   html;

            index  index.html index.htm index.php;

        }

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;

        }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值