LNMP之PHP安装
1.检查安装PHP所需的lib库
安装必要的函数库:如:lib、zlib
rpm -qa zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel
rpm -qa freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel
安装相关的lib软件包:
yum install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel -y
yum install freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel -y
下载安装libiconv库
[root@instance-yf0xzby9 tools]# wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
[root@instance-yf0xzby9 tools]# tar zxf libiconv-1.14.tar.gz
[root@instance-yf0xzby9 tools]# cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
make
make install
cd ../
安装libmcrypt库
CentOS默认的yum中没有libmcrypt-devel,实现配置epel第三方yum源
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
yum -y install libmcrypt-devel
安装mhash加密扩展库
yum -y install mhash
安装mcrypt加密扩展库
yum -y install mcrypt
2.开始安装PHP服务(FastCGI方式)
01.获取PHP包
wget http://cn.php.net/get/php-5.3.27.tar.gz/form/cn2.php.net/mirror
wget http://cn.php.net/get/php-5.3.27.tar.gz/form/this/mirror
wget http://cn2.php.net/distributions/php-5.3.27.tar.gz
02.解压配置PHP
tar zxf php-5.3.27.tar.gz
cd php-5.3.27
./configure \
--prefix=/application/php.3.27 \
--with-mysql=/application/mysql \
--with-iconv-dir=/usr/local/libconv \
--with-freetype-fir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--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-xsl \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-ftp
ln -s /application/mysql/lib/libmysqlclient.so.18 /usr/lib64/
touch ext/phar/phar.phar
make
make install
03.配置PHP引擎配置文件php.ini
001.设置软链接方便访问
ln -s /application/php.3.27(此处为版本号) /application/php
ls -l /application/php
002.查看PHP默认模板文件
ls php.ini*(在安装包路径下)
003.拷贝PHP配置文件到PHP默认目录下,并更改文件名称php.ini
cp php.ini-production /application/php/lib/php.ini
ls -l /application/php/lib/php.ini
3.配置PHP服务的配置文件php-fpm.conf
cd /application/php/etc
ls
cp php-fpm.conf.default php-fpm.conf
4.启动PHP服务(FastCGI方式)
01.启动PHP服务php-fpm
/application/php/sbin/php-fpm
02.检查PHP服务php-fpm的进程及启动端口情况
ps -ef|grep php-fpm
lsof -i :9000
5.配置Nginx支持PHP程序请求访问
01.修改Nginx配置文件
001.查看当前Nginx配置文件
cd /application/nginx/conf/
cp nginx.conf nginx.conf.02
cat nginx.conf
002.PHP解析,以blog为例
cat extra/blog.conf
[root@instance-yf0xzby9 extra]# cat blog.conf
server {
listen 80;
server_name blog.etiantian.org;
location / {
root html/blog;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ .*\.(php|php)?$ {
root html/blog;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
003.检查启动Nginx
/application/nginx/sbin/nginx -t
/application/nginx/sbin/nginx -s reload
6.测试LNMP环境生效情况
01.测试PHP解析请求是否ok
cd ../html/blog
echo "<?php phpinfo(); ?>" >test_info.php
cat test_info.php
02.调整Windows下的hosts解析(当前机器的IP)
172.16.0.4 www.etiantian.org bbs.etiantian.org blog.etiantian.org
03.打开浏览器,http://blog.etiantian.org/test_info.php
04.测试PHP连接MySQL情况
[root@instance-yf0xzby9 blog]# cat test_info.php
<?php
//$link_id=mysql_connect('hostname','username','passwords');
$link_id=mysql_connect('localhost','root','hty123') or mysql_error();
//$link_id=mysql_connect('localhost','test','');
if('$link_id') {
echo "mysql successful by hty!";
} else{
echo mysql_error();
}
// phpinfo();
?>
再次打开浏览器,http://blog.etiantian.org/test_info.php