Ubuntu 16.04 服务器配置

6 篇文章 0 订阅

Ubuntu16.04 换源

  1. cd /etc/apt
    
  2. #deb包
    deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse 
    ##测试版源 
    deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse 
    # 源码 
    deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse 
    ##测试版源 
    deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
    # Canonical 合作伙伴和附加 
    deb http://archive.canonical.com/ubuntu/ xenial partner 
    deb http://extras.ubuntu.com/ubuntu/ xenial main
    
  3. 使用 sudo vim sources.list 打开文件,输入 ggdG 删除所有内容(这句指令可以理解为从第1行到最后1行之间的内容都删了)使用 sudo apt-get update 即可更新获取 阿里云软件源 提供的软件列表;

安装软件:

sudo apt-get update

sudo apt-get install nginx mysql-server php 

sudo apt-get install php7.0-fpm

sudo apt-get install redis-server

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

配置

  1. 配置 php

    sudo vim /etc/php/7.0/fpm/php.ini       
    

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

  2. 配置 fpm

    sudo vim /etc/php/7.0/fpm/pool.d/www.conf
    

    找到 listen = /run/php/php7.0-fpm.sock 修改为 listen = /var/run/php/php7.0-fpm.sock 。当然,你也可以不修改,但必须前后一致,后面会用到这个配置。

  3. 配置 nginx

    sudo vim /etc/nginx/sites-available/default
    

    主要是配置 server 这一部分,最终配置如下:

    server {
            listen 80;
    
            root /var/www/your-project-name/public;
            index index.php index.html index.htm;
    
            # Make site accessible from http://localhost/
            server_name www.xxx.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$ {
                    try_files $uri /index.php =404;
                    fastcgi_split_path_info ^(.+\.php)(/.+)$;
                    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
                    fastcgi_index index.php;
                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    include fastcgi_params;
            }
    }
    

    解释:

    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.0-fpm.sock; 的目录要和 fpm 的配置文件中的 listen 一致。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值