CentOS7部署EduSoho网校版开源系统

最近由于公司业务需求,需要一套类似于Mooc的网校系统,很早之前就部署过Edusoho这套网校系统,刚好可以拿来用。
所需环境

1、Centos7
2、Nginx
3、Mariadb
4、PHP7.2
5、EduSoho系统包 下载地址:EduSoho

注:nginx和mariadb好像没有版本要求,我用的是yum安装下来的那个版本,php7.1好像上传题库的时候会有影响,我换了7.2之后题库上传就正常了,但是一次上传的题库不能大于200题,这个bug我也不清楚在哪。

一、部署步骤如下

1、安装LNMP(LNMP=Linux Nginx Mysql PHP)

1
2
3
安装Nginx
touch /etc/yum.repos.d/nginx.repo
vi /etc/yum.repos.d/nginx.repo

1
2
3
4
5
6
7
8
9
然后把这段贴到刚建好的nginx.repo里面
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/OS/OSRELEASE/$basearch/
gpgcheck=0
enabled=1
其中OS就填centos(小写的),OSRELEASE就填7,因为我用的是centos7
然后保存,接着安装nginx
yum -y install nginx* --skip-broken
1
2
3
4
安装PHP
yum -y install epel-release
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum install php72w* --skip-broken

LNMP这里就不再做过多的描述了,可以查看我之前教如何部署LNMP的帖子

点击这里查看如何部署LNMP:Centos7 Build LNMP Server
二、配置Nginx
1
vi /etc/nginx/nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
worker_connections 1024;
}

http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 102400;
types_hash_max_size 2048;

include /etc/nginx/mime.types;
default_type application/octet-stream;

# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;

server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;

# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;

location / {
}

error_page 404 /404.html;
location = /404.html {
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}

# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2 default_server;
# listen [::]:443 ssl http2 default_server;
# server_name _;
# root /usr/share/nginx/html;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /404.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }

}
1
vi /etc/nginx/edusoho.conf

如果/etc/nginx/里面没有edusoho.conf的话,要自行创建一个
把配置文件贴到edusoho.conf里面,配置文件是官方给的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
server {
listen 80;
server_name 172.16.255.115;
   root /www/edusoho/web;
#access_log /var/log/nginx/edusoho.access.log;
#error_log /var/log/nginx/edusoho.error.log;

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

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

location ~ ^/udisk {
internal;
root /www/edusoho/app/data/;
}

location ~ ^/(app|app_dev)\.php(/|$) {
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 HTTPS off;
fastcgi_param HTTP_X-Sendfile-Type X-Accel-Redirect;
fastcgi_param HTTP_X-Accel-Mapping /udisk=/www/edusoho/app/data/udisk;
fastcgi_buffer_size 102400k;
fastcgi_buffers 8 102400k;
}

location ~* \.(jpg|jpeg|gif|png|ico|swf)$ {
expires 3y;
access_log off;
gzip off;
}

location ~* \.(css|js)$ {
access_log off;
expires 3000y;
}

location ~ ^/files/.*\.(php|php5)$ {
allow all;
}

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
include fastcgi_params;
}
}

nginx配文说明:
I.edusoho配文

1、/www/edusoho/web
这里是系统包所在的目录,官方是说为了安全,所以要把目录指到web里面
2、
fastcgi_buffer_size 102400k;
fastcgi_buffers 8 102400k;
这两个 我调到102400k,不知道是不是nginx等待时间太短还是什么原因,如果上传的题目太多的话(200以上),按F12你会发现里面有一条是500内部错误,到现在我都还没解决,但是我设置完之后最多一次可以传200题。

II.nginx.conf配文

1、
keepalive_timeout 102400;
types_hash_max_size 2048;
这两个我分别调到102400和2048,因为会出现上面说的内部500错误的问题。

三、数据库配置
1
2
3
4
5
6
7
8
9
10
11
yum install -y mariadb* --skip-broken
systemc restart mariadb
mysql_secure_installation
Enter current password for root (enter for none):<–初次运行直接回车
Set root password? [Y/n] <– 是否设置root用户密码,输入y并回车或直接回车
New password: <– 设置root用户的密码
Re-enter new password: <– 再输入一次你设置的密码
Remove anonymous users? [Y/n] <– 是否删除匿名用户,回车
Disallow root login remotely? [Y/n] <–是否禁止root远程登录,否,
Remove test database and access to it? [Y/n] <– 是否删除test数据库,回车
Reload privilege tables now? [Y/n] <– 是否重新加载权限表,回车

可以参考我的文章,如何部署LNMP

1
2
重启Nginx、PHP、Mariadb并设为自动启动
systemctl restart nginx php-fpm mariadb && systemctl enable nginx php-fpm mariadb

打开浏览器,输入nginx配置的server_name,然后按照提示一步一步安装即可

四、设置证书内容有姓名、公司、身份证号、课程、性别的关键字

先来一张证书效果图
avatar
做法如下:
1、编辑src/Biz/Certificate/Strategy/的BaseStrategy.php文件

1
vi /www/edusoho/src/Biz/Certificate/Strategy/的BaseStrategy.php

差不多从第70行开始,你会看到里面已经有name和username这两个关键字了,我们可以继续往下添加几个if来增加我们想要的关键字

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
if (strstr($recipientContent, '$sex$')) {
if ($user['gender'] == 'male'){
$recipientContent = str_replace('$sex$', '男', $recipientContent);}
if ($user['gender'] == 'female'){
$recipientContent = str_replace('$sex$', '女', $recipientContent);}
if ($user['gender'] == 'secret'){
$recipientContent = str_replace('$sex$', '保密', $recipientContent);}
}

if (strstr($recipientContent, '$cmp$')) {
$recipientContent = str_replace('$cmp$', $user['company'], $recipientContent);
}

if (strstr($recipientContent, '$idca$')) {
$recipientContent = str_replace('$idca$', $user['idcard'], $recipientContent);
}

全部代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
protected function getRecipientContent($userId, $recipientContent)
{
$user = $this->getUserService()->getUserAndProfile($userId);
if (strstr($recipientContent, '$name$')) {
$recipientContent = str_replace('$name$', $user['truename'], $recipientContent);
}

if (strstr($recipientContent, '$username$')) {
$recipientContent = str_replace('$username$', $user['nickname'], $recipientContent);
}

if (strstr($recipientContent, '$sex$')) {
if ($user['gender'] == 'male'){
$recipientContent = str_replace('$sex$', '男', $recipientContent);}
if ($user['gender'] == 'female'){
$recipientContent = str_replace('$sex$', '女', $recipientContent);}
if ($user['gender'] == 'secret'){
$recipientContent = str_replace('$sex$', '保密', $recipientContent);}
}

if (strstr($recipientContent, '$cmp$')) {
$recipientContent = str_replace('$cmp$', $user['company'], $recipientContent);
}

if (strstr($recipientContent, '$idca$')) {
$recipientContent = str_replace('$idca$', $user['idcard'], $recipientContent);
}

return $recipientContent;
}

解释:
我们看到性别这一段多了好几个判断

1
2
3
4
5
6
7
8
if (strstr($recipientContent, '$sex$')) {
if ($user['gender'] == 'male'){
$recipientContent = str_replace('$sex$', '男', $recipientContent);}
if ($user['gender'] == 'female'){
$recipientContent = str_replace('$sex$', '女', $recipientContent);}
if ($user['gender'] == 'secret'){
$recipientContent = str_replace('$sex$', '保密', $recipientContent);}
}

这是因为如果你没加判断的话,因为性别的结果是直接读数据库的,而写库的时候是以英文去写的,这个时候出来的性别结果会是英文,只有我们底下加了这三个判断,出来的性别结果才会强制转换为中文。

五、版权去除
部署完毕后,你会发现浏览器的标签页上会多了个- Powered By EduSoho,主页底部也会有一个叫做 Powered By EduSoho v21.1.3 @2014-2021的版权字样
根据EduSoho的开源协议规定,这两个地方是不允许去除的,否则会被追究法律责任。
我只是用来研究它的结构,所以蛮记录下,但是如果你是拿来商用或其他非研究学习用途的,千万不要去除版权

1、去除浏览器标签的- Powered By EduSoho字样

1
2
vi /www/edusoho/app/Resources/views/browser/upgrade.html.twig
在第九行中将- Powered by EduSoho字样删除即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class=""> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
 <title>{{'upgrade.browser.title'|trans}} - {{ setting('site.name') }}{% if not setting('copyright.owned') %} - Powered by EduSoho{% endif %}</title>
//这里的- Powered by EduSoho删除
 <link rel="stylesheet" media="screen" href="{{ asset('bundles/topxiaweb/css/browser-upgrade.css') }}" />
</head>

<body>
<div class="container">
<div class="title">{{ setting('site.name') }}</div>
<div class="message">{{'upgrade.browser.message'|trans({ '%name%':site.name })}}</div>
<div class="browsers">
<div class="head">{{'upgrade.browser.recommend_browsers'|trans}}</div>
<div>
<a href="http://www.google.cn/intl/zh-CN/chrome/browser/" target="_blank"><i class="browser-chrome"></i></a>
<a href="http://firefox.com.cn/download/" target="_blank"><i class="browser-firefox"></i></a>
<a href="http://windows.microsoft.com/zh-CN/internet-explorer/downloads/ie" target="_blank"><i class="browser-ie"></i></a>
</div>
</div>
</div>
</body>
</html>

2、去除底部的Powered By EduSoho v21.1.3 @2014-2021字样

1
2
vi /www/edusoho/app/Resources/views/powered-by.html.twig
将第6行删除或者修改即可

1
2
3
4
5
6
7
8
{% if setting('copyright.owned') and setting('copyright.thirdCopyright')|default(0) != 2 and setting('copyright.licenseDomains') and app.request.server.get('HTTP_HOST') in setting('copyright.licenseDomains')|split(';') %}
{% if setting('copyright.name') %}
Powered by <a href="{{ path('homepage') }}" target="_blank">{{ setting('copyright.name') }}</a>
{% endif %}
{% else %}
 Powered by <a href="http://www.edusoho.com/" target="_blank">EduSoho v{{constant('\\AppBundle\\System::VERSION') }}</a> //修改这里的链接和EduSoho v或者整行删除
 ©2014-{{ null|date('Y') }}
{% endif %}
六、未解决的问题总结:

1、证书添加头像
搞了好几天,证书上显示用户的头像还是没搞出来,代码太绕了,烧脑

七、踩坑

如果你不是用它的插件之类的(插件要收费),千万千万不要绑定域名,域名一经绑定,你nginx换个域名就会提示file not found,如果只是为了升级系统,你可以先本地虚拟机部署一个edusoho系统,然后把AccessKey和SecretKey复制到实际用的edusoho系统去,应用前记得先把实际应用的edusoho系统的AccessKey和SecretKey复制一份保存,等升级完了再把没绑域名的AccessKey和SecretKey再改回去

传送门:

EduSoho官网
EduSoho下载地址
EduSoho Github

本文仅用于学习研究,切勿用于其他非法用途。若因使用者用于非法用途导致侵犯软件作者的利益,因此产生的责任(包括但不限于法律责任)与博主无关!!!
关注我的公众号吧~戴戴的Linux

文章目录
  1. 1. 最近由于公司业务需求,需要一套类似于Mooc的网校系统,很早之前就部署过Edusoho这套网校系统,刚好可以拿来用。
  2. 2. 所需环境
  3. 3. 一、部署步骤如下
  4. 4. 点击这里查看如何部署LNMP:Centos7 Build LNMP Server
  5. 5. 二、配置Nginx
  6. 6. nginx配文说明:
  7. 7. I.edusoho配文
  8. 8. II.nginx.conf配文
  9. 9. 三、数据库配置
  10. 10. 四、设置证书内容有姓名、公司、身份证号、课程、性别的关键字
  11. 11. 全部代码如下:
  12. 12. 五、版权去除
  13. 13. 部署完毕后,你会发现浏览器的标签页上会多了个- Powered By EduSoho,主页底部也会有一个叫做 Powered By EduSoho v21.1.3 @2014-2021的版权字样
  14. 14. 根据EduSoho的开源协议规定,这两个地方是不允许去除的,否则会被追究法律责任。
  15. 15. 我只是用来研究它的结构,所以蛮记录下,但是如果你是拿来商用或其他非研究学习用途的,千万不要去除版权
  16. 16. 六、未解决的问题总结:
  17. 17. 七、踩坑
  18. 18. 传送门:


本站总访问量 本文总阅读量