Linux 下編譯安裝 PHP 5.6

來源:互聯網
上載者:User

標籤:curl   connector   ash   ssl   選項   log   status   依賴   lan   

系統內容:

  • CentOS 6.5 / 7.0 x86_64
  • Fedora 20 x86_64
下載 PHP 源碼包
# wget http://cn2.php.net/distributions/php-5.6.0.tar.xz# xz -d php-5.6.0.tar.xz# tar xf php-5.6.0.tar -C /usr/local/src/
添加 epel 源
# rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
安裝依賴
# yum install gcc bison bison-devel zlib-devel libmcrypt-devel mcrypt mhash-devel openssl-devel libxml2-devel libcurl-devel bzip2-devel readline-devel libedit-devel sqlite-devel

註:如果你使用的 epel 7 的源,可能會沒有 mcrypt mhash mhash-devel 幾個包,在 http://dl.fedoraproject.org/pub/epel/6/x86_64/ 中下載,使用 yum localinstall xxx.rpmrpm -Uvh xxx.rpm 手動安裝即可。

建立 www 使用者
# groupadd www# useradd -g www -s /sbin/nologin -M www
編譯安裝
# cd /usr/local/src/php-5.6.0/# ./configure \--prefix=/usr/local/php56 --with-config-file-path=/usr/local/php56/etc --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-opcache --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gettext --enable-mbstring --with-iconv --with-mcrypt --with-mhash --with-openssl --enable-bcmath --enable-soap --with-libxml-dir --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --with-curl --with-zlib --enable-zip --with-bz2 --with-readline

參數說明:

""" 安裝路徑 """--prefix=/usr/local/php56 """ php.ini 設定檔路徑 """--with-config-file-path=/usr/local/php56/etc """ 最佳化選項 """--enable-inline-optimization --disable-debug --disable-rpath --enable-shared """ 啟用 opcache,預設為 ZendOptimizer+(ZendOpcache) """--enable-opcache """ FPM """--enable-fpm --with-fpm-user=www --with-fpm-group=www """ MySQL """--with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd """ 國際化與字元編碼支援 """--with-gettext --enable-mbstring --with-iconv """ 加密擴充 """--with-mcrypt --with-mhash --with-openssl """ 數學擴充 """--enable-bcmath """ Web 服務,soap 依賴 libxml """--enable-soap --with-libxml-dir """ 進程,訊號及記憶體 """--enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm """ socket & curl """--enable-sockets --with-curl """ 壓縮與歸檔 """--with-zlib --enable-zip --with-bz2 """ GNU Readline 命令列快速鍵綁定 """--with-readline

如果你的 Web Server 使用的 Apache 請添加類似:--with-apxs2=/usr/local/apache-xx/bin/apxs 參數。

關於 mysqlnd 請查看 什麼是 PHP 的 MySQL Native 驅動? 或查看 MySQL 官方介紹:MySQL native driver for PHP, 或 Installation on Unix。

PHP 5.6 內建了 phpdbg 互動式調試器,通過 --enable-phpdbg 開啟,會在 PREFIX/bin 目錄下產生一個 phpdbg 命令,感興趣的可以試一下。

更多編譯參數請使用 ./configure --help 查看。

# make -j8# make install

如果想重新安裝:

# make clean# make clean all# ./configure ...# make -j8# make install
配置 PHP

設定檔

# cp php.ini-development /usr/local/php56/etc/php.ini

php-fpm 服務

# cp /usr/local/php56/etc/php-fpm.conf.default /usr/local/php56/etc/php-fpm.conf# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm56# chmod +x /etc/init.d/php-fpm56

啟動 php-fpm

# service php-fpm56 startStarting php-fpm  done

php-fpm 可用參數 start|stop|force-quit|restart|reload|status

添加 PHP 命令到環境變數

編輯 ~/.bash_profile,將:

PATH=$PATH:$HOME/bin改為:PATH=$PATH:$HOME/bin:/usr/local/php56/bin

使 PHP 環境變數生效:

# . ~/.bash_profile

查看看 PHP 版本

# php -vPHP 5.6.0 (cli) (built: Sep 23 2014 03:44:18) Copyright (c) 1997-2014 The PHP GroupZend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies
轉載請註明出處。
本文地址:http://blog.aboutc.net/linux/65/compile-and-install-php-on-linux

Linux 下編譯安裝 PHP 5.6

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.