前言: LNMP的搭建后的原理如下:
1>nginx1.6.2(已安装好)
2.Mysql安装方法(5.5.32已安装好)
1>编译安装 5.1,5.5不同 mysql-5.5.32.tar.gz
2>二进制包,直接解压,初始化数据库即可,无需编译。mysql-5.5.32-linux2.6-x86_64.tar.gz
3>yum/rpm
3.php安装: 5.3.27
1>安装准备:确保数据库和web服务软件安装并正常使用
[root@lll /]# netstat -lntup|egrep "nginx|mysql"
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 1778/mysqld
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 2938/nginx: master
2>检查依赖包并安装然后检查
[root@lll /]#rpm -qa zlib libxml libjpeg freetype libpng gd curl libiconv zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel
[root@lll /]#yum install zlib libxml libjpeg freetype libpng gd curl libiconv zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel
[root@lll /]#rpm -qa zlib libxml libjpeg freetype libpng gd curl libiconv zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel
3>安装libiconv-1.14.tar.gz
[root@lll /]tar zxf libiconv-1.14.tar.gz
[root@lll /]cd libiconv-1.14
[root@lll /]./configure --prefix=/usr/local/libiconv
[root@lll /]make
[root@lll /]make install
4>安装libmcrypt-2.5.8.tar.gz(安全加密)
tar zxf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make
make install
sleep 2
/sbin/ldconfig
cd libltdl/
./configure --enable-ildl-install
make
make install
cd ../../
5>安装mhash-0.9.9.9.tar.gz(不可逆向的php加密方式扩展库)
tar -xf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure LD_LIBRARY_PATH=/usr/local/lib
make
make install
rm –f /usr/lib/libmcrypt.*
rm –f /usr/lib/libmhash*
ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
6>安装mcrypt-2.6.8.tar.gz(php重要的加密支持扩展)
tar xf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
/sbin/ldconfig
./configure
make
make install
7>开始安装php5.3.27
[root@lll usr]# tar zxf php-5.3.27.tar.gz
[root@lll php-5.3.27]# yum install libxslt* -y
./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-zlib-dir \
--with-libxml-dir=/usr \
--enable-xml \
--disable-rpath \
--enable-safe-mode \
--enable-bcmath \
--enable-shmop \
--enable-sysvshm \
--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
[root@lll php-5.3.27]# ln -s /application/mysql/lib/libmysqlclient.so.18 /usr/lib64/
[root@lll php-5.3.27]# make
[root@lll php-5.3.27]# make install
[root@lll php]# ln -s /application/php5.3.27/ /application/php
8.配置fpm参数并启动php-fpm服务(启服务从后往前启动,停服务从前往后停)
[root@lll etc]# cd /usr/php-5.3.27/
[root@lll php-5.3.27]# cp php.ini-production /application/php/lib/php.ini
1>将修改过的php-fpm.conf移动到/application/php/etc/下面
[root@lll etc]# mv /usr/19-lnmp-conf/application/php/etc/php-fpm.conf /application/php/etc/
[root@lll etc]# vimdiff php-fpm.conf php-fpm.conf.default ----对比文件
[root@lll php]# /application/php/sbin/php-fpm -t -----检查语法
[root@lll php]# /application/php/sbin/php-fpm ------启动php进程
[root@lll php]# netstat -lntup|grep php-fpm ------查看进程(9000端口)
[root@lll php]# cat >>/etc/rc.local<<EOF ------把mysql,php,nginx增加到/etc/rc.local中开机自启动
/etc/init.d/mysqld start
/application/php/sbin/php-fpm
/application/nginx/sbin/nginx
EOF
9.整个LNMP启动及测试程序
五、Nginx整合PHP(nginx.conf.default中默认的php处理配置就是一个坑,通不过,需重新配置php处理配置)
1>修改nginx.conf文件
(1)查看nginx.conf文件内容
vi nginx.conf
worker_processes 2;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 192.168.93.148:80;
server_name www.abc.org;
root html/www;
index index.html index.htm;
}
}
2>修改nginx.conf文件内容
从nginx.conf.default文件中将涉及php的部分拷贝过来,同时修改php处理时的根路径:
将root html改为root html/www。
vi nginx.conf
worker_processes 2;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 192.168.93.148:80;
server_name www.abc.org;
root html/www;
index index.html index.htm;
#location~ \.php$ {
# root html/www;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
}
}
3>去掉添加内容中的“#”号
a、查看nginx.conf文件的行数
cat -n nginx.conf
b、查看nginx.conf中含“#”号的内容
sed -n '15,21p' nginx.conf
c、过滤nginx.conf中的“#”号
sed -e '15,21s/#//g' nginx.conf
d、确认无误后,将修改内容写入nginx.conf文件中
sed -i '15,21s/#//g' nginx.conf
4>查看修改后的nginx.conf文件内容
cat nginx.conf
worker_processes 2;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 192.168.93.148:80;
server_name www.abc.org;
root html/www;
index index.html index.htm;
location ~ \.php$ {
root html/www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
}
}
5>检查Nginx语法
/application/nginx/sbin/nginx -t
6>平滑重启Nginx
/application/nginx/sbin/nginx -s reload
7>访问http://www.etiantian.org/phpinfo.php,报错:File not found
8>重新修改nginx.conf文件中关于PHP的处理配置
vi nginx.conf
worker_processes 2;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 192.168.93.148:80;
server_name www.abc.org;
root html/www;
index index.html index.htm;
location ~ .*\.(php|php5)?$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
}
9>访问http://www.etiantian.org/phpinfo.php成功