標籤:
PHP(外文名:PHP: Hypertext Preprocessor,中文名:“超文本前置處理器”)是一種通用開源指令碼語言。文法吸收了C語言、Java和Perl的特點,利於學習,使用廣泛,主要適用於Web開發領域。PHP以其開發原始碼,免費,快捷,跨平台,高效,物件導向,強大的生動影像建立等功能深受廣大開發人員的喜愛。本文描述基於CentOS 6.7下編譯安裝PHP 5.6.9。
一、相關依賴包安裝
1、示範環境# more /etc/redhat-release CentOS release 6.7 (Final)2、擴充支援(mcrypt、mhash擴充和libevent)如果想讓編譯的php支援mcrypt、mhash擴充和libevent,需要安裝以下包 libmcrypt libmcrypt-devel mhash mhash-devel說明:mcrypt擴充庫可以實現加密解密功能,就是既能將明文加密,也可以密文還原。mhash是基於離散數學原理的無法復原向的php加密方式擴充庫,其在預設情況下不開啟。mhash的可以用於建立校正數值,訊息摘要,訊息認證碼,以及無需原文的關鍵資訊儲存(如密碼)等。centos源不能安裝libmcrypt-devel,由於著作權的原因沒有內建mcrypt的包可以使用第三方源,這樣還可以使用yum來安裝安裝第三方yum源 # wget http://www.atomicorp.com/installers/atomic # sh ./atomic使用yum命令安裝 # yum install php-mcrypt libmcrypt libmcrypt-devel mhash mhash-devel3、libevent相關包可以根據需要安裝libevent,系統一般會內建libevent,但版本有些低。因此可以升級安裝如下兩個rpm包。 # yum install libevent libevent-devel說明:libevent是一個非同步事件通知庫檔案,其API提供了在某檔案描述上發生某事件時或其逾時時執行回呼函數的機制它主要用來替換事件驅動的網路伺服器上的event loop機制。目前來說, libevent支援/dev/poll、kqueue、select、poll、epoll及Solaris的event ports。4、支援xml的相關包支援xml的rpm包bzip2 是一個基於Burrows-Wheeler 變換的無損壓縮軟體能夠高效的完成檔案資料的壓縮libcurl主要功能就是用不同的協議串連和溝通不同的伺服器,也就是相當封裝了的sockPHP libcurl允許你用不同的協議串連和溝通不同的伺服器 # yum install libxml2 libxml2-devel bzip2-devel libcurl-devel5、圖形相關的rpm包通常對應的錯誤提示:JIS-mapped Japanese font support in GD # yum install libjpeg-devel libpng-devel freetype-devel
二、編譯安裝php-5.6.9
首先下載源碼包至本地目錄,下載位置http://mirrors.sohu.com/php/# pwd /usr/local/src# tar -xf php-5.6.9.tar.gz# cd ..# ln -sv ./src/php-5.6.9 php# cd php/# ./configure --prefix=/usr/local/php \ --with-mysql=/usr/local/mysql \ --with-openssl \ --enable-fpm \ --enable-sockets \ --enable-sysvshm \ --enable-ftp \ --with-mysqli=/usr/local/mysql/bin/mysql_config \ --enable-mbstring \ --with-freetype-dir \ --with-jpeg-dir \ --with-png-dir \ --with-zlib-dir \ --with-libxml-dir=/usr \ --enable-xml \ --with-mhash \ --with-mcrypt \ --with-config-file-path=/etc/php/php.ini \ --with-config-file-scan-dir=/etc/php/php.d \ --with-bz2 \ --with-curl \ --with-pear \ --with-gd # make && make install###以下為安裝完畢之後的提示資訊 Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/ Installing PHP CLI binary: /usr/local/php/bin/ Installing PHP CLI man page: /usr/local/php/php/man/man1/ Installing PHP FPM binary: /usr/local/php/sbin/ Installing PHP FPM config: /usr/local/php/etc/ Installing PHP FPM man page: /usr/local/php/php/man/man8/ Installing PHP FPM status page: /usr/local/php/php/php/fpm/ Installing PHP CGI binary: /usr/local/php/bin/ Installing PHP CGI man page: /usr/local/php/php/man/man1/ Installing build environment: /usr/local/php/lib/php/build/ Installing header files: /usr/local/php/include/php/ Installing helper programs: /usr/local/php/bin/ program: phpize program: php-config Installing man pages: /usr/local/php/php/man/man1/ page: phpize.1 ### Author : Leshami page: php-config.1 ### Blog : http://blog.csdn.net/leshami Installing PEAR environment: /usr/local/php/lib/php/ [PEAR] Archive_Tar - installed: 1.3.12 [PEAR] Console_Getopt - installed: 1.3.1 [PEAR] Structures_Graph- installed: 1.0.4 [PEAR] XML_Util - installed: 1.2.3 [PEAR] PEAR - installed: 1.9.5 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/php/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin ln -s -f /usr/local/php/bin/phar.phar /usr/local/php/bin/phar Installing PDO headers: /usr/local/php/include/php/ext/pdo/###建立php配置目錄 # mkdir -pv /etc/php/php.d###php配置 php.ini是php運行核心設定檔 php-fpm.conf是php-fpm進程服務的設定檔# cp /usr/local/php/php.ini-production /etc/php/php.ini# cp /usr/local/php/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm# chmod 755 /etc/init.d/php-fpm# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf###測試php配置# /usr/local/php/sbin/php-fpm -t[23-May-2016 20:03:52] NOTICE: configuration file /usr/local/php/etc/php-fpm.conf test is successful# chkconfig --add php-fpm# chkconfig php-fpm on# service php-fpm start Starting php-fpm done# ps -ef|grep php root 45690 1 0 20:07 ? 00:00:00 php-fpm: master process(/usr/local/php/etc/php-fpm.conf) nobody 45691 45690 0 20:07 ? 00:00:00 php-fpm: pool www nobody 45692 45690 0 20:07 ? 00:00:00 php-fpm: pool www root 45694 3441 0 20:07 pts/4 00:00:00 grep php# netstat -nltp|grep 9000 tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 45690/php-fpm
三、配置apache訪問PHP
###開啟以下模組# vim /etc/httpd24/httpd.conf ###注意此處,我這裡是單獨編譯安裝的httpd2.4版本,所以路徑有所不同 LoadModule proxy_module modeles/mod_proxy.so LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps ProxyRequests Off ###關閉正向 Proxy,開啟下行的反向 Proxy ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/$1# service httpd24 restart Stopping httpd24: [ OK ] Starting httpd24: [ OK ]
四、驗證PHP
###編寫一個php頁面測試# echo "> <html>> <h1>This is a php test page.</h1>> <?php> phpinfo();> ?>> </html>">>/usr/local/apache/htdocs/index.php ###測試PHP# curl -I http://localhost:90/index.phpHTTP/1.1 200 OKDate: Fri, 15 Jul 2016 03:16:50 GMTServer: Apache/2.4.9 (Unix)X-Powered-By: PHP/5.6.9Content-Type: text/html; charset=UTF-8
Linux 6 下編譯安裝 PHP 5.6