lnmp 环境搭建

# 安装php7.1
sudo apt-get update  
sudo apt-get install -y language-pack-en-base  
locale-gen en_US.UTF-8

sudo apt-get install software-properties-common  
sudo LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php  
sudo apt-get update

sudo apt-get -y install php7.1  
sudo apt-get -y install php7.1-mysql  
sudo apt-get install php7.1-fpm

apt-get install php7.1-curl php7.1-xml php7.1-mcrypt php7.1-json php7.1-gd php7.1-mbstring

# 安装mysql5.7
wget http://dev.mysql.com/get/mysql-apt-config_0.5.3-1_all.deb  
sudo dpkg -i mysql-apt-config_0.5.3-1_all.deb  
sudo apt-get update  
sudo apt-get install mysql-server

# 安装nginx
sudo apt-get -y install nginx  

配置

  1. 配置php:
sudo vim /etc/php/7.1/fpm/php.ini  

输入/fix_pathinfo搜索,将cgi.fix_pathinfo=1改为cgi.fix_pathinfo=0:

  1. 编辑fpm的配置文件: 运行:
    sudo vim /etc/php/7.1/fpm/pool.d/www.conf  

    找到listen = /run/php/php7.1-fpm.sock修改为listen = 127.0.0.1:9000。使用9000端口。

service php7.1-fpm restart

  1. 配置Nginx:

    sudo vim /etc/nginx/sites-available/default  
    server {  
        #listen 80 default_server;
        listen 80;
        #listen [::]:80 default_server ipv6only=on;
    
        root /var/www/your-project-name/public;
        index index.php index.html index.htm;
    
        # Make site accessible from http://localhost/
        server_name lufficc.com www.lufficc.com;
    
        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ /index.php?$query_string;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
        }
    
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
        #
        #       # With php7.0-cgi alone:
                fastcgi_pass 127.0.0.1:9000;
        #       # With php7.0-fpm:
        #       fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }
    }

    root:是你的项目的public目录,也就是网站的入口

index:添加了,index.php,告诉Nginx先解析index.php文件

server_name:你的域名,没有的话填写localhost

location / try_files修改为了try_files $uri $uri/ /index.php?$query_string;

location ~ .php$部分告诉Nginx怎么解析Php,原封不动复制即可,但注意:fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;的目录要和fpm的配置文件中的listen一致。

本作品采用《CC 协议》,转载必须注明作者和本文链接
毛仔
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 1

大神,你的文章对我启发很大,感谢,希望您多出一些精品文章,给我们学习!

5年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!