Plugins Plugin hub Backup SEO Caching Security Forms WooCommerce Images Best backup plugins
Hosting Hosting directory Shared hosting Managed WordPress Cloud hosting VPS hosting By reader location Hosting finder
Themes & builders Compare Rank Math vs Yoast
Tools All tools Hosting finder Plugin stack builder Cost calculator Salt generator Theme detector Who is hosting this? Speed test Headline analyzer robots.txt generator Redirect generator Uptime calculator Blog name generator
Blog Best backup plugins Deals
Guides All guides Speed up WordPress Choose hosting Back up WordPress
How we test

Troubleshooting

WordPress Not Working on localhost: Causes and How to Fix It

WordPress Not Working on localhost: Causes and How to Fix It

Short answer

WordPress on localhost usually fails because Apache or MySQL is stopped, another program is using port 80 or 3306, the wp-config database details are wrong, or the site URL still points to a live domain. Start both services, fix the port or credentials, and set the correct local URL.

Key takeaways

  • Confirm both the web server and MySQL are running in your local tool.
  • Port conflicts on 80 or 3306 stop Apache or MySQL from starting.
  • XAMPP usually uses root with no password; MAMP uses root as the password.
  • Imported sites need their URL changed to the local address.
  • Inner-page 404s mean mod_rewrite or AllowOverride is not set.

Why is WordPress not working on localhost?

WordPress on localhost usually fails because Apache or MySQL is not running, a port is already in use, the database details are wrong, the URL is wrong, or permalinks need mod_rewrite.

A local install runs on your own computer through a tool like XAMPP, MAMP, WAMP, Local or Docker. It needs a web server, PHP and a database all working together.

If any one of those three parts stops, the browser shows an error such as This site can't be reached, Error establishing a database connection, a blank page or a 404.

Start by noting the exact message. Then work through the causes below in order, because the early ones are the most common.

Are Apache and MySQL actually running?

Open your local server's control panel and confirm both the web server and the database show as running; if either is stopped or fails to start, nothing else will work.

In XAMPP, open the Control Panel and click Start next to Apache and MySQL. Both should turn green.

In MAMP, the start button should show both servers active. In Local, the site must be started from the app.

If a service starts and then stops again, the log in the control panel usually explains why. The two most common reasons are a port conflict and a damaged MySQL data folder.

The XAMPP project site has FAQs for each operating system. If you have not set up XAMPP yet, our guide on adding WordPress to XAMPP covers it from the start.

How do you fix a port conflict on localhost?

Fix a port conflict by stopping the other program using port 80, 443 or 3306, or by changing your local server to use a different port such as 8080.

Apache normally listens on port 80 and MySQL on port 3306. Other programs can already be using those ports, including other local server stacks, Windows web services, and some chat or virtual machine apps.

You have two options:

  • Stop the other program. Close or disable the service using the port, then start Apache again.
  • Change the port. In XAMPP, edit Apache's httpd.conf and change Listen 80 to Listen 8080. Then visit localhost:8080/yoursite.

If you change the port after WordPress is installed, update the site URL too. Otherwise WordPress redirects you back to the old port.

How do you fix error establishing a database connection on localhost?

Check that MySQL is running, the database exists, and the database name, username, password and host in wp-config.php match your local server's settings.

Open wp-config.php in your site folder and look at these lines:

  • DB_NAME must match a database you created in phpMyAdmin.
  • DB_USER is often root on a fresh XAMPP install.
  • DB_PASSWORD is often empty on XAMPP, but MAMP uses root by default.
  • DB_HOST is usually localhost. If MySQL runs on a custom port, use localhost:3307 or 127.0.0.1 with that port.

Create the database first if it does not exist. Open phpMyAdmin from the control panel, click New, give it the name you used in wp-config.php, and save.

For more causes, see our guide to fixing error establishing a database connection.

Are you using the right localhost URL?

Use the address that matches your site folder, such as localhost/mysite, and make sure the WordPress and site address values in the database match it.

In XAMPP, sites live in the htdocs folder. A folder named mysite is reached at http://localhost/mysite. Typing just localhost opens the XAMPP dashboard instead.

Problems often start after importing a live site. The database still holds the live domain, so WordPress redirects you to the real website or shows a broken page.

Fix it by setting the correct values in wp-config.php:

define( 'WP_HOME', 'http://localhost/mysite' );
define( 'WP_SITEURL', 'http://localhost/mysite' );

Then run a search and replace for the live address. Our guide on WordPress not working after changing the site URL explains the safe way to do that.

Why can you not open the dashboard on localhost?

You cannot open the dashboard on localhost when the site URL is wrong, cookies do not match the address, or WordPress is not fully installed yet.

Go to http://localhost/mysite/wp-admin/. If WordPress was never installed, you will see the install screen instead, which is normal. Fill it in to create your admin account.

If the login page keeps reloading, the address in your browser does not match the site URL, or you mixed localhost with 127.0.0.1. Use one form everywhere.

Our guide on opening the WordPress dashboard on localhost covers the login steps for each local tool.

Why do pages show 404 on localhost but the homepage works?

Inner pages return 404 on localhost when Apache's rewrite module is off, the .htaccess file is missing, or the server ignores .htaccess rules.

WordPress pretty permalinks need mod_rewrite. To fix it in XAMPP:

  1. Open httpd.conf and make sure the line loading mod_rewrite is not commented out.
  2. In the same file, find the section for htdocs and set AllowOverride All.
  3. Restart Apache.
  4. In WordPress, go to Settings > Permalinks and click Save Changes to rebuild .htaccess.

The Apache mod_rewrite documentation explains the module if you want the details. For other permalink issues, see our guide to fixing permalinks not working.

Can PHP settings break WordPress on localhost?

Yes, a PHP version that is too old or too new for your plugins, a missing extension such as mysqli, or a low memory limit can cause blank pages or fatal errors.

Check which PHP version your local tool uses. Local and MAMP let you switch per site. XAMPP ties the PHP version to the XAMPP release you installed.

WordPress needs the mysqli extension to talk to the database. It is enabled by default in most stacks, but a custom php.ini may have turned it off. The PHP manual's mysqli page lists the requirements.

To see the real error instead of a blank page, turn on debugging in wp-config.php. Our guide on enabling debug mode shows the lines to add.

Can file permissions cause problems on Mac or Linux?

Yes, if the web server user cannot read or write your site folder, you will see install errors, failed uploads or requests for FTP details when installing plugins.

On Mac and Linux, files you copy into the web folder may belong to your user, not the web server. WordPress then cannot write to wp-content.

Fix it by giving the web server write access to wp-content, or add define( 'FS_METHOD', 'direct' ); to wp-config.php on a local site only. Never use wide-open 777 permissions on a live server.

Which local tool causes the fewest problems?

Purpose-built tools like Local or WordPress Studio usually cause fewer problems than general stacks like XAMPP, because they configure ports, PHP and databases per site.

ToolSetup effortCommon issues
XAMPPModeratePort conflicts, manual database setup
MAMPModerateDefault ports differ, MySQL password is root
LocalLowNeeds app running, router mode settings
WordPress StudioLowFewer server options
DockerHigherContainer and volume configuration

If XAMPP keeps fighting you, try Local or a similar tool. Our guide to setting up a local WordPress development environment compares the options in more detail.

Frequently asked questions

Why does localhost show the XAMPP dashboard instead of my site?

Typing localhost alone opens the default htdocs index, which is the XAMPP dashboard. Add your site's folder name to the address, for example localhost followed by a slash and the folder name, to load your WordPress site.

Why does my local WordPress site redirect to the live site?

The database still contains the live domain in the home and siteurl options. Set the local address with WP_HOME and WP_SITEURL in wp-config, then run a serialization-safe search and replace to change the remaining links.

What are the default database login details for XAMPP?

A fresh XAMPP install usually uses root as the username with an empty password and localhost as the host. MAMP uses root for both the username and password. Create the database in phpMyAdmin before running the WordPress installer.

Why does Apache not start in XAMPP?

The most common reason is that another program already uses port 80 or 443. Close that program or change Apache's listen port in httpd.conf to something like 8080. The XAMPP control panel log usually names the blocked port.

Can I use HTTPS on a localhost WordPress site?

Yes, but you need a local certificate. Tools like Local can create and trust one for you. With XAMPP you must configure it yourself. For most testing, plain HTTP on localhost is fine and avoids certificate warnings.

Sources

  1. XAMPP Apache Friends
  2. mod_rewrite Apache HTTP Server
  3. MySQL Improved Extension PHP Manual
  4. Local Local

Is your product missing, or something out of date?

Tell us what to add or correct. We read every note and reply when we need a source. A message does not buy a ranking.

About the editors

Written and checked byWPLegible Editorial Team Independent WordPress reviews and guides

Researched from the primary sources listed above and checked against our editorial rules before publishing.