目录
编译环境 编译机
乌班图18.04
源码包
哪里可以获取源码包?
编译过程配置编译环境
./configure --prefix=/usr/local/php --enable-fpm --with-pdo-mysql --without-pdo-sqlite --without-sqlite3
我不知道如何配置环境,该怎么办?
使用./configure -h 查看使用帮助,然后根据需要启用或禁用各个功能或模块。
强烈建议配置--prefix到指定目录,这样make install在安装时只会将相关产品安装到该目录。 卸载软件时,可以直接删除该目录(没有方便快捷的命令可以直接卸载软件)。
开始编译
# make
.......
Generating phar.php
Generating phar.phar
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
clicommand.inc
pharcommand.inc
phar.inc
invertedregexiterator.inc
directorytreeiterator.inc
directorygraphiterator.inc
Build complete.
Don't forget to run 'make test'.
编译比较耗时php源码编译编译器,耐心等待即可。
安装
# make install
Installing 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-config
Installing 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.phar
ln -s -f phar.phar /usr/local/php/bin/phar
Installing PDO headers: /usr/local/php/include/php/ext/pdo/
运行配置运行环境
运行方式:nginx+php
配置文件可以直接使用默认的default文件。 这些配置文件在安装目录下都有对应的示例。 如果没有特殊要求,可以直接使用默认的配置文件。
1.创建php.ini文件
直接将项目源码中的php.ini.Production配置文件复制到/usr/local/php/etc目录下。
make install 不会将 php.ini 文件安装到配置文件中,因此需要自动复制。 php.ini
2.创建php-fpm.conf文件
/usr/local/php/etc# cp php-fpm.conf.default php-fpm.conf
3. 创建文件
/usr/local/php/etc/php-fpm.d# cp www.conf.default www.conf
4.将连接套接字配置为文件(可选)
默认情况下,本地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:9000
listen = /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/php
sbin/php-fpm -c etc -y etc/php-fpm.conf
关于启动参数的作用php源码编译编译器,可以通过php-fpm -v来查看。
php与php-fpm的关系
启动的是应用程序启动的php-fpm程序而不是php,这是为什么呢?
php
php程序在命令行执行php脚本
php-fpm
php-fpm 与 Web 服务器通信并执行 php 脚本。 它是一个始终驻留在系统中的守护进程。
查看php配置参数的技巧
php -i
检查php的句型是否正确
php -l xxx.php
遇到的问题 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 it
is in your PATH or set the PKG_CONFIG environment variable to the full
path to pkg-config.
Alternatively, you may set the environment variables LIBXML_CFLAGS
and 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
libxml-2.0 库不存在
解决方案:apt install libxml2-dev
checking for libxml-2.0 >= 2.9.0... no
configure: error: Package requirements (libxml-2.0 >= 2.9.0) were not met:
No package 'libxml-2.0' found
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
sqlite3库不存在
解决方案:添加--without-sqlite3
原因:没有使用到sqlite3库,所以编译的时候可以直接去掉这个模块,这样系统也可以省去安装一个无用的库。
checking for sqlite3 >= 3.7.7... no
configure: error: Package requirements (sqlite3 >= 3.7.7) were not met:
No package 'sqlite3' found
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.