lnmp

(1)安装nginx

  1.下载地址: http://nginx.org/en/download.html ,选择下载相应版本,并解压到目录下

  2.安装依赖包 yum -y install pcre*  yum -y install openssl*

     如果安装出现在下面的错误是缺少编译环境。安装编译源码所需的工具和库 
       ./configure: error: C compiler cc is not found 
      #yum install gcc gcc-c++ ncurses-devel perl

  3. a、执行 ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-pcre

    b、编译 make

    c、安装 make install (如果是非root用户 make 和sudo make install 分开 同理,其他的安装包也是这样)

  4. 建立软链接:# ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/
  5. 配置nginx.conf 支持php
    进入/usr/local/nginx/conf目录,编辑nginx.conf
    
location / {
            root   /home/www;    #根目录,可指定目录
            index index.php index.html index.htm; #增加index.php 默认支持php
        }
#打开支持php location ~ .php$ { # root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; #将/scripts 改为 root 指定目录地址 #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME /home/www$fastcgi_script_name; include fastcgi_params; } ……
#在配置未见末尾加入 include vhost/*.conf; 建立虚拟主机配置目录
    建立虚拟主机配置目录,并将此目录导入到nginx.conf中

    # mkdir vhost

    # vim ./nginx.conf (在最后大括号前添加一行并保存退出: include vhost/*.conf; )

  6. 可在vhost目录内新建虚拟主机配置文件,以.conf结尾。

server {
    listen 80;#监听80端口,接收http请求
    server_name www.lblog.com;#域名
    root /home/www/blog;#准备存放代码工程的路径
    index index.php index.html index.htm;

    location / {
       try_files $uri $uri/ /index.php$is_args$args; #去除 index.php
    }

    location ~ .php$ {
        #fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        #fastcgi_split_path_info ^(.+.php)(/.+)$;
        #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        #include fastcgi_params;
        try_files $uri =404;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi.conf;#加载nginx的fastcgi模块
    }

}

  

 (2)安装php(源码编译安装)

  1.下载地址:http://php.net/downloads.php

  2.安装依赖包 :yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel

  3. 由于centOS没有libmcrypt,所以要先下载第三方源

wget http://www.atomicorp.com/installers/atomic
sh ./atomic
yum install php-mcrypt libmcrypt-devel

  4. 解压安装包并cd到安装包目录下,并做安装配置

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysqli --with-iconv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-zlib --enable-pdo --with-pdo-mysql --enable-opcache

       5.make && make install

  6. cd  /usr/local/php 进行相关配置  
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp php.ini-production /usr/local/php/etc/php.ini
     修改www.conf 下面的user = www ,group=www (需要先创建)
     接着运行/usr/local/php/sbin/php-fpm 就可以启动php了
原文地址:https://www.cnblogs.com/aajonas/p/6681404.html