CentOS7 搭建LNMP

一、        安装依赖文件

  1、  sudo yum install gcc gcc-c++ zlib zlib-devel libxml2 libxml2-devel openssl openssl-devel –y

二、        下载并安装软件

  1、  下载软件

    a、mkdir soft && cd soft

    b、   wget https://ftp.pcre.org/pub/pcre/pcre-8.38.tar.gz

    c、 wget http://120.198.248.29/cache/nginx.org/download/nginx-1.8.1.tar.gz?ich_args2=152-20234809035231_19dcecf02723c4110c668715844f4eb6_10001002_9c886d29d5caf4d2953c518939a83798_4a66cb383b8e0070ac4a841bcf222958

    d、   wget http://am1.php.net/distributions/php-7.0.19.tar.gz

    e、   wget http://download.lighttpd.net/spawn-fcgi/releases-1.6.x/spawn-fcgi-1.6.3.tar.gz

  2、  安装软件

    a、安装pcre:

      1)    tar xvf pcre-8.38.tar.gz

      2)    cd pcre-8.38

      3)    sudo ./configure

      4)    sudo make

      5)    sudo make install

    b、   安装nginx

      1)    tar xvf nginx-1.8.1.tar.gz

      2)    cd nginx-1.8.1

      3)    sudo ./configure –prefix=/usr/local/nginx

      4)    sudo make

      5)    sudo make install

    c、 安装php

      1)    tar xvf php-7.0.19.tar.gz

      2)    cd php-7.0.19

      3)    sudo ./configure  --prefix=/usr/local/php

      4)    sudo make

      5)    sudo make install

    d、   安装maraidb

      1)    sudo yum groupinstall maraidb mariadb-server –y

      2)    sudo systemctl start mariadb

      3)    sudo systemctl enable mariadb

      4)    sudo mysql_secure_installation      //此处设置好密码好,按4个y确认即可

    e、   安装spawn-fcgi

      1)    tar xvf spawn-fcgi-1.6.3.tar.gz

      2)    cd spawn-fcgi-1.6.3

      3)    sudo ./configure –prefix=/usr/local/spawn-fcgi

      4)    sudo make

      5)    sudo make install

三、        配置相关文件

  1、  Nginx虚拟主机设置

    a、cd /usr/local/nginx/conf

    b、   sudo mkdir vhost/ && cd vhost/

    c、 sudo vim www.test.com.conf,添加的内容如下:

      server{

              listen          10.0.0.20:80;

              server_name     www.test.com;

              root    /data/www.test.com;

 

              access_log      /data/logs/www.test.com.log main;

              error_log       /data/logs/www.test.com.error.log;

              location ~ \.php$

                {

                      fastcgi_pass    127.0.0.1:9000;

                      fastcgi_index   index.php;

                      fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;

                      include fastcgi_params;

                }

 

            location / {

                    index   index.php index.html index.htm;

             }

      }  

  2、  修改/usr/local/nginx/conf/nginx.conf,内容如下:

    a、将以下内容的注释去掉:

      log_format  main  '$remote_addr - $remote_user [$time_local] "$request"

                     '$status $body_bytes_sent "$http_referer" '

                          '"$http_user_agent" "$http_x_forwarded_for"';

    b、   在文件的最后面加上如下内容:、

      include vhost/*.conf;

  3、  创建文件

    a、sudo –p /data/logs

    b、   sudo touch /data/logs/www.test.com.log

    c、 sudo touch /data/logs/www.test.com.error.log

    d、   sudo mkdir –p /data/www.test.com

  4、  修改spawn-fcgi的配置

    a、cd /usr/local/spawn-fcgi/bin

    b、   sudo ./spawn-fcgi –a 127.0.0.1 –p 9000 –f /usr/local/php/bin/php-cgi

    c、 查看配置结果:sudo ss –tulpn | grep  9000

  5、  编辑测试文件 sudo vim /data/www.test.com/index.php,内容如下:

    <?php

            phpinfo();

    ?>

四、 添加开机启动项

  1、  设置启动文件可执行:sudo chmod +x /etc/rc.local

  2、  往/usr/rc.local 里添加如下内容:

    /usr/local/nginx/sbin/nginx –t

    /usr/local/nginx/sbin/nginx

    /usr/local/spawn-fcgi/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -f /usr/local/php/bin/php-cgi

  3、  重启电脑:sudo reboot

五、 测试结果

  1、  在windows的hosts里添加内容: 10.0.0.20 www.test.com

  2、  在浏览器打开:http://10.0.0.20 或者 http://www.test.com

posted @ 2017-05-21 14:49  jefflee168  阅读(346)  评论(0编辑  收藏  举报