Skip to content

初始化EduSoho

克隆代码

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

初始化程序

创建数据库:

bash
mysql -uroot -e 'CREATE DATABASE `edusoho` DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_unicode_ci'

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

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

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

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

创建数据库表结构:

bash
bin/phpmig migrate

初始化系统配置:

bash
app/console system:init

创建软连接:

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

配置域名

添加域名解析:

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

添加Nginx配置:

配置文件目录:/etc/nginx/sites-enabled
配置文件目录:/opt/homebrew/etc/nginx/servers
配置文件目录:/usr/local/etc/nginx/servers

在配置文件目录下,新增edusoho.conf配置文件,内容如下:

nginx
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:9000;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
        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:

bash
sudo service nginx restart
bash
sudo brew services restart nginx

前端实时编译

安装依赖包:

bash
cd /var/www/edusoho
# 中国大陆地区可配置 NPM 镜像,加速软件包的安装 
# npm config set registry https://registry.npmmirror.com
npm i

启动实时编译服务:

bash
npm run dev

验证配置

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

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