返回顶部
首页 > 资讯 > 后端开发 > PHP编程 >PHP源码编译安装
  • 493
分享到

PHP源码编译安装

phpsqliteubuntu 2023-09-21 13:09:58 493人浏览 泡泡鱼
摘要

目录 编译环境编译过程运行配置运行环境1. 创建php.ini文件2. 创建 php-fpm.conf文件3. 创建 www.conf文件4. 配置连接socket为文件(可选)5. 配置ng

目录

编译环境

  1. 编译机器

ubuntu 18.04

  1. 源码

https://www.PHP.net/distributions/php-8.1.5.tar.gz

源码包从何获取?https://www.php.net/releases/

编译过程

  1. 配置编译环境
./configure --prefix=/usr/local/php --enable-fpm --with-pdo-Mysql --without-pdo-sqlite --without-sqlite3

不知道环境如何配置怎么办?
使用./configure -h查看使用帮助,再根据自己的需求,启用或禁用某些功能或模块。

强烈建议配置--prefix到一个指定的目录,这样make install安装时就会把相关的产物只安装到这一个目录下,在卸载软件时,可以直接删除此目录即可(没有一个方便快捷的指令可以直接卸载软件)。

  1. 开始编译
# make.......Generating phar.phpGenerating phar.pharPEAR package PHP_ArcHive not installed: generated phar will require PHP's phar extension be enabled.clicommand.incpharcommand.incphar.incinvertedregexiterator.incdirectorytreeiterator.incdirectorygraphiterator.incBuild complete.Don't forget to run 'make test'.

编译相对是比较耗时的,只需要耐心等待即可。

  1. 安装
# make installInstalling shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20210902/Installing PHP CLI binary:        /usr/local/php/bin/Installing PHP CLI man page:      /usr/local/php/php/man/man1/Installing PHP FPM binary:        /usr/local/php/sbin/Installing PHP FPM defconfig:     /usr/local/php/etc/Installing PHP FPM man page:      /usr/local/php/php/man/man8/Installing PHP FPM status page:   /usr/local/php/php/php/fpm/Installing phpdbg binary:         /usr/local/php/bin/Installing phpdbg man page:       /usr/local/php/php/man/man1/Installing PHP CGI binary:        /usr/local/php/bin/Installing PHP CGI man page:      /usr/local/php/php/man/man1/Installing build environment:     /usr/local/php/lib/php/build/Installing header files:          /usr/local/php/include/php/Installing helper programs:       /usr/local/php/bin/  program: phpize  program: php-configInstalling man pages:             /usr/local/php/php/man/man1/  page: phpize.1  page: php-config.1/root/php/php-8.1.5/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin/phar.pharln -s -f phar.phar /usr/local/php/bin/pharInstalling PDO headers:           /usr/local/php/include/php/ext/pdo/

运行

配置运行环境

运行模式: Nginx+php
配置文件直接使用默认的默认文件即可。这些配置文件在安装目录下都有相应的示例,如果没有特别的需求,直接使用默认的配置文件即可。

1. 创建php.ini文件

直接从项目源码复制php.ini.production配置文件到/usr/local/php/etc目录。
make install并没有把php.ini文件安装到配置文件中,所以需要手动copy。php.ini

2. 创建 php-fpm.conf文件

/usr/local/php/etC# cp php-fpm.conf.default php-fpm.conf

3. 创建 www.conf文件

/usr/local/php/etc/php-fpm.d# cp www.conf.default www.conf

4. 配置连接Socket为文件(可选)

默认是在开启了本地的9000端口,会占用一定的系统资源,因为只给本机使用,不如socket文件效率高,且nginx又支持socket文件,所以直接配置成socket文件吧。使用分号把listen = 127.0.0.1:9000 这一行注释掉,再添加一行 listen = /usr/local/php/var/run/php-fpm.sock即可。

; The address on which to accept FastCGI requests.; Valid syntaxes are:;   'ip.add.re.ss:port'    - to listen on a tcp socket to a specific IPv4 address on;a specific port;;   '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on;a specific port;;   'port'                 - to listen on a TCP socket to all addresses;(IPv6 and IPv4-mapped) on a specific port;;   '/path/to/unix/socket' - to listen on a unix socket.; Note: This value is mandatory.;listen = 127.0.0.1:9000listen = /usr/local/php/var/run/php-fpm.sock

5. 配置nginx

Http{    server{        location ~ \.php$ {            fastcgi_pass   unix:/usr/local/php/var/run/php-fpm.sock;            fastcgi_index  index.php;            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;            include        fastcgi_params;        }     }}

启动php

cd /usr/local/phpsbin/php-fpm -c etc -y etc/php-fpm.conf

关于启动参数的作用,可以通过php-fpm -v 来查看。

  • -c 指定php.ini配置文件所在目录
  • -y 指定FastCGI进程管理的配置文件

php与php-fpm的关系

启动应用启动的php-fpm程序,而不是php,这是为什么呢?

php

php程序是在命令行中执行php脚本的

php-fpm

php-fpm是与来与WEB服务器通信,并执行php脚本的,它是一个守护进程,一直驻留在系统中。

小技巧

  1. 查看php的配置参数
php -i
  1. 检查php的语法是否正确
php -l xxx.php

遇到的问题

  1. pkg-config库过旧问题

解决方法:apt install pkg-config

configure: error: in `/root/php/php-8.1.5':configure: error: The pkg-config script could not be found or is too old.  Make sure itis in your PATH or set the PKG_CONFIG environment variable to the fullpath to pkg-config.Alternatively, you may set the environment variables LIBXML_CFLAGSand LIBXML_LIBS to avoid the need to call pkg-config.See the pkg-config man page for more details.To get pkg-config, see .See `config.log' for more details
  1. libxml-2.0库不存在

解决方法:apt install libxml2-dev

checking for libxml-2.0 >= 2.9.0... noconfigure: error: Package requirements (libxml-2.0 >= 2.9.0) were not met:No package 'libxml-2.0' foundConsider adjusting the PKG_CONFIG_PATH environment variable if youinstalled software in a non-standard prefix.
  1. sqlite3库不存在

解决方法:添加 --without-sqlite3
原因:并不使用sqlite3库,所以编译的时候可以直接去除此模块,这样也系统也能少安装一个无用的库。

checking for sqlite3 >= 3.7.7... noconfigure: error: Package requirements (sqlite3 >= 3.7.7) were not met:No package 'sqlite3' foundConsider adjusting the PKG_CONFIG_PATH environment variable if youinstalled software in a non-standard prefix.

来源地址:https://blog.csdn.net/mushanshui/article/details/124767064

--结束END--

本文标题: PHP源码编译安装

本文链接: https://www.lsjlt.com/news/414042.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作