Linux下面安裝PHP詳解

目前PHP項目開發幾種比較流行的架構搭建中,LNMP在性能方面是最好的,正因為如此,使得LNMP架構逐漸流行起來,今天,前面提到了Nginx部署,由於項目實際環境的需要,今天就在說一下怎麼部署PHP。

Linux下面安裝PHP詳解

環境

  • CentOS 6.3

  • PHP 5.6

安裝步驟

1. 下載並安裝PHP:先下載文件到對應的目錄,然後解壓文件。

wget http://cn2.php.net/distributions/php-5.6.0.tar.xz

xz -d php-5.6.0.tar.xz

tar xvf php-5.6.0.tar

cd php-5.6.0

2. 安裝PHP依賴包

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

如果你是複製後,使用命令,請保證命令為一行。

3. 創建www用戶:這是PHP5.6的默認用戶,否則可能在啟動PHP的時候會報錯。

groupadd www

useradd -g www -s /sbin/nologin -M www

4. 編譯並安裝PHP

./configure --prefix=/usr/local/webserver/php --with-config-file-path=/usr/local/webserver/php/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

5. 編譯並安裝

make && make install

6. 配置PHP

配置的過程主要是把PHP的相關文件拷貝到相應的安裝目錄,包括配置文件php.ini,php-pfm啟動腳本。具體路徑請參考實際情況。

cp /usr/local/webserver/php/etc/php-fpm.conf.default /usr/local/webserver/php/etc/php-fpm.conf

cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

chmod +x /etc/init.d/php-fpm

7. 啟動php-fpm服務

service php-fpm start


分享到:


相關文章: