PHP 安装
LNMP 下 php 在 Apache 服务下是 libphp5.so nginx 服务下是 9000 端口
#确保 web 服务和 MySQL 正常
143
[root@oldboy nginx-1.6.2]# netstat -lntup|egrep "nginx|mysql"
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
5577/nginx
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
5871/mysqld
#检查依赖库是否正常
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 安装完毕!!!!!!!!!