总结
豆包 AI 助手文章总结

5分钟搭建 nginx +php (LNMP)新手专用

php中文网
发布: 2016-06-23 13:45:22
原创
1164人浏览过

这里要先声明一下,针对nginx的php安装和针对apache的php安装是有区别的,因为nginx中的php是以fastcgi的方式结合nginx的,可以理解为nginx代理了php的fastcgi,而apache是把php作为自己的模块来调用的。

  • 先把php 和php-fpm编译安装吧 请看http://heilinux.blog.51cto.com/6123663/1575582

  • 修改配置文件

    1

    cd   php-5.6.2

    cp php.ini-production /usr/local/php/etc/php.inicp /usr/local/php/etc/php-fpm.conf.default.conf  php-fpm.conf
    登录后复制

    保存配置文件后,检验配置是否正确的方法为:

    /usr/local/php/sbin/php-fpm -t
    登录后复制

    如果出现诸如 “test is successful” 字样,说明配置没有问题。

    立即学习PHP免费学习笔记(深入)”;

    启动php-fpm

    cp /usr/local/src/php-5.3.27/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpmchmod 755 /etc/init.d/php-fpmservice php-fpm start
    登录后复制

    如果想让它开机启动,执行:

    chkconfig php-fpm on
    登录后复制

    检测是否启动:

    ps aux |grep php-fpm
    登录后复制
    netstat -ant |grep 9000
    登录后复制

    看看是不是有很多个进程(大概20多个)还有你的9000端口开启了么?。

    》》》》》》》》》》》》》》》》华华丽丽的分隔符《《《《《《《《《《《《《《《《《《《

    安装nginx

    开始安装nginx吧  

    1

    2

    wget 

    http: //nginx .org /download/nginx-1 .6.2. tar .gz  // 最新稳定版哦

     

    解压nginx

    tar zxvf nginx-1.6.2.tar.gz
    登录后复制

    配置编译参数

    cd nginx-1.6.2./configure \--prefix=/usr/local/nginx \--with-http_realip_module \--with-http_sub_module \--with-http_gzip_static_module \--with-http_stub_status_module  \--with-pcre
    登录后复制

    编译nginx

    make
    登录后复制

    安装nginx

    make install
    登录后复制

    因为nginx比较小,所以很快就会安装完,而且也不会出什么错误,如果出错了,yum安装pcre-devel(嘿嘿,我是这个问题了,至于你出别的问题问度娘吧。)

    》》》》》》》》》》》》》》》》》》华丽的分隔符《《《《《《《《《《《《《《《《《《《《《

    添加一个nginx主程序的符号链接  

    1

    2

      

    ln  -sf  /usr/local/nginx/sbin/nginx   /usr/sbin

    1

    nginx -t      测试一下吧,成功了吧,是不是很有成就感,别着急 咱们继续!

    更改nginx配置

    首先把原来的配置文件清空:

    > /usr/local/nginx/conf/nginx.conf
    登录后复制

    “>” 这个符号之前阿铭介绍过,为重定向的意思,单独用它,可以把一个文本文档快速清空。

    vim /usr/local/nginx/conf/nginx.conf
    登录后复制

    写入如下内容:

    user nobody nobody;worker_processes 2;error_log /usr/local/nginx/logs/nginx_error.log crit;pid /usr/local/nginx/logs/nginx.pid;worker_rlimit_nofile 51200;events{    use epoll;    worker_connections 6000;}http{    include mime.types;    default_type application/octet-stream;    server_names_hash_bucket_size 3526;    server_names_hash_max_size 4096;    log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'    '$host "$request_uri" $status'    '"$http_referer" "$http_user_agent"';    sendfile on;    tcp_nopush on;    keepalive_timeout 30;    client_header_timeout 3m;    client_body_timeout 3m;    send_timeout 3m;    connection_pool_size 256;    client_header_buffer_size 1k;    large_client_header_buffers 8 4k;    request_pool_size 4k;    output_buffers 4 32k;    postpone_output 1460;    client_max_body_size 10m;    client_body_buffer_size 256k;    client_body_temp_path /usr/local/nginx/client_body_temp;    proxy_temp_path /usr/local/nginx/proxy_temp;    fastcgi_temp_path /usr/local/nginx/fastcgi_temp;    fastcgi_intercept_errors on;    tcp_nodelay on;    gzip on;    gzip_min_length 1k;    gzip_buffers 4 8k;    gzip_comp_level 5;    gzip_http_version 1.1;    gzip_types text/plain application/x-javascript text/css text/htm application/xml;server{    listen 80;    server_name localhost;    index index.html index.htm index.php;    root /usr/local/nginx/html;    location ~ \.php$ {        include fastcgi_params;        fastcgi_pass 127.0.0.1:9000;        fastcgi_index index.php;        fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;    }}}
    登录后复制

    》》》》》》》》》》》》》》》》你相信么,你已经搞定了LNMP了《《《《《《《《《《《《《《

    测试是否解析php文件

    创建测试文件:

    vim /usr/local/nginx/html/2.php
    登录后复制

    内容如下:

    <?php    echo "测试php是否解析";?>
    登录后复制

    测试:

     curl localhost/2.php
    登录后复制

    看到什么了。。不要怀疑自己的眼睛,不要热泪盈眶。你已经成功了。

    欢迎大家访问我的个人网站 萌萌的IT人
    PHP速学教程(入门到精通)
    PHP速学教程(入门到精通)

    PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

    下载
    来源:php中文网
    本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
    最新问题
    豆包 AI 助手文章总结
    开源免费商场系统广告
    热门教程
    更多>
    最新下载
    更多>
    网站特效
    网站源码
    网站素材
    前端模板
    关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
    php中文网:公益在线php培训,帮助PHP学习者快速成长!
    关注服务号 技术交流群
    PHP中文网订阅号
    每天精选资源文章推送
    PHP中文网APP
    随时随地碎片化学习
    PHP中文网抖音号
    发现有趣的

    Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号