php7 即时编译,编译PHP7.3

## 1、下载PHP源代码

首先需要从PHP官网下载PHP7.3.6的源代码,[点击下载]() 下载到自己存放的目录当中

![](https://i.vgy.me/vmAxnF.png)

![](https://i.vgy.me/o5rdDv.png)

```

解压

tar -zxf php-7.3.6.tar.gz

进入目录

cd php-7.3.6

```

## 2、安装依赖

```

sudo apt update

sudo apt install gcc

sudo apt install make

sudo apt install openssl

sudo apt install curl

sudo apt install libbz2-dev

sudo apt install libxml2-dev

sudo apt install libjpeg-dev

sudo apt install libpng-dev

sudo apt install libfreetype6-dev

sudo apt install libzip-dev

```

>[danger] 安装好这些依赖,可能还会出现一些依赖不存在的错误,到时候有什么提示错误,百度搜索安装即可

## 3、配置PHP

```

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysqli --with-pdo-mysql --with-iconv-dir --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 --enable-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts

```

>[success] +--------------------------------------------------------------------+| License: || This software is subject to the PHP License, available in this || distribution in the file LICENSE. By continuing this installation || process, you are bound by the terms of this license agreement. || If you do not agree with the terms of this license, you must abort || the installation process at this point. |+--------------------------------------------------------------------+

> Thank you for using PHP.

> 在这一步中,如果出现无法找到某个依赖的情况,可以尝试使用sudo apt install来重新安装一下没有找到的依赖

```

configure: error: Cannot find OpenSSL's

這個問題是缺少openssl-devel apt-get install libssl-dev 安裝即可

checking for cURL 7.15.5 or greater... configure: error: cURL version 7.15.5 or later is required to compile php with cURL support

這個問題是cURL版本問題解除安裝重灌下curl就好了 sudo apt-get install curl libcurl3 libcurl3-dev

configure: error: DBA: Could not find necessary header file(s).

網上找了半天都說是少了這個包 libdb-dev 我的卻不行 安裝 libgdbm-dev 這個包才ok

Configure: error: libpng.(also) not found.

apt-get install libjpeg-dev libpng-dev

configure: error: freetype-config not found.

apt-get -y install libfreetype6-dev

configure: error: Please reinstall the libzip distribution

apt install libzip-dev

```

>[danger] 途中可能出现N种错误,但是不要慌,百度谷歌慢慢搞!!!

## 4、编译并安装PHP

在完成配置后,可以直接使用make来进行编译,可以使用参数-j来指定编译线程数量来多线程编译

```

make -j4

```

编译需要一段比较长的时间,请稍作等待,编译成功后会输出如下内容

```

Build complete.Don't forget to run 'make test'.

```

然后执行以下命令进行安装

```

sudo make install

```

执行完成后,PHP将会被安装到

```

/usr/local/php/

```

## 5、验证PHP

可以使用如下指令来输出PHP的版本,来验证是否正确安装

```

/usr/local/php/bin/php -v

```

如果正确安装,将会出现如下内容

```

PHP 7.3.1 (cli) (built: Jan 18 2019 20:11:04) ( ZTS )Copyright (c) 1997-2018 The PHP GroupZend Engine v3.3.1, Copyright (c) 1998-2018 Zend Technologies

```

到这一步为止,PHP7.3.1便成功从源代码编译安装了。

## 6、复制php.ini

编译安装后的目录并不会有现成的php.ini,需要手动复制过去。在解压出来的源代码目录中,有供开发环境使用的php.ini-development和供生产环境使用的php.ini-production。输入命令来复制(以开发环境为例)

```

sudo cp php.ini-development /usr/local/php/etc/php.ini

```

![](https://i.vgy.me/zsUCgG.png)

### 附上查阅资料的网站链接

>[info] Ubuntu 安裝php 7.3遇到的錯誤:[https://www.itread01.com/content/1541669590.html](https://www.itread01.com/content/1541669590.html)

> php编译错误总结:[https://zhuanlan.zhihu.com/p/62145198](https://zhuanlan.zhihu.com/p/62145198)

> 我在编译安装 PHP 时,遇到了 “freetype-config not found”的问题:[https://www.doopsky.com/ops/981.html](https://www.doopsky.com/ops/981.html)

> ubuntu源码编译安装php常见错误解决办法:[https://blog.csdn.net/white\_\_cat/article/details/28907535](https://blog.csdn.net/white__cat/article/details/28907535)

> 安装php过程中的错误和解决方式 configure: error: jpeglib.h not found:[https://www.cnblogs.com/flywang/p/5256356.html](https://www.cnblogs.com/flywang/p/5256356.html)

> deepin下安装curl 附 CURL常用命令:[https://blog.csdn.net/jkxqj/article/details/52891090](https://blog.csdn.net/jkxqj/article/details/52891090)

## 7、启动php-fpm

```

/usr/local/php/sbin/php-fpm

```

>[danger] ERROR: failed to open configuration file '/private/etc/php-fpm.conf': No such file or directory (2)

> ERROR: failed to load configuration file '/private/etc/php-fpm.conf'

> ERROR: FPM initialization failed

> 启动就会报错,是因为在php的etc目录下面没有php-fpm.conf这个文件,我们需要在etc目录下复制一个

```

cp php-fpm.conf.default php-fpm.conf

#再次运行检查

/usr/local/php/sbin/php -t

```

>[danger] \[27-Jun-2019 22:19:57\] WARNING: Nothing matches the include pattern '/usr/local/php/etc/php-fpm.d/\*.conf' from /usr/local/php/etc/php-fpm.conf at line 143.

> \[27-Jun-2019 22:19:57\] ERROR: No pool defined. at least one pool section must be specified in config file

> \[27-Jun-2019 22:19:57\] ERROR: failed to post process the configuration

> \[27-Jun-2019 22:19:57\] ERROR: FPM initialization failed

> 检查又报错了,是因为我们include没找到.conf文件,在php-fpm.d当中时 www.conf.default这个文件我们需要修改复制出来的php-fpm.conf的include

![](https://i.vgy.me/gQAVJM.png)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值