PHP 安裝php
LNMP 下 php 在 Apache 服務下是 libphp5.so nginx 服務下是 9000 端口html
#確保 web 服務和 MySQL 正常mysql
143nginx
[root@oldboy nginx-1.6.2]# netstat -lntup|egrep "nginx|mysql"web
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTENsql
5577/nginx數據庫
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTENvim
5871/mysqldapi
#檢查依賴庫是否正常瀏覽器
yum install zlib libxml libjpeg freetype gd curl libiconv zlib-devel libxml2-devel
libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel libmcrypt-devel
libxslt* bzip2* -y
#安裝 libiconv-1.14 庫
tar zxvf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
echo $?
make echo $? make install echo $?
#安裝 libmcrypt-2.5.8.tar.gz 庫 tar zxvf libmcrypt-2.5.8.tar.gz cd libmcrypt-2.5.8
./configure
make
make install
#安裝 mhash-0.9.9.9
tar zxvf mhash-0.9.9.9.tar.gz cd mhash-0.9.9.9
./configure
144
make
make install
#安裝 mcrypt
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
/sbin/ldconfig
./configure LD_LIBRARY_PATH=/usr/local/lib
make
make install
#安裝 PHP5.3.2.7
[root@oldboy php-5.3.27]# yum install libxslt* -y
tar zxvf php-5.3.27.tar.gz
cd php-5.3.27
./configure \
--prefix=/application/php5.3.27 \
--with-mysql=/application/mysql \
--with-iconv-dir=/usr/local/libiconv \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-libxml-dir=/usr \
--enable-xml \
--disable-rpath \
--enable-safe-mode \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--with-curlwrappers \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--with-mcrypt \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--enable-short-tags \
--enable-zend-multibyte \
--enable-static \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-ftp
#make 出錯
/home/tools/php-5.3.27/sapi/cli/php: error while loading shared libraries:
libmysqlclient.so.18: cannot open shared object file: No such file or directory
make: *** [ext/phar/phar.php] 錯誤 127
#解決方法
ln -s /application/mysql/lib/libmysqlclient.so.18 /usr/lib64/
make
make install
ln -s /application/php5.3.27/ /application/php
#配置 PHP
[root@oldboy php-5.3.27]# cp php.ini-production /application/php/lib/php.ini
[root@oldboy php-5.3.27]# cd /application/php/etc/
#修改 php-fpm.conf,配置參數看 F 盤的附件
[root@oldboy ~]# vim /application/php/etc/php-fpm.conf
/application/php/sbin/php-fpm –t #檢查參數
#添加啓動項
[root@oldboy ~]# vi /etc/rc.local
/etc/init.d/mysqld start
/application/php/sbin/php-fpm
/application/nginx/sbin/nginx
#PHP 鏈接 nginx,首先在 nginx 的 html 目錄下建立 index.php 首頁 [root@oldboy html]# vim /application/nginx/html/index.php
<?php phpinfo();?>
#編輯 nginx 的 nginx.conf 配置文件
[root@oldboy html]# vim /application/nginx/conf/nginx.conf location ~ .*\.(php|php5)?$ {
fastcgi_pass 127.0.0.1:9000;
147
fastcgi_index index.php; #index.php 爲在 html 目錄下建立的
include fastcgi.conf; }
#檢查語法而且重啓 nginx
[root@oldboy html]# /application/nginx/sbin/nginx –t
[root@oldboy html]# /application/nginx/sbin/nginx -s reload
#最後在瀏覽器中輸入 IP/index.php 測試,若出現 PHP 頁面證實已成功!
#PHP 鏈接 MySQL 數據庫,一樣在/application/nginx/的 html 目錄下建立 mysql.php
[root@oldboy html]# vim mysql.php
<?php $link_id=mysql_connect('localhost','root','oldboy123') or mysql_err();
if ($link_id)
{ echo "mysql successful by oldboy! \n"; }
else { echo "mysql_error()"; } ?>
#最後在瀏覽器中輸入 IP/mysql.php 測試,若出現 successful!頁面證實已成功!
#或者使用如下 PHP 它自己的引擎這種方法測試
[root@oldboy html]# /application/php/bin/php mysql.php mysql successful by oldboy!
#到此 LNMP 安裝完畢!!!!!!!!!