Linux下安裝php

svoid發表於2015-04-19

安裝 apache

安裝 apache 依賴於apr,apr-util,pcre
shell> tar zxvf httpd-2.4.12.tar.gz
shell> tar zxvf apr-1.5.1.tar.gz
shell> tar zxvf apr-util-1.5.4.tar.gz
shell> tar zxvf pcre-8.36.tar.gz
shell> mv apr-1.5.1 httpd-2.4.12/srclib/apr
shell> mv apr-util-1.5.4 httpd-2.4.12/srclib/apr-util

shell> cd pcre-8.36
shell> ./configure --prefix=/usr/local/pcre
shell> make && make install 

shell> cd ../httpd-2.4.12
shell> ./configure --prefix=/usr/local/apache2 --with-pcre=/usr/local/pcre --enable-so
shell> make && make install

測試
shell> /usr/local/apache2/bin/apachectl start
shell> ps -ef |grep httpd
root      1872     1  0 17:24 ?        00:00:00 /usr/local/apache2/bin/httpd -k start
daemon    1873  1872  0 17:24 ?        00:00:00 /usr/local/apache2/bin/httpd -k start
daemon    1874  1872  0 17:24 ?        00:00:00 /usr/local/apache2/bin/httpd -k start
daemon    1875  1872  0 17:24 ?        00:00:00 /usr/local/apache2/bin/httpd -k start
瀏覽器訪問該IP顯示`It works!`

安裝 php

安裝依賴包
shell> yum install automake autoconf libtool bison libxml2 libxml2-devel

shell> xz -d php-5.5.23.tar.xz
shell> tar xvf php-5.5.23.tar
shell> cd php-5.5.23

shell> ./configure --prefix=/usr/local/php --enable-fpm --with-mysql --with-apxs2=/usr/local/apache2/bin/apxs
shell> make && make install 
chmod 755 /usr/local/apache2/modules/libphp5.so
[activating module `php5' in /usr/local/apache2/conf/httpd.conf]
Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-zts-20121212/
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
  page: php-config.1
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
/tool/php-5.5.23/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/

配置Apache支援php

修改預設路徑
shell> mkdir -p /var/www
shell> vi /usr/local/apache2/conf/httpd.conf 
===================================================
# 新增模組
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule php5_module    modules/libphp5.so

# 修改檔案根目錄
DocumentRoot "/var/www"



    DirectoryIndex index.php index.html


# 新增apache對php支援
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
===================================================

測試

shell> vi /var/www/index.php 
===================================================

 phpinfo();
?>
===================================================

重新通過瀏覽器訪問該IP顯示`PHP Version 5.5.23`

參考:
http://www.cnblogs.com/fly1988happy/archive/2011/12/14/2288096.html

整理自網路

Svoid
2015-04-18

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29733787/viewspace-1585540/,如需轉載,請註明出處,否則將追究法律責任。

相關文章