A local development and testing server is one of the most important tools in any WordPress developer’s arsenal. These tried-and-tested solutions enable you to quickly and easily build a website, without the risk of breaking a live web server. However, they may occasionally still encounter issues.
MAMP is a popular local web development tool for building WordPress websites, but it can occasionally fall prey to localhost problems. Fortunately, if you’re encountering the common “localhost refused to connect” message, there are steps you can take to resolve this error.
In this article, we’ll explore what MAMP’s localhost error is, and what causes the problem. We’ll then share seven ways you can solve this connection issue. Let’s get started!
An Introduction to MAMP (And the “Localhost Refused to Connect” Error)
MAMP is a solution stack composed of open source and proprietary software. The name MAMP is derived from its components: macOS, Apache, PHP, MySQL or MariaDB, and Perl or Python. However, MAMP isn’t restricted to these elements. For example, you might choose to use Nginx instead of Apache.
MAMP installs a local server environment on your Windows or macOS computer, and is commonly used to develop dynamic websites. MAMP is also widely used by developers working with Content Management Systems (CMS) such as WordPress:
With MAMP, you can set up a local development environment on your computer. This eliminates the time, cost, and complexity often associated with configuring a standalone web server. In other words, it’s ideal for quickly testing projects, or for developing websites without the risk of breaking a live server.
However, you may still encounter issues when using MAMP. When you attempt to access your localhost, it’s possible that you might see the following error message: “localhost refused to connect”.
This typically occurs when there’s an issue with your port configuration. For example, another service may be blocking the port MAMP is trying to use, or perhaps you’re attempting to access the wrong port entirely. You may also encounter this error when MAMP fails to start the server.
How to Resolve MAMP’s “Localhost Refused to Connect” Error (7 Methods)
MAMP is a popular solution for developing and testing projects in a local environment. However, if you can’t connect to localhost, you’ll struggle to get any value out of this tool. If you’re encountering the “localhost refused to connect” error, here are seven fixes that should help you re-connect and get back to work.
1. Try a Different Web Browser
It’s possible that your connection issues may be browser-specific. Every web browser has a unique setup and behavior.
In particular, some browsers automatically redirect to the Hypertext Transfer Protocol Secure (HTTPS) equivalent of any HTTP web address. If you don’t have Secure Sockets Layer (SSL) enabled for your web project, this redirect may trigger a localhost error.
Before moving onto more complex fixes, you may want to try accessing your localhost via an alternative web browser. This can help you test whether the issue lies with MAMP, or the browser you’re using.
If you don’t encounter the localhost error in an alternative browser, this suggests that the problem is browser-specific. In this scenario, we recommend checking your browser’s settings for any configurations that might cause issues with MAMP. For example, you might discover that your browser is redirecting HTTP requests to HTTPS by default.
The steps for resolving this redirect issue will vary based on what you’re using. For example, Chrome users can disable this redirect by heading to chrome://net-internals/#hsts:
Next, scroll to the following section, Delete domain security policies, and input your localhost domain. You can then select Delete, which should disable Chrome’s redirect for your localhost.
2. Allow Incoming Connections
If you’re unable to access the web server via localhost, there’s a chance that your firewall may be blocking the connection. You can often resolve this problem by modifying your firewall settings to allow incoming connections for the port that MAMP is trying to access. Alternatively, you can allow connections for the entire MAMP application.
If you’re a macOS user, you can edit your firewall settings by navigating to Apple > System Preferences… > Security & Privacy. You can then select the Firewall tab:
To enable incoming connections for the entire MAMP application, select Firewall Options. You can then click on the + icon, select MAMP, and choose Add. MAMP will then be added to your list of permitted applications.
At this point, check to make sure that the MAMP application is configured to Allow incoming connections, and then click on OK. Your firewall will now permit all incoming connections for MAMP.
If you’re using Windows Defender, you should have received a firewall notification when you installed MAMP. However, you can change your Windows firewall permissions at any time, by navigating to Start > Settings > Update & Security > Windows Security. You can then select Firewall & Network Protection to make the necessary changes to your firewall settings.
3. Check MAMP’s Document Root
When you access your localhost, MAMP displays the contents of your document root. By default, this is located at /Applications/MAMP/htdocs, and contains either an index.html or index.php file.
If you move or delete this index file, MAMP will have nothing to load. If you edit the index file incorrectly, MAMP may also struggle to display any content. This can cause a range of errors, including the “localhost refused to connect” message.
You can determine whether you’ve inadvertently modified or moved this important folder by heading to /Applications/MAMP/htdocs/. If it doesn’t contain an index.html or index.php file, that is likely contributing to your localhost errors.
It’s also worth checking to see if MAMP is loading content from the correct folder. If you’re using the free version of MAMP, you can check the root document’s location in the main MAMP window:
If you’re using MAMP Pro, this process is slightly different. You can verify the root’s location by selecting Hosts > General. This screen will display your Document Root file path:
If you suspect that there may be an issue with your document root, you can simply select Open In followed by your favorite file manager. This will take you directly to the document root, where you can inspect the folder’s contents and make any necessary changes.
4. Change the Port Settings
Server programs such as MAMP require exclusive access to a specific network port. This enables multiple programs to run on the same machine.
Every server has a default port. The Apache web server typically uses port 80, while the MySQL database server uses port 3306. By default, MAMP uses ports 8888, 8889, and 7888. However, these ports may already be in use by some other program or piece of software.
In this scenario, you can configure MAMP to use an alternative port. If you’re using the free version, you can check the port settings by navigating to MAMP > Preferences. Then select the Port tab:
If you’re using MAMP Pro, you’ll find these options in the Ports & User tab. You can then see the exact ports that MAMP is using:
If MAMP is already using an alternative port, you can try restoring the default settings by selecting MAMP default. If you’re a Pro user, you can click on the Set default MAMP Ports button. This will reset the ports for Apache, Nginx, and MySQL to 8888, 7888, and 8889.
Alternatively, MAMP has an 80 & 3306 button, which will set the ports to most commonly used values. After modifying the port settings, you may get positive results by typing the new port number directly into your browser’s address bar, as in http://<localhost>:8888/.
If you’re still encountering the localhost error, you can try configuring MAMP to use a completely random port number, such as 8814. You can then type this address directly into your web browser (http://localhost:8814/) to see whether it resolves your localhost problem.
5. Verify That Your Apache Web Server Is Running
Apache is one of the most frequently-used web servers. Both MAMP and MAMP Pro provide this option. If the Apache server isn’t running, however, you’ll struggle to connect to your localhost.
You can see whether your Apache server is running by taking a look at the Stop/Start button in upper right hand corner of the MAMP app. If the Apache web server is active, this button will be green. If you’re a MAMP Pro user, you can perform verification by selecting “Apache” in the left-hand menu:
MAMP Pro users can also view more information about their Apache servers by selecting either Info or Status. If the server is running, both of these buttons will launch a tab containing more information about the Apache configuration.
If your Apache web server isn’t running, another MySQL service may be using the same port. If you suspect this is the case, one solution is to quit all httpd processes on your machine. The exact steps to quit httpd processes will vary depending on your operating system.
Looking for high-performance WordPress hosting powered by Google Cloud Platform’s fastest servers? Check out our plans.
Mac users can identify and quit httpd processes using Activity Monitor. In the Activity Monitor toolbar, select View > All Processes:
In the Search field, type “httpd”. Select each result in the list, and then click on the Stop icon in Activity Monitor’s upper-left corner:
After quitting every httpd process, relaunch MAMP and try restarting the Apache web server.
If this doesn’t resolve your issue, there’s a chance that your httpd.conf.temp file may be corrupted. Some MAMP Pro users have reported positive results after renaming this file.
On your local machine, navigate to ~/Library/Application Support/appsolute/MAMP PRO/templates. You can then rename httpd.conf.temp to http.conf.temp.bak. Restart MAMP, and check to see whether your Apache server is now running successfully.
6. Restart the Apache Web Server
You can also resolve the “localhost refused to connect” error by restarting the Apache web server. To stop the server, launch your Mac’s Terminal by navigating to Applications > Utilities > Terminal.
Alternatively, Windows users can launch the Command Prompt. Then run the following command: “sudo apachectl stop”. In the Terminal or Command Prompt window, you should see the following message: Operation now in progress.
If you’ve modified MAMP’s port settings, it’s a good idea to restore them to their defaults (80/3306). You can either navigate to MAMP > Preferences… > Ports (MAMP), or Ports & User (MAMP Pro). In the resulting window, select MAMP default.
Next, switch back to the Terminal or Command Prompt, and run the following command: “sudo apachectl restart”. You can then restart the Apache web server by selecting the Start / Stop icon in MAMP’s upper-right corner.
7. Reinstall MAMP
Last but not least, you may be able to resolve this issue by uninstalling and then reinstalling MAMP. Just be aware that uninstalling the program will remove all the databases located in your db folder.
If you’re using MAMP Pro, that folder is located in /Library/Application Support/appsolute/MAMP PRO/db. If you want to retain this information, you can move the files to a secure location before uninstalling MAMP.
We also recommend making a note of your Apache, MySQL, and DynDNS port numbers, as some Content Management Systems (CMSs) are port-dependent. You can find this information by selecting Hosts in MAMP’s left-hand menu, and then opening the General tab.
To uninstall MAMP Pro, select MAMP PRO > Uninstall MAMP Pro. If prompted, enter your admin username and password:
After uninstalling MAMP, you’ll see the following message: MAMP Pro has been uninstalled successfully. You can now head over to your computer’s /Applications folder, and delete the MAMP folder.
Now that you’ve completely removed MAMP, it’s time to reinstall it! You can download a fresh copy of MAMP from the official website, and then install the application as normal.
After successfully installing MAMP, you may want to restore your databases. In your favorite file manager, navigate to /Library/Application Support/appsolute/MAMP PRO/db. You can then drag your db files into that folder.
The MAMP local server environment can be invaluable for building and testing your website. However, if you encounter the “localhost refused to connect” error, you’ll have to resolve it before moving forward.
Fortunately, if you do encounter this problem, there are steps you can take to resolve it. We recommend testing to see whether the issue is browser-specific, by trying to access your project via an alternative web browser. You may also get positive results by modifying your firewall settings and MAMP’s port configuration.
Do you have any questions about resolving the “localhost refused to connect” error? Share them in the comments section below!
Save time, costs and maximize site performance with:
- Instant help from WordPress hosting experts, 24/7.
- Cloudflare Enterprise integration.
- Global audience reach with 28 data centers worldwide.
- Optimization with our built-in Application Performance Monitoring.