1.下載源碼包,並解壓php
#進入目錄,並下載源碼包 cd /usr/local/src/ wget http://cn2.php.net/distributions/php-5.6.30.tar.bz2 #解壓源碼包 注意這裏是用的 xjvf tar xjvf php-5.6.30.tar.bz2
2.設置編譯參數:配置編譯參數的長短,取決於咱們給它設置所要檢查的項目多少python
[root@centos001 php-5.6.30]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif
錯誤一:mysql
#輸出錯誤以下:未找到XML2配置。請檢查您的libxml2的安裝 configure: error: xml2-config not found. Please check your libxml2 installation.
解決方法:
首先,輸出結果告訴咱們缺乏配置文件,而後須要去下載一個包,可是咱們不知道名字,因此咱們先檢索一下git
#檢索咱們須要安裝的包 [root@centos001 php-5.6.30]# yum list | grep xml2 libxml2.x86_64 2.9.1-6.el7_2.3 @anaconda libxml2.i686 2.9.1-6.el7_2.3 base libxml2-devel.i686 2.9.1-6.el7_2.3 base libxml2-devel.x86_64 2.9.1-6.el7_2.3 base libxml2-python.x86_64 2.9.1-6.el7_2.3 base libxml2-static.i686 2.9.1-6.el7_2.3 base libxml2-static.x86_64 2.9.1-6.el7_2.3 base mingw32-libxml2.noarch 2.9.3-1.el7 epel mingw32-libxml2-static.noarch 2.9.3-1.el7 epel mingw64-libxml2.noarch 2.9.3-1.el7 epel mingw64-libxml2-static.noarch 2.9.3-1.el7 epel python-xml2rfc.noarch 2.5.2-2.el7 epel tinyxml2.x86_64 2.1.0-2.20140406git6ee53e7.el7 epel tinyxml2-devel.x86_64 2.1.0-2.20140406git6ee53e7.el7 epel xml2.x86_64 0.5-7.el7 epel #通常選擇devel 結尾的文件 [root@centos001 php-5.6.30]# yum install -y libxml2-devel
從新設置編譯參數
錯誤二:又出問題了sql
#輸出以下:說是 找不到一個叫OpenSSL的玩意 configure: error: Cannot find OpenSSL's <evp.h>
解決方法:和上面的差很少 找yum包來安裝apache
[root@centos001 php-5.6.30]# yum install -y openssl-devel
錯誤三:vim
checking for BZip2 in default path... not found configure: error: Please reinstall the BZip2 distribution
解決方法:找包安裝centos
[root@centos001 php-5.6.30]# yum install -y bzip2-devel
錯誤四:api
configure: error: jpeglib.h not found.
解決方法:找包安裝php7
[root@centos001 php-5.6.30]# yum install -y libjpeg-turbo-devel
錯誤五:
configure: error: png.h not found.
解決方法:
[root@centos001 php-5.6.30]# yum install -y libpng-devel
錯誤六:輸出錯誤信息而且在使用yum list搜索時也出現了錯誤
configure: error: freetype-config not found. [root@centos001 php-5.6.30]# yum list | grep - i freetype grep: i: 沒有那個文件或目錄 grep: freetype: 沒有那個文件或目錄
解決方法:不加i選項(忽略大小寫)搜索
[root@centos001 php-5.6.30]# yum install -y fretype freetype-devel
錯誤7、
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解決辦法: yum list報錯的緣由是:centos默認的yum源裏沒有咱們須要的這個包,因此須要藉助epel yum擴展源
[root@centos001 php-5.6.30]# yum install -y epel-release [root@centos001 php-5.6.30]# yum install -y libmcrypt-devel
3.從新配置編譯參數後獲得以下就是正確的,要是不放心能夠用echo $? 檢查一下
Thank you for using PHP. config.status: creating php5.spec config.status: creating main/build-defs.h config.status: creating scripts/phpize config.status: creating scripts/man1/phpize.1 config.status: creating scripts/php-config config.status: creating scripts/man1/php-config.1 config.status: creating sapi/cli/php.1 config.status: creating sapi/cgi/php-cgi.1 config.status: creating ext/phar/phar.1 config.status: creating ext/phar/phar.phar.1 config.status: creating main/php_config.h config.status: executing default commands [root@centos001 php-5.6.30]# echo $? 0
[root@centos001 php-5.6.30]# make && make install #輸出信息 Wrote PEAR system config file at: /usr/local/php/etc/pear.conf You may want to add: /usr/local/php/lib/php to your php.ini include_path /usr/local/src/php-5.6.30/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin ln -s -f phar.phar /usr/local/php/bin/phar #獲得目錄 Installing PDO headers: /usr/local/php/include/php/ext/pdo/
[root@centos001 php-5.6.30]# ls /usr/local/php/ bin etc include lib php #核心文件所在目錄 [root@centos001 php-5.6.30]# ls /usr/local/php/bin/ pear peardev pecl phar phar.phar php php-cgi php-config phpize [root@centos001 php-5.6.30]# du -sh /usr/local/php/bin/php 36M /usr/local/php/bin/php # apache 所須要的文件 及時刪掉上面的php文件也能夠^C [root@centos001 php-5.6.30]# du -sh /usr/local/apache2.4/modules/libphp5.so 37M /usr/local/apache2.4/modules/libphp5.so #查看php所加載的模塊 [root@centos001 php-5.6.30]# /usr/local/php/bin/php -m [PHP Modules]
最後:複製配置文件。由於咱們剛纔配置編譯參數時,定義了php的配置文件所在的目錄
#複製配置文件。production適用於生產環境中 [root@centos001 php-5.6.30]# cp php.ini-production /usr/local/php/etc/php.ini #用這個命令能看到php的編譯參數還有配置文件路徑(沒有複製配置文件以前,文件路徑後的配置文件信息是空的) [root@centos001 php-5.6.30]# /usr/local/php/bin/php -i |less
當咱們安裝好後怎麼使用呢?答案是須要編輯配置文件
進入下面的目錄後/php5.so 就能看見apache所須要的php模塊 用#來選擇 要不要加載這個模塊
[root@centos001 php-5.6.30]# vi /usr/local/apache2.4/conf/httpd.conf
下載安裝包並解壓
#進入目錄 cd /usr/local/src/ #下載源碼包 wget 下載地址 #解壓 注意格式 tar jxvf
# 進入源碼包目錄 [root@centos001 php-7.1.6]# cd php-7.1.6 # 配置編譯參數 [root@centos001 php-7.1.6]# ./configure --prefix=/usr/local/php7 --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php7/etc --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif
# make # make install #輸出 Installing PDO headers: /usr/local/php7/include/php/ext/pdo/
一臺機器能夠同時有兩個php存在,可是注意須要把apache調用指定好
[root@centos001 php-7.1.6]# ls /usr/local/apache2.4/modules/libphp7.so /usr/local/apache2.4/modules/libphp7.so #複製配置文件 cp php.ini-production /usr/local/php7/etc/php.ini
[root@centos001 php-7.1.6]# /usr/local/apache2.4/bin/apachectl -M
注意:一臺機器能夠同時有兩個php存在,可是注意須要把apache調用指定好
#進入配置文件後用/php5.so搜索 [root@centos001 php-7.1.6]# vim /usr/local/apache2.4/conf/httpd.conf
1、php中mysql,mysqli,mysqlnd,pdo究竟是什麼
http://blog.csdn.net/u013785951/article/details/60876816
2、查看編譯參數
http://ask.apelearn.com/question/1295