Updated:
Install Moodle on Localhost: Paths, install.php and Fixes
Choose the correct web root for your Moodle version, configure moodledata and the database, and troubleshoot 404, PHP extensions, and installer failures.
http://localhost/moodle/ opens a Moodle installation only if your local web server maps that URL to Moodle. Searching for it does not install Moodle. First check the Moodle version and your web server configuration: the layout changed in Moodle 5.1.
Choose the web root for your version
| Version or layout | Web-server mapping | Example browser URL |
|---|---|---|
Moodle before 5.1, installed in htdocs/moodle | Serve that installation directory under /moodle | http://localhost/moodle/ |
| Moodle 5.1 and later public-directory layout | Serve the installation’s public directory, keeping the remaining code outside the served tree | Depends on the configured virtual host or alias |
| Local server configured on port 8888 | Same mapping with the server’s actual port | http://localhost:8888/moodle/ |
For Moodle 5.1+, simply copying the entire download into htdocs/moodle is not sufficient. Follow the versioned installation instructions and web-server routing guidance. A subdirectory URL is possible, but its alias or virtual host must map to public correctly; changing the URL alone does not configure it.
Check requirements before installing
Match the PHP and database versions to the exact Moodle release. For example, the Moodle 5.1 release requirements specify PHP 8.2 minimum, PostgreSQL 15, MySQL 8.4, or MariaDB 10.11 minimum. Do not assume an existing XAMPP or MAMP package meets those requirements.
Check CLI PHP with php -v, php --ini, and php -m. Apache or PHP-FPM can use a different PHP binary and configuration; the installer’s environment checks describe the web runtime. Enable only the required extensions in that runtime’s active configuration and restart it.
Prepare three separate locations
- Code: unpack an official Moodle download into your chosen code directory.
- Web root: map the browser URL to the correct served directory for that version.
- Data: create a separate
moodledatadirectory writable by the web-server account and outside the publicly served directory.
Download code from Moodle’s official downloads. Create a dedicated database and account with permissions for that Moodle database. phpMyAdmin can help administer MySQL or MariaDB; use the actual configured database credentials rather than assuming the phpMyAdmin login is the Moodle application account.
Run the installer
With the web server and database running, open the URL you configured. If it is http://localhost/moodle/, the first-install script is http://localhost/moodle/install.php.
| Installer field | What to enter |
|---|---|
Web address / wwwroot | The exact configured browser base URL, including a non-default port if needed |
| Data directory | Absolute filesystem path to the separate moodledata directory |
| Database host | Address reachable from the PHP process; use a database service name inside a shared container network |
| Database name and user | The database and credentials created for Moodle |
Complete environment checks, schema installation, and administrator setup. Confirm you can log in and create a test course. If the browser URL changes later, review wwwroot in config.php so generated links match it.
Troubleshoot by the visible symptom
| Symptom | Check before retrying |
|---|---|
| Connection refused | Web-server process and actual port; no installer can run before the server answers |
404 on /moodle/install.php | DocumentRoot or alias, directory name, and the version’s public layout |
| Missing extension or unsupported PHP | The web runtime’s active php.ini, not only CLI PHP |
moodledata not writable | Absolute path and permissions for the web-server user; avoid granting everyone write access |
| Database connection failed | Database process, host, credentials, and database version |
| CSS or generated links use another address | Configured wwwroot, port, and web-server mapping |
Read the web server’s error log for a blank page or HTTP 500. Record the first relevant error before repeatedly restarting installation.
Configure background tasks
Use the CLI cron script with a compatible PHP executable:
php /absolute/path/to/moodle/admin/cli/cron.php
The path is to your installation; replace it before running. The Moodle cron guide recommends scheduling the command every minute. Use your OS scheduler; browser-based cron is not the preferred setup.
Related: local PHP environments, port troubleshooting, and localhost URL parsing.