Azure Ubuntu20.04虚拟机部署Moodle遇脚本执行错误及首页跳转问题
一、CLI安装脚本提示“Could not open input file”的解决方案
确认文件真实路径
先全局搜索install.php的实际位置,执行命令:find / -name "install.php" -type f搜索结果会显示完整路径,比如常见的
/var/www/html/moodle/admin/cli/install.php(多数用户会把Moodle解压到Apache默认根目录下)。若你的Moodle确实在根目录/moodle,执行ls /moodle/admin/cli/再次确认install.php存在,注意Linux路径区分大小写,别写错文件名。使用正确的PHP CLI路径
先确认系统中PHP CLI的实际位置,执行:which php或针对PHP7.4:
which php7.4用返回的路径加上正确的install.php路径执行,例如:
/usr/bin/php /var/www/html/moodle/admin/cli/install.php检查文件权限
确保PHP进程能读取该文件,执行:ls -l /path/to/install.php若所有者不是www-data(Apache运行用户),修改权限:
sudo chown -R www-data:www-data /path/to/moodle
二、设置Apache默认页跳转至Moodle
Moodle安装完成后不会自动完成跳转,需手动配置,以下是几种常用方法:
简单PHP跳转
删除Apache默认的/var/www/html/index.html,在该目录下创建index.php文件,内容如下:<?php header("Location: /moodle"); exit; ?>访问公网IP时会自动跳转到Moodle页面。
修改Apache文档根目录
编辑Apache默认站点配置文件:sudo nano /etc/apache2/sites-available/000-default.conf将
DocumentRoot /var/www/html修改为你的Moodle根目录,比如DocumentRoot /var/www/html/moodle,保存后重启Apache:sudo systemctl restart apache2此时访问公网IP会直接打开Moodle首页。
使用Apache重写规则
先启用mod_rewrite模块:sudo a2enmod rewrite编辑Apache站点配置,在
<Directory /var/www/html>块中添加AllowOverride All:sudo nano /etc/apache2/sites-available/000-default.conf保存后在
/var/www/html目录下创建.htaccess文件,内容如下:RewriteEngine On RewriteRule ^$ /moodle [R=301,L]最后重启Apache生效:
sudo systemctl restart apache2
内容的提问来源于stack exchange,提问作者Zabrake

