以下是一个详细的步骤和代码示例,用于编译和安装PHP。
| 步骤 | 描述 | 代码/命令 |
|---|---|---|
| 1 | 下载PHP源码 | curl-Ohttps://secure.php.net/distributions/php-7.4.30.tar.gz |
| 2 | 解压源码 | tar-xzfphp-7.4.30.tar.gz |
| 3 | 进入源码目录 | cdphp-7.4.30 |
| 4 | 准备编译环境 | ./configure--prefix=/usr/local/php--with-config-file-path=/usr/local/php/conf--enable-fpm--enable-mysqlnd--with-mysqli--with-pdo-mysql--with-zlib--with-bz2--with-readline--enable-xml--enable-bcmath--enable-shmop--enable-sockets--enable-mbstring--enable-ftp--enable-gd--with-jpeg-dir=/usr/local/jpeg--with-png-dir=/usr/local/png--with-freetype-dir=/usr/local/freetype--enable-zip |
| 5 | 编译PHP | make |
| 6 | 安装PHP | makeinstall |
| 7 | 设置PHP环境变量 | 在你的shell配置文件(如.bashrc或.zshrc)中添加以下行:exportPATH=$PATH:/usr/local/php/bin |
| 8 | 验证PHP安装 | php-v |
以上步骤展示了如何从源码编译PHP。注意,这个例子使用了PHP 7.4.30版本,但你可以根据需要下载不同版本的源码。确保你已经安装了所有必要的依赖,以便编译过程中不会出现错误。








