美文网首页
搭建服务器

搭建服务器

作者: 李景磊 | 来源:发表于2017-05-26 15:19 被阅读0次

    服务器搭建手册

    服务器 版本: Ubuntu 16.04 64位
    PHP版本 php7.0
    MySQL版本 5.7
    nginx 版本 1.10
    

    Nginx 安装

    apt-get -y install nginx
    

    php 安装

    apt-get -y install php7.0
    

    MySQL安装

    apt-get -y install mysql-client-5.7
    

    安装composer管理工具

    apt-get -y install composer
    

    composer 切换国内镜像

    composer config -g repo.packagist composer https://packagist.phpcomposer.com
    
    

    安装 php-FPM工具

    apt-get -y install php7.0-fpm
    

    安装 php-MySQL 扩展

    apt-get -y install  php7.0-mysql 
    

    安装项目管理工具 Git

    apt-get -y install git
    

    安装laravel 依赖

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

    安装系统解压和压缩工具

    apt-get -y install zip unzip
    

    安装laravel 5.1 LTS版

    项目工作目录在/var/www下面

    cd /var/www
    
    composer create-project laravel/laravel your-project-name --prefer-dist "5.1.*"
    

    修改php-fpm

    sudo vim /etc/php/7.1/fpm/php.ini 
    
    • 将 默认注释的一行;cgi.fix_pathinfo=1下面添加一行cgi.fix_pathinfo=0
    HP's
    ; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok
    ; what PATH_INFO is.  For more information on PATH_INFO, see the cgi specs.  Setting
    ; this to 1 will cause PHP CGI to fix its paths to conform to the spec.  A setting
    ; of zero causes PHP to behave as before.  Default is 1.  You should fix your scripts
    ; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
    ; http://php.net/cgi.fix-pathinfo
    ;cgi.fix_pathinfo=1
    cgi.fix_pathinfo=0
    
    sudo vim /etc/php/7.0/fpm/pool.d/www.conf  
    
    • 找到listen = /run/php/php7.1-fpm.sock修改为listen = 127.0.0.1:9000。使用9000端口。

    • 修改完毕后service php7.0-fpm restart 重启php-fpm服务

    修改Nginx配置

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

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

    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一致。
    

    重启Nginx

    sudo service nginx restart
    

    相关文章

      网友评论

          本文标题:搭建服务器

          本文链接:https://www.haomeiwen.com/subject/sqlxfxtx.html