基于Apache+php+MySQL+Moodle搭建本地课程管理系统(CMS)

环境配置

apache配置

下载Apache 2.4.35 Win64,此为免安装版,解压到amp目录下,修改配置文件httpd.conf(注意与php相关的配置根据php版本修改)。

运行cmd,进入Apache24/bin目录,输入httpd.exe,启动http服务器。在浏览器中输入localhost:8080/index.html,显示It works!,表明Apache配置成功。

php配置

下载php VC15 x64 Thread Safe,此为免安装版,解压到amp目录下,修改配置文件名php.ini-developmentphp.ini,按要求配置,需要取消部分用;注释的配置。

在Apache24/htdocs文件夹中新建文件phpinfo.php,写入如下代码:

<?php
echo phpinfo();

在浏览器中输入localhost:8080/phpinfo.php,如果显示php版本信息,则php配置成功。

mysql配置

下载MySQL Community Server 5.6.41,解压到amp目录下,按要求安装。新建配置文件my.ini,写入以下内容。

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
 basedir = F:\amp\mysql\mysql-5.6.41-winx64
 datadir = F:\amp\mysql\mysql-5.6.41-winx64\data
port = 3306
character_set_server=utf8
# server_id = .....


# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

innodb_file_format = barracuda
innodb_large_prefix = 1
innodb_file_per_table = 1
[client]
port=3306
default-character-set=utf8

启动mysql:net start mysql

修改root密码:

use mysql;
UPDATE user SET password=PASSWORD("123456") WHERE user='root';
FLUSH PRIVILEGES;

停止mysql:net stop mysql

测试mysql,在Apache24/htdocs文件夹中新建文件test.php,写入如下代码:

<?php
define("DB_SERVER", "localhost");
define("DB_USER", "root");
define("DB_PASSWORD", "LLte6628");
define("DB_DATABASE", "snp01");

$con = mysqli_connect(DB_SERVER , DB_USER, DB_PASSWORD, DB_DATABASE);
if(!$con)
    die("连接错误:".mysqli_connect_error());
else
    echo "恭喜,mysql连接成功!\n";
?>

在浏览器中输入localhost:8080/test.php,如果显示恭喜,mysql连接成功!,则mysql配置成功。

moodle安装

下载Moodle 3.5.2+,启动web server,浏览器输入localhost:8080/moodle/index.php。部分需要填写的信息如下:

数据库主机:即dbhost,为用于存放数据库的机器的IP或域名,此处填入localhost;
数据库名:即dbname,为Moodle使用的数据库
数据用户名:即dbuser,为提供使用的数据库用户名(对Moodle的数据库有一定权限的用户),此处填入root;
数据库密码:即dbpass,为数据库用户的密码,此处填入root对应的密码;
表格名称前缀:默认为mdl_,可修改。
数据库服务端口:即为数据库服务占用的端口,MySQL为3306。

安装过程中可能需要php_extension,把php.ini对应的扩展行首的注释符去掉即可。对mysql配置文件的修改参考[4]。

在浏览器中输入localhost:8080/moodle,若出现登陆界面则表示安装成功。

结果展示

01

主要参考资料

[1]. Windows下Apache+PHP+MySQL搭建历程

[2]. windows下配置apache+php环境

[3]. MYSQL安装出现问题(The service already exists)

[4]. Moodle 服务器安装 error