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 layoutWeb-server mappingExample browser URL
Moodle before 5.1, installed in htdocs/moodleServe that installation directory under /moodlehttp://localhost/moodle/
Moodle 5.1 and later public-directory layoutServe the installation’s public directory, keeping the remaining code outside the served treeDepends on the configured virtual host or alias
Local server configured on port 8888Same mapping with the server’s actual porthttp://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

  1. Code: unpack an official Moodle download into your chosen code directory.
  2. Web root: map the browser URL to the correct served directory for that version.
  3. Data: create a separate moodledata directory 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 fieldWhat to enter
Web address / wwwrootThe exact configured browser base URL, including a non-default port if needed
Data directoryAbsolute filesystem path to the separate moodledata directory
Database hostAddress reachable from the PHP process; use a database service name inside a shared container network
Database name and userThe 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

SymptomCheck before retrying
Connection refusedWeb-server process and actual port; no installer can run before the server answers
404 on /moodle/install.phpDocumentRoot or alias, directory name, and the version’s public layout
Missing extension or unsupported PHPThe web runtime’s active php.ini, not only CLI PHP
moodledata not writableAbsolute path and permissions for the web-server user; avoid granting everyone write access
Database connection failedDatabase process, host, credentials, and database version
CSS or generated links use another addressConfigured 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.

Local development guides & tools © LocalHost Run