## 1、下載PHP源代碼
首先需要從PHP官網下載PHP7.3.6的源代碼,[點擊下載]() 下載到自己存放的目錄當中


```
解壓
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
```

### 附上查閱資料的網站鏈接
>[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

- 基礎
- 安裝PHP
- 語言基礎
- 變量
- 變量操作
- 超全局數組變量
- 變量作用域
- 變量傳值方式
- 常量
- 數據類型
- 運算符
- 流程控制
- 文件包含
- 錯誤處理
- 字符串操作
- 數組
- 函數
- 進階
- 面向對象
- 提高
- TP
- 安裝項目
- 框架基礎知識
- 命令創建模塊
- URL生命周期
- 路由操作
- Request請求類
- 參數綁定
- 依賴注入
- 模板操作
- 查詢操作
- 添加操作
- laravel
- ☆目錄結構
- CSRF攻擊
- ☆路由
- ☆控制器
- ☆請求類
- ☆視圖
- ☆模板繼承
- ☆表單驗證
- ☆DB類
- ☆模型
- ☆數據庫遷移
- 類型、修飾、索引
- ☆數據填充
- ☆數據分頁
- ☆session處理
- ☆中間件
- ☆緩存操作
- ☆文件上傳
- ☆接口操作
- ☆擴展插件
- restful
- 工作
- 工作記錄
- QQ登錄
- 新浪登錄
- 微信登錄
- sphinx搜索
- 數據庫
- MySQL
- ☆數據庫操作
- ☆數據表操作
- ☆數據的操作
- 待修改
- 優化
- 存儲引擎選擇
- 列表類型選擇
- 范式
- 慢日志查詢
- 精準時間記錄查詢
- 計劃任務 explain
- 索引
- 索與事務
- 查詢緩存
- 存儲過程
- 觸發器
- 分區
- 分表
- sphinx
- 讀寫分離
- 搜索優化
- 網站靜態化
- Memcache
- Mongodb
- Readis
- php使用redis
- 服務器
- Linux
- 目錄結構
- 常用命令
- VIM編輯器
- 用戶與用戶組
- 權限管理
- 運行級別
- 網絡模式
- ssh
- 軟件安裝
- 計劃任務
- Ubuntu
- 編譯PHP7.3
- 編譯MySQL
- 編譯Nginx
- apache虛擬機配置
- 安裝composer
- Nginx
- Git