初始化EduSoho

克隆代码

mkdir /var/www
cd /var/www
git clone https://github.com/edusoho/edusoho.git

初始化程序

创建数据库:

mysql -uroot -e 'CREATE DATABASE `edusoho` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci'

创建程序配置文件,并修改数据库相关配置:

cd /var/www/edusoho
cp app/config/parameters.yml.dist app/config/parameters.yml

创建上传、缓存、日志目录:

mkdir -p app/cache app/logs app/data web/files
chmod 777 app/cache app/logs app/data web/files

创建数据库表结构:

bin/phpmig migrate

初始化系统配置:

app/console system:init

创建软连接:

php app/console assets:install web --symlink --relative

配置域名

添加域名解析:

sudo bash -c 'echo "127.0.0.1 edusoho.local" >> /etc/hosts'

添加Nginx配置:

Ubuntu 用户在/etc/nginx/sites-enabled目录下,macOS 用户在/usr/local/etc/nginx/sites-enabled目录下,新增esdev.conf配置文件,内容如下:

server {
    set $root_dir /var/www/edusoho;
    set $webpack_server http://127.0.0.1:3030;

    server_name edusoho.local;
    root $root_dir/web;

    error_log /var/log/nginx/edusoho_error.log;
    access_log /var/log/nginx/edusoho_access.log;

    location / {
        index app_dev.php;
        try_files $uri @rewriteapp;
    }

    location @rewriteapp {
        rewrite ^(.*)$ /app_dev.php/$1 last;
    }

    location ~ ^/(app_dev)\.php(/|$) {
        # fastcgi_pass unix:/run/php/php7.1-fpm.sock;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
        fastcgi_param HTTP_X-Sendfile-Type X-Accel-Redirect;
        fastcgi_param HTTP_X-Accel-Mapping /udisk=$root_dir/app/data/udisk;
        fastcgi_buffer_size 128k;
        fastcgi_buffers 8 128k;
    }

    location ~ ^/udisk {
        internal;
        root $root_dir/app/data/; 
    }

    location ~ ^/static-dist {
        proxy_pass $webpack_server;
    }

    # 以下配置允许运行.php的程序,方便于其他第三方系统的集成。
    location ~ \.php$ {
    # [改] 请根据实际php-fpm运行的方式修改
        fastcgi_pass   127.0.0.1:9001;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
        fastcgi_param  HTTPS              off;
        fastcgi_param  HTTP_PROXY         "";
    }

    # 配置设置图片格式文件
    location ~* \.(jpg|jpeg|gif|png|ico|swf)$ {
        # 过期时间为3年
        expires 3y;

        # 关闭日志记录
        access_log off;

        # 关闭gzip压缩,减少CPU消耗,因为图片的压缩率不高。
        gzip off;
    }

    # 配置css/js文件
    location ~* \.(css|js)$ {
        access_log off;
        expires 3y;
    }

    # 禁止用户上传目录下所有.php文件的访问,提高安全性
    location ~ ^/files/.*\.(php|php5)$ {
        deny all;
    }
}

注意

此Nginx配置只能用于开发环境,正式生产环境配置,请参考:EduSoho部署

重启Nginx:

Ubuntu:

sudo service nginx restart

macOS:

sudo brew services restart nginx

前端实时编译

安装依赖包:

cd /var/www/edusoho
yarn

启动实时编译服务:

npm run dev

验证配置

在浏览器中打开 http://edusoho.local ,如出现EduSoho首页,表示配置成功。系统默认超管账号为:

用户名:测试管理员
密码:kaifazhe

results matching ""

    No results matching ""