码迷,mamicode.com
首页 > 其他好文 > 详细

LNMP第一部分环境搭建

时间:2015-06-20 14:28:57      阅读:238      评论:0      收藏:0      [点我收藏+]

标签:local   用户   lnmp   nginx   

                          

                     LNMP第一部分环境搭建


一、MySQL安装(同LAMP里面的安装方法)

        参考网址:http://sxct168.blog.51cto.com/824373/1661366

二、php安装

1进入/usr/local/src/目录下

[root@mysql ~]# cd /usr/local/src/

 

2、下载php

wget  http://cn2.php.net/distributions/php-5.4.37.tar.bz2

 

3、解压

tar jxf php-5.4.37.tar.bz2

 

4创建一个php-fpm用户,并且禁止登陆

      useradd -s /sbin/nologin php-fpm

 

5、配置php参数

cd php-5.4.37

./configure --prefix=/usr/local/php   --with-config-file-path=/usr/local/php/etc  --enable-fpm   --with-fpm-user=php-fpm  --with-fpm-group=php-fpm   --with-mysql=/usr/local/mysql  --with-mysql-sock=/tmp/mysql.sock  --with-libxml-dir  --with-gd   --with-jpeg-dir   --with-png-dir   --with-freetype-dir  --with-iconv-dir   --with-zlib-dir   --with-mcrypt   --enable-soap   --enable-gd-native-ttf   --enable-ftp  --enable-mbstring  --enable-exif    --disable-ipv6     --with-curl

 

--prefix=:后面跟的是安装路径

--with-config-file-path=:后面跟配置文件的路径

1)这一步如果报错,需要安装gcc

   安装:[root@mysql php-5.4.37]# yum install gcc


2)配置php时遇到的错误,需要用到yum扩展源来搜索所需要的包,但是需要安装yum扩展源

   安装yum扩展源:yum install -y epel-release

配置php时遇到的错误:

1error: xml2-config not found. Please check your libxml2 installation.

      #  yum install -y libxml2-devel


2error: Please reinstall the libcurl distribution -

    easy.h should be in <curl-dir>/include/curl/

     # yum -y install curl-devel


3error: jpeglib.h not found.

    #  yum install -y libjpeg-devel


4error: png.h not found.

  # yum install -y libpng libpng-devel


5)  error: freetype-config not found.

  #  yum install -y freetype-devel


6) error: mcrypt.h not found. Please reinstall libmcrypt.

   # yum install -y libmcrypt-devel

解决了以上6个错误之后,在进行./configure配置时,没有出现错误,出现Thank you for using PHP

出现这个就说明配置成功了,如下图所示:

技术分享

最后还是要使用echo $?来检测一下是否OK

[root@mysql php-5.4.37]# echo $?

0  #这里提示数字0的话,就说明刚才的配置没有问题

 

7)使用ls查看/usr/local/php/目录下,已经出现了安装目录

      [root@mysql php-5.4.37]# ls /usr/local/php/

技术分享

6、编译php

     make

7、安装php

     make install

8、修改配置文件

     1)在当前目录下(/usr/local/src/php-5.4.37目录下)拷贝php.ini-production配置文件到/usr/local/php/etc/目录下,并且改名为php.ini

         cp php.ini-production /usr/local/php/etc/php.ini

 

  2) /usr/local/src/php-5.4.37目录下有两个配置文件

        php.ini-development:这个是配置文件是在开发环境是使用的

        php.ini-production:这个是实际生产环境中使用的

 

    3拷贝启动脚本/etc/init.d/目下,并且命名为php-fpm

        cp /usr/local/src/php-5.4.37/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

[root@mysql php-5.4.37]# cp /usr/local/src/php-5.4.37/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

 

   4移动配置文件,并且重命名

        mv /usr/local/php/etc/php-fpm.conf.default  /usr/local/php/etc/php-fpm.conf

 

  5给php-fpm目录赋予可执行权限

        chmod 755 /etc/init.d/php-fpm

 

   6加入到启动列表

      chkconfig --add php-fpm

 

  7设置默认启动

       chkconfig php-fpm on

 

 8启动php

       service php-fpm start

 

 三、安装nginx

1、进入/usr/local/src/目录

      cd /usr/local/src/


2、下载nginx

     wget http://nginx.org/download/nginx-1.6.2.tar.gz


3、解压

    tar zxvf nginx-1.6.2.tar.gz


4、配置nginx文件

   cd nginx-1.6.2

./configure   --prefix=/usr/local/nginx   --with-pcre

这个错误"./configure: error: the HTTP rewrite module requires the PCRE library."提示是没有安装PCRE库

安装PCRE库:

[root@mysql nginx-1.6.2]# yum install -y pcre-devel

 

5编译

      make


6、安装

     make install

 

7、安装完成之后,使用ls查看/usr/local/nginx/目录,目录下会生成4个目录文件

    

  [root@mysql
nginx-1.6.2]# ls /usr/local/nginx/
       conf 
html  logs  sbin     #生成的目录文件

8启动nginx: 

    /usr/local/nginx/sbin/nginx

[root@mysql
nginx-1.6.2]# ps aux |grep nginx
root      7271 
0.0  0.0  19836  
604 ?        Ss   08:38  
0:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody    7272 
0.0  0.1  20260 
1196 ?        S    08:38  
0:00 nginx: worker process     
root      7276 
0.0  0.0 103248   872 pts/0   
S+   08:38   0:00 grep nginx

1)启动失败,如果端口占用,需要把进程杀死

        killall [进程名称]

 

2)然后在重启nginx

/usr/local/nginx/sbin/nginx -s reload

 

四、编写nginx启动脚本

1、在/etc/init.d/目录下创建一个nginx文件,加入以下内容

vim /etc/init.d/nginx 

加入如下内容

#!/bin/bash
# chkconfig: - 30
21  #定义了启动在那个级别中,30是启动顺序,21是关闭顺序
# description: http
service.
# Source Function
Library
.
/etc/init.d/functions
# Nginx Settings
 
NGINX_SBIN="/usr/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/logs/nginx.pid"
RETVAL=0
prog="Nginx"
 
start() {
        echo -n $"Starting $prog: "
        mkdir -p /dev/shm/nginx_temp
        daemon $NGINX_SBIN -c $NGINX_CONF
        RETVAL=$?
        echo
        return $RETVAL
}
 
stop() {
        echo -n $"Stopping $prog: "
        killproc -p $NGINX_PID $NGINX_SBIN
-TERM
        rm -rf /dev/shm/nginx_temp
        RETVAL=$?
        echo
        return $RETVAL
}
 
reload(){
        echo -n $"Reloading $prog: "
        killproc -p $NGINX_PID $NGINX_SBIN -HUP
        RETVAL=$?
        echo
        return $RETVAL
}
 
restart(){
        stop
        start
}
 
configtest(){
    $NGINX_SBIN -c $NGINX_CONF -t
    return 0
}
 
case "$1"
in
  start)
        start
        ;;
  stop)
        stop
        ;;
  reload)
        reload
        ;;
  restart)
        restart
        ;;
  configtest)
        configtest
        ;;
  *)
        echo $"Usage: $0
{start|stop|reload|restart|configtest}"
        RETVAL=1
esac
exit $RETVAL

2保存后,执行

     1chmod a+x /etc/init.d/nginx

           或者

           chmod 755 /etc/init.d/nginx

    2chkconfig --add nginx #加入到启动列表

    3chkconfig nginx on #设定为开机启动

 

3chkconfig --list nginx

      查看在哪些级别是关闭和开启的

 

4、启动nginx命令

     service nginx start

 

 1) 如果启动失败,提示有进程占用了80端口,查询是那个进程占用了80端口

    netstat -lnp |grep 80

 

2) 杀死占用的80端口的进程,然后在启动,当然如果你使用上面的步骤已经把nginx启动了,那么你现在使用service nginx start启动nginx也会失败的,也会提示你80端口被占用,所以你需要service nginx stop先停止nginx,然后在启动就OK

 

killall 进程名称

 

五、配置解析php

1nginx的配置文件位置

     /usr/local/nginx/conf/nginx.conf

 vim  /usr/local/nginx/conf/nginx.conf   //把下面的配置,前面的#删除,并更改fastcgi_param SCRIPT_FILENAME 那一行

具体如图:

技术分享

技术分享

需要修改的文件:

        location ~ \.php$ {

            root           html;

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;

            include        fastcgi_params;

        }

 

 

2、配置完成后检查配置文件有没有错误

    /usr/local/nginx/sbin/nginx -t

   

[root@mysql ~]#
/usr/local/nginx/sbin/nginx -t
nginx: the
configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration
file /usr/local/nginx/conf/nginx.conf test is successful

有这个提示就说明配置是正确的

 

3重新加载

/usr/local/nginx/sbin/nginx-s reload

或者一下都可以

 [root@mysql ~]# /etc/init.d/nginx reload     

 

4、测试

1)在nginx目录下编写一个php脚本测试

vim  /usr/local/nginx/html/1.php

增加 

<?php
    phpinfo();
?>

 

2)在Linux系统测试

      curl localhost/1.php

      或者127.0.0.1/1.php -I都是一样的

[root@mysql ~]# curl
localhost/1.php -I
HTTP/1.1 200 OK  #出现200k就证件节气解析成功
Server: nginx/1.6.2
Date: Sat, 20 Jun
2015 03:06:20 GMT
Content-Type:
text/html
Connection:
keep-alive
X-Powered-By:
PHP/5.4.37

 

3)在浏览器测试,如下图

技术分享

技术分享


    笔记有错误的地方还请大神指正,小白会继续修改 

本文出自 “IT交流学习” 博客,请务必保留此出处http://sxct168.blog.51cto.com/824373/1663798

LNMP第一部分环境搭建

标签:local   用户   lnmp   nginx   

原文地址:http://sxct168.blog.51cto.com/824373/1663798

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!