PearProject 在 WSL 下的開發環境部署教程

cnguu發表於2019-08-22

簡介

專案管理系統:PearProject

部署環境

  • WSL(Ubuntu18.04)
  • Nginx1.16.0
  • PHP7.2
  • MySQL5.7.26
  • Redis5.0.3

專案依賴

  • PDO PHP Extension
  • PHP Igbinary
  • PHP Redis

部署過程

後端

$ cd /www/wwwroot
$ sudo git clone https://github.com/a54552239/pearProjectApi.git
$ cd pearProjectApi
$ sudo composer install
$ sudo chown www:www -R ../pearProjectApi
$ mkdir runtime
$ sudo chmod 777 -R ../pearProjectApi

前端

$ sudo chown -R $USER:$(id -gn $USER) /home/cnguu/.config
$ cd /www/wwwroot
$ sudo git clone https://github.com/a54552239/pearProject.git
$ cd pearProject
$ sudo npm install
$ sudo chown www:www -R ../pearProject

修改 vue.config.js

const DEV_URL = 'http://p1.test';
module.exports = {
    devServer: {
        disableHostCheck: true,
    }
}

Nginx 配置

先配置 Windows 下的 hosts

PearProject 在 WSL 下的部署教程

同理配置 WSL 下的 hosts

// $ sudo vim /etc/hosts
127.0.0.1 p1.test
127.0.0.1 p2.test

再配置 Nginx

server
{
    listen 80;
    server_name p1.test;
    index index.php;
    root /www/wwwroot/pearProjectApi;

    include enable-php-72.conf;

    location / {
        try_files $uri $uri/ /index.php$uri;
        if ( -f $request_filename) {
            break;
        }
        if ( !-e $request_filename) {
            rewrite ^(.*)$ /index.php/$1 last;
            break;
        }
    }

    #禁止訪問的檔案或目錄
    location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
    {
        return 404;
    }

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        expires      30d;
        error_log off;
        access_log /dev/null;
    }

    location ~ .*\.(js|css)?$
    {
        expires      12h;
        error_log off;
        access_log /dev/null; 
    }
    access_log  /dev/null;
    error_log  /www/wwwlogs/p1.test.error.log;
}

server
{
    listen 80;
    server_name p2.test;

    location /
    {
        proxy_pass http://127.0.0.1:8045;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header REMOTE-HOST $remote_addr;
    }
}

愛護牙齒

相關文章