{"id":40288,"date":"2021-11-25T10:03:38","date_gmt":"2021-11-25T10:03:38","guid":{"rendered":"\/tutorials\/?p=40288"},"modified":"2026-03-10T09:29:33","modified_gmt":"2026-03-10T09:29:33","slug":"how-to-fix-localhost-refused-to-connect-error","status":"publish","type":"post","link":"\/ca\/tutorials\/how-to-fix-localhost-refused-to-connect-error","title":{"rendered":"Localhost refused to connect: 5 solutions to fix the Error"},"content":{"rendered":"<p>Among the different network connection errors you might encounter is &ldquo;<strong>localhost refused to connect<\/strong>&rdquo; or the &ldquo;<strong>ERR_Connection_Refused<\/strong>&rdquo; error.<\/p><p>When you try to connect to an IP address, you usually try to connect to a different computer. However, since localhost uses the loopback address network, connecting to it means you&rsquo;re establishing a connection with your own computer.<\/p><p>That&rsquo;s why many developers and network administrators use localhost to test programs or sites that are still in development. Doing so reduces the risk of breaking a live site.<\/p><p>So, when you can&rsquo;t access localhost, you won&rsquo;t be able to access your project in a local environment.<\/p><p>There are various causes of this error, as shown in the table below. Also, note that you have to be on your local machine to access your localhost &ndash; you can&rsquo;t access it on any other device.<\/p><figure tabindex=\"0\" class=\"wp-block-table\"><table><tbody><tr><td><strong>Error code<\/strong><\/td><td>Localhost Refused to Connect<\/td><\/tr><tr><td><strong>Error type<\/strong><\/td><td>Browser\/Firewall<\/td><\/tr><tr><td><strong>Error variations<\/strong><\/td><td>ERR_CONNECTION_REFUSED<br>127.0.0.1 refused to connect<br>This site can&rsquo;t be reached localhost refused to connect.<\/td><\/tr><tr><td><strong>Error causes<\/strong><\/td><td>Server blocked by firewall<br>Server running on a wrong port<br>Apache server not running properly<br>Browser settings need to be reconfigured<\/td><\/tr><\/tbody><\/table><\/figure><?xml encoding=\"utf-8\" ?><figure class=\"wp-block-image size-full\"><a class=\"hgr-tutorials-cta hgr-tutorials-cta-web-hosting\" href=\"\/ca\/web-hosting\" target=\"_blank\" rel=\"noreferrer noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/11\/Web-hosting_in-text-banner.png\" alt=\"Hostinger web hosting banner\" class=\"wp-image-98604\"  sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><p>\n\n\n\n<div class=\"protip\">\n                    <h2 class=\"featured-snippet title\">What Is the Localhost Refused to Connect Error?<\/h2>\n                    <p>It is a common error that can happen when working on a local machine. The localhost simulates a web server running on your computer. When the &ldquo;localhost refused to connect&rdquo; error appears, it is likely due to misconfigured port. Other common reasons include insufficient permissions and the Apache webserver not running properly.<\/p>\n                <\/div>\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-fix-localhost-refused-to-connect-video-tutorial\">How to fix &ldquo;localhost refused to connect&rdquo; &ndash; video tutorial<\/h2><p>If you prefer a visual guide to fixing this error, watch our video tutorial below. Otherwise, feel free to skip to the next section.<\/p><figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"How to Fix Localhost Refused to Connect\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/fzTq0e-tHvo?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure><p>\n  <div class=\"youtube-shortcode\">\n    <div class=\"row\">\n      <div class=\"col-7 col-sm-8 d-flex align-items-center\">\n        <img decoding=\"async\" class=\"channel-logo\" src=\"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-content\/themes\/tutorialsthemeuplift\/public\/images\/youtube-channels\/hostinger-academy.jpg\" alt=\"youtube channel logo\">\n        <div class=\"d-flex flex-column justify-content-between\">\n          <span class=\"slogan d-none d-sm-block\">Subscribe For more educational videos!<\/span>\n          <span class=\"channel-name\">Hostinger Academy<\/span>\n                    <\/div>\n      <\/div>\n      <div class=\"col-5 col-sm-4 d-flex align-items-center justify-content-end\">\n          <a class=\"subscribe-button\" target=\"_blank\" rel=\"nofollow noopener noreferrer\" href=\"http:\/\/www.youtube.com\/channel\/UCbNIC-svDbtUOH2qsLnPQPg?sub_confirmation=1\">\n            <img decoding=\"async\" src=\"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-content\/themes\/tutorialsthemeuplift\/public\/images\/icons\/youtube.svg\" alt=\"subscribe\">\n            <span>Subscribe<\/span>\n          <\/a>\n      <\/div>\n    <\/div>\n  <\/div>\n\n    \n\n\n\n<\/p><p><\/p><h2 class=\"wp-block-heading\" id=\"h-5-methods-to-solve-the-localhost-refused-to-connect-error\">5 methods to solve the &ldquo;localhost refused to connect&rdquo; error<\/h2><p>Here are five methods to solve the &ldquo;<strong>localhost refused to connect<\/strong>&rdquo; error, in no particular order.<\/p><h3 class=\"wp-block-heading\" id=\"h-1-temporarily-disable-your-firewall\">1. Temporarily disable your firewall<\/h3><p>A firewall is a security system that monitors and filters your traffic, blocking potential threats. While it&rsquo;s an important tool, the detection protocols may run inaccurately sometimes.<\/p><p>A firewall might incorrectly block safe web pages or incoming connections. Therefore, if you&rsquo;re currently developing a website and you need to access its locally hosted version, it&rsquo;s best to temporarily disable the firewall. That way, your test site won&rsquo;t be blocked.<\/p><p>Remember that re-enable your firewall immediately once the website goes live and you no longer see the &ldquo;ERR_CONNECTION_REFUSED&rdquo; localhost problem message.<\/p><p>Here are the steps to disable the firewall on Mac, Windows, and Linux, respectively.<\/p><p><strong>How to disable the firewall on Mac<\/strong><\/p><ol class=\"wp-block-list\">\n<li>Navigate to <strong>System Preferences<\/strong>.<\/li>\n\n\n\n<li>Select <strong>Security and Privacy<\/strong>.<\/li>\n<\/ol><div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter size-full\"><a href=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/11\/mac-system-preferences.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1059\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/11\/mac-system-preferences.png\" alt=\"Accessing Mac's Security and Privacy via System Preferences\" class=\"wp-image-40289\"  sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div><ol class=\"wp-block-list\" start=\"3\">\n<li>Select the <strong>Firewall<\/strong> tab to see the complete firewall settings.<\/li>\n\n\n\n<li>Click the <strong>lock icon<\/strong>, then enter your username and password.<\/li>\n\n\n\n<li>You&rsquo;ll see a message informing you that, if you turn off the firewall, you&rsquo;ll accept all incoming connections, including those that potentially carry unauthorized resources. Click the <strong>Turn off Firewall<\/strong> button.<\/li>\n<\/ol><figure class=\"wp-block-image size-full is-style-default\"><a href=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/11\/image4.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1328\" height=\"1162\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/11\/image4.png\" alt=\"Turning off Mac's firewall via Security &amp; Privacy\" class=\"wp-image-40293\"  sizes=\"auto, (max-width: 1328px) 100vw, 1328px\" \/><\/a><\/figure><ol class=\"wp-block-list\" start=\"6\">\n<li>Click the <strong>lock<\/strong> to prevent further changes on this setting without your permission.<\/li>\n<\/ol><p>Note that the steps to disable the firewall on Mac might be slightly different depending on your macOS version.<\/p><p><strong>How to disable the firewall on Windows<\/strong><\/p><p>There are two ways to disable the firewall on Windows 10, 8, 7, and Vista &ndash; via the control panel or command prompt.<\/p><p>Here are the steps to disable the firewall using the control panel:<\/p><ol class=\"wp-block-list\">\n<li>Open the control panel, then navigate to <strong>System and Security <\/strong>-&gt;<strong> Windows Defender Firewall<\/strong>.<\/li>\n<\/ol><div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter size-full\"><a href=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/11\/image9.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1173\" height=\"575\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/11\/image9.png\" alt=\"Accessing Windows Defender Firewall via System and Security\" class=\"wp-image-40295\"  sizes=\"auto, (max-width: 1173px) 100vw, 1173px\" \/><\/a><\/figure><\/div><ol class=\"wp-block-list\" start=\"2\">\n<li>Select <strong>Turn Windows Defender Firewall on or off<\/strong>.<\/li>\n<\/ol><div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter size-full\"><a href=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/11\/turn-windows-defender-firewall-on-off.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1173\" height=\"663\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/11\/turn-windows-defender-firewall-on-off.png\" alt=\"Selecting Turn Windows Defender Firewall on or off\" class=\"wp-image-40299\"  sizes=\"auto, (max-width: 1173px) 100vw, 1173px\" \/><\/a><\/figure><\/div><ol class=\"wp-block-list\" start=\"3\">\n<li>Switch off both firewalls in the <strong>private<\/strong> and <strong>public<\/strong> network settings.<\/li>\n<\/ol><figure class=\"wp-block-image size-full is-style-default\"><a href=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/11\/private-public-network-firewalls.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1171\" height=\"883\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/11\/private-public-network-firewalls.png\" alt=\"Turning off firewalls in both private and public networks\" class=\"wp-image-40300\"  sizes=\"auto, (max-width: 1171px) 100vw, 1171px\" \/><\/a><\/figure><ol class=\"wp-block-list\" start=\"4\">\n<li>Click the <strong>OK<\/strong> button to apply the changes.<\/li>\n<\/ol><p>If the option is not clickable, it means the firewall settings are under another security program&rsquo;s control. If this is the case, you might want to uninstall that app first.<\/p><p>Meanwhile, these steps apply for turning off the firewall via the command prompt:<\/p><ol class=\"wp-block-list\">\n<li>Open the command prompt as administrator.<\/li>\n\n\n\n<li>Enter the following command:<\/li>\n<\/ol><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">netsh advfirewall set allprofiles state off<\/pre><p><strong>How to disable the firewall on Linux<\/strong><\/p><p>The steps to stop and disable the firewall vary according to your Linux distribution.<\/p><p>If you use <strong>Ubuntu<\/strong> or <strong>Debian<\/strong>, your firewall should be managed by <strong>ufw<\/strong>. If you use <strong>CentOS<\/strong> or <strong>RHEL<\/strong>, the default firewall management tool will be <strong>firewalld<\/strong>.<\/p><p><div><p class=\"important\">It&rsquo;s important to stop the firewall first before disabling it. Otherwise, you&rsquo;ll experience errors during the process.<\/p><\/div>\n\n\n\n<\/p><p>To disable the firewall on ufw, follow these steps:<\/p><ol class=\"wp-block-list\">\n<li>Stop the ufw using this command:<\/li>\n<\/ol><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo ufw disable<\/pre><ol class=\"wp-block-list\" start=\"2\">\n<li>Once the firewall successfully stops, run a command to disable the ufw service at boot time.<\/li>\n<\/ol><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo systemctl disable ufw<\/pre><ol class=\"wp-block-list\" start=\"3\">\n<li>Verify that the ufw is disabled by using this command:<\/li>\n<\/ol><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo ufw status\nsudo systemctl status ufw<\/pre><ol class=\"wp-block-list\" start=\"4\">\n<li>Re-enable the ufw.<\/li>\n<\/ol><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo systemctl enable ufw\nsudo ufw enable\n## verify that ufw started ##\nsudo ufw status<\/pre><p>Alternatively, here are the steps to stop and disable the firewall on firewalld:<\/p><ol class=\"wp-block-list\">\n<li>Stop the firewalld using the following command.<\/li>\n<\/ol><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo systemctl stop firewalld<\/pre><ol class=\"wp-block-list\" start=\"2\">\n<li>Disable the firewalld at boot time by using this command.<\/li>\n<\/ol><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo systemctl disable firewalld\nsudo systemctl mask --now firewalld<\/pre><ol class=\"wp-block-list\" start=\"3\">\n<li>Simply enter this command to verify if the firewalld has been disabled.<\/li>\n<\/ol><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo systemctl status firewalld<\/pre><ol class=\"wp-block-list\" start=\"4\">\n<li>Run the following commands to enable firewalld again.<\/li>\n<\/ol><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo systemctl unmask --now firewalld\nsudo systemctl enable firewalld\nsudo systemctl start firewalld\n## verify that the firewalld started ##\nsudo firewall-cmd --state<\/pre><h3 class=\"wp-block-heading\" id=\"h-2-flush-your-dns\">2. Flush your DNS<\/h3><p>The DNS cache stores data from websites you visit, so these web pages will load quicker the next time you access them.<\/p><p>However, if the <a href=\"\/ca\/tutorials\/what-is-dns\">DNS<\/a> contains too many records, it might fail to function.<\/p><p>To solve this, <a href=\"\/ca\/tutorials\/how-to-flush-dns\" target=\"_blank\" rel=\"noreferrer noopener\">flush the DNS<\/a> to erase the records:<\/p><ol class=\"wp-block-list\">\n<li>Open the command prompt by typing <strong>cmd<\/strong> on the search bar next to the start menu.<\/li>\n\n\n\n<li>Enter this command:<\/li>\n<\/ol><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ipconfig \/flushdns<\/pre><ol class=\"wp-block-list\" start=\"3\">\n<li>Check whether the 127.0 0.1 refused to connect issue has disappeared or not.<\/li>\n<\/ol><h3 class=\"wp-block-heading\" id=\"h-3-connect-with-specified-port\">3. Connect with specified port<\/h3><p>The default port number for the web server is <strong>80<\/strong>. If you&rsquo;re trying to access it by typing <strong>localhost<\/strong> in your browser &ndash; which will direct to <strong>localhost:80<\/strong> &ndash; but it turns out your <a href=\"\/ca\/tutorials\/what-is-a-web-server\">web server<\/a> is not configured to use the default port, you&rsquo;ll get the localhost error or 127.0 0.1 refused to connect message.<\/p><p>However, port 80 may sometimes be used by another application on your computer. For example, if Skype is currently using it, you wouldn&rsquo;t be able to run the <a href=\"\/ca\/tutorials\/what-is-apache\">Apache server<\/a> on the same port simultaneously.<\/p><p>To solve this problem, first, let&rsquo;s check whether port 80 is free. We&rsquo;re going to use XAMPP to do this.<\/p><p><a href=\"\/ca\/tutorials\/how-to-use-xampp-wordpress\/\">XAMPP<\/a> is a web server solution stack used to build websites offline on a local web server. It&rsquo;s a cross-platform tool, so it works on Windows, Mac, and Linux. It&rsquo;s commonly used to install WordPress on a local computer.  <\/p><p>Here are the steps to check free port number on Windows and Linux &ndash; it will be <a href=\"https:\/\/www.apachefriends.org\/faq_osx.html\" target=\"_blank\" rel=\"noreferrer noopener\">slightly different on Mac<\/a>.<\/p><ol class=\"wp-block-list\">\n<li>Click the <strong>Start Menu<\/strong> to start XAMPP.<\/li>\n\n\n\n<li>Click the <strong>Netstat<\/strong> button on the right side of the control panel.<\/li>\n<\/ol><figure class=\"wp-block-image size-full is-style-default\"><a href=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/11\/xampp-control-panel-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1999\" height=\"1304\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/11\/xampp-control-panel-1.png\" alt=\"Selecting the Netstat button in the XAMPP Control Panel to see all used ports\" class=\"wp-image-40316\"  sizes=\"auto, (max-width: 1999px) 100vw, 1999px\" \/><\/a><\/figure><ol class=\"wp-block-list\" start=\"3\">\n<li>You&rsquo;ll see all the used ports on your computer. Check whether port 80 is free or used by another application.<\/li>\n<\/ol><div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter size-full\"><a href=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/11\/netstat-used-ports.png\"><img loading=\"lazy\" decoding=\"async\" width=\"829\" height=\"683\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/11\/netstat-used-ports.png\" alt=\"List of used ports in Netstat\" class=\"wp-image-40317\"  sizes=\"auto, (max-width: 829px) 100vw, 829px\" \/><\/a><\/figure><\/div><ol class=\"wp-block-list\" start=\"4\">\n<li>If port 80 is already used by another application, choose a free port number, for example port 8080.<\/li>\n<\/ol><p>Next, let&rsquo;s proceed to connect with the correct port number using the <strong>listen<\/strong> command.<\/p><p>The listen command is required to instruct Apache HTTPd to listen to only specific IP addresses or ports. If this command is not present in the <strong>config<\/strong> file, your server will fail to start.<\/p><p>Here are the steps to change Apache&rsquo;s port in XAMPP:<\/p><ol class=\"wp-block-list\">\n<li>Click the <strong>Start Menu<\/strong> to start XAMPP.<\/li>\n\n\n\n<li>You&rsquo;ll see the XAMPP icon in your taskbar&rsquo;s system tray. Double-click it.<\/li>\n\n\n\n<li>The XAMPP control panel window will appear. It will show a list of all currently running services.<\/li>\n\n\n\n<li>Click on the <strong>Stop<\/strong> button next to <strong>Apache<\/strong>.<\/li>\n<\/ol><div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter size-full\"><a href=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/11\/stop-apache-xampp-control-panel.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1999\" height=\"1311\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/11\/stop-apache-xampp-control-panel.png\" alt=\"Stopping Apache from XAMPP Control Panel\" class=\"wp-image-40319\"  sizes=\"auto, (max-width: 1999px) 100vw, 1999px\" \/><\/a><\/figure><\/div><ol class=\"wp-block-list\" start=\"5\">\n<li>Open the file explorer, then find the <strong>httpd.conf<\/strong> file in the config folder. If you use Windows, it will be in the <strong>C:xamppapacheconf <\/strong>directory. If you use Linux, it will be in <strong>bin\/apache<\/strong>. On Mac, the path will be <strong>Applications\/XAMPP\/xamppfiles\/etc\/httpd.conf<\/strong>.<\/li>\n\n\n\n<li>Open it using <strong>Notepad<\/strong> or any other text editor available. Then, look for these lines inside the file:<\/li>\n<\/ol><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Listen 80\nServerName localhost:80<\/pre><ol class=\"wp-block-list\" start=\"7\">\n<li>If your port 80 is free, just make sure that the port number in the Listen command matches the port number for the localhost. If another application is using port 80, replace it with an available port number. In this example, we&rsquo;ll change it to port <strong>8080<\/strong>.<\/li>\n<\/ol><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Listen 8080\nServerName localhost:8080<\/pre><ol class=\"wp-block-list\" start=\"8\">\n<li>Save the file. It will ask for administrative privileges, choose <strong>Yes<\/strong>.<\/li>\n\n\n\n<li>Open the XAMPP control panel again, then start the Apache web server.<\/li>\n\n\n\n<li>Access <strong>http:\/\/localhost:8080 <\/strong>or <strong>https:\/\/127.0.0.1:8080\/<\/strong> to check whether the localhost is working.<\/li>\n<\/ol><p>If you&rsquo;re using <a href=\"\/ca\/tutorials\/what-is-wamp\" target=\"_blank\" rel=\"noreferrer noopener\">WAMP<\/a> &ndash; a solution stack for the Windows operating system &ndash; do the following steps to change the running port.<\/p><ol class=\"wp-block-list\">\n<li>Right-click the taskbar and select <strong>Task Manager<\/strong>.<\/li>\n\n\n\n<li>Click <strong>End Task<\/strong> for any instances of WAMP that are still running.<\/li>\n\n\n\n<li>Next, open file explorer and navigate to the config folder in <strong>C:wampapache2conf<\/strong>.<\/li>\n\n\n\n<li>Look for the <strong>HTTPD config file<\/strong>. Open it with a text editor like Notepad.<\/li>\n\n\n\n<li>Look for these lines inside the file:<\/li>\n<\/ol><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Listen 80\nServerName localhost:80<\/pre><ol class=\"wp-block-list\" start=\"6\">\n<li>If your port 80 is free, just make sure that the port number in the listen command matches the port number for the localhost. If port 80 is already used by another application, replace the number with an available port.<\/li>\n<\/ol><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Listen 8080\nServerName localhost:8080<\/pre><ol class=\"wp-block-list\" start=\"7\">\n<li>Save the file.<\/li>\n\n\n\n<li>Open WAMP again to see if you still get the same error.<\/li>\n<\/ol><h3 class=\"wp-block-heading\" id=\"h-4-ensure-apache-is-running\">4. Ensure Apache is running<\/h3><p>If your Apache web server is not running, you won&rsquo;t be able to access localhost.<\/p><p>To check the status of your Apache, the command will vary depending on the distribution that you use.<\/p><p>Here&rsquo;s the command for Debian or Ubuntu:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ sudo systemctl status apache2<\/pre><p>And here&rsquo;s the command for CentOS\/RHEL\/Fedora:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># systemctl status httpd<\/pre><p>The result from this status check will tell whether your server is running or stopped.<\/p><p>If it tells you that the server is stopped, try to troubleshoot by restarting it using the following command.<\/p><p>For Debian and Ubuntu:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo systemctl restart apache2<\/pre><p>For CentOS\/RHEL\/Fedora:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># systemctl restart httpd<\/pre><p>The output of the restart command will look like this:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">* Restarting web server apache2  [ OK ]<\/pre><p>If the restart attempt fails, you&rsquo;ll get an error message. The message may vary depending on your choice of distribution, but it will fall along these lines:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">apache2: unrecognized service<\/pre><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Failed to restart apache2.service: Unit apache.service failed to load: No such file or directory.<\/pre><p>If you see these error messages, try to reinstall the service. Once you&rsquo;re sure the web server is installed correctly, restart it using the corresponding command.<\/p><h3 class=\"wp-block-heading\" id=\"h-5-go-through-browser-settings\">5. Go through browser settings<\/h3><p>Your browser settings can also cause the 127.0 0.1 &ldquo;refused to connect&rdquo; error because every web browser has a different setup and characteristics.<\/p><p>For instance, when you enter an HTTP web address, some browsers automatically redirect you to its HTTPS equivalent. However, if that site has an invalid SSL certificate or doesn&rsquo;t have any, you&rsquo;ll get the <strong>localhost refused to connect<\/strong> error message.<\/p><p>If you&rsquo;re using Chrome browser, follow these steps:<\/p><ol class=\"wp-block-list\">\n<li>Enter <strong>chrome:\/\/net-internals\/#hsts<\/strong> on your browser&rsquo;s address bar.<\/li>\n<\/ol><div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter size-full\"><a href=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/11\/chrome-hsts.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"247\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/11\/chrome-hsts.png\" alt=\"Chrome's HSTS settings.\" class=\"wp-image-40320\"  sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div><ol class=\"wp-block-list\" start=\"2\">\n<li>Locate <strong>Delete domain security policies<\/strong>, then type <strong>localhost<\/strong>.<\/li>\n<\/ol><figure class=\"wp-block-image size-full is-style-default\"><a href=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/11\/delete-domain-security-policies.png\"><img loading=\"lazy\" decoding=\"async\" width=\"889\" height=\"117\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/11\/delete-domain-security-policies.png\" alt=\"Deleting domain security policies in localhost.\" class=\"wp-image-40321\"  sizes=\"auto, (max-width: 889px) 100vw, 889px\" \/><\/a><\/figure><ol class=\"wp-block-list\" start=\"3\">\n<li>Restart the browser.<\/li>\n<\/ol><h2 class=\"wp-block-heading\" id=\"h-difference-between-err-connection-refused-and-err-connection-timeout\"><strong>Difference between &ldquo;ERR_CONNECTION_REFUSED&rdquo; and &ldquo;ERR_CONNECTION_TIMEOUT<\/strong>&ldquo;<\/h2><p>When trying to access localhost, you may encounter two potential errors &ndash; <strong>ERR_CONNECTION_REFUSED<\/strong> and<strong> ERR_CONNECTION_TIMEOUT<\/strong>. Both are closely related but require different solutions.<\/p><p>&ldquo;ERR_CONNECTION_REFUSED&rdquo; localhost error indicates that the server rejected the attempted connection, while &ldquo;ERR_CONNECTION_TIMEOUT&rdquo; indicates that nothing happened and the client is still waiting for a response.<\/p><p>Therefore, to solve &ldquo;ERR_CONNECTION_REFUSED&rdquo; localhost issue, you need to check the firewall since it&rsquo;s what rejects the data packets. You&rsquo;ll also need to look at the <strong>Listen<\/strong> directive in the <strong>httpd.conf<\/strong> file and make sure it&rsquo;s correctly set.<\/p><p>Meanwhile, to <a href=\"\/ca\/tutorials\/fix-err_connection_timed_out\">solve &ldquo;ERR_CONNECTION_TIMEOUT&rdquo; on Chrome<\/a>, you&rsquo;ll need to look at your connection settings because this error means the service is not running as it should or is not correctly installed.<\/p><h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2><p>&ldquo;Localhost refused to connect&rdquo; is a network connection error you might encounter when working on a project on your local web server.<\/p><p>It is triggered if the firewall blocks your server or you use the wrong port. The localhost error can also happen if your Apache web server or Chrome browser is not configured correctly.<\/p><p>There are five methods to solve the &ldquo;localhost refused to connect&rdquo; error:<\/p><ul class=\"wp-block-list\">\n<li><strong>Temporarily disable your firewall<\/strong> &ndash; Turn the firewall off so it won&rsquo;t flag the project on your localhost as malicious and block its access.<\/li>\n\n\n\n<li><strong>Flush DNS <\/strong>&ndash; Clear existing browser data.<\/li>\n\n\n\n<li><strong>Connect with specified port<\/strong> &ndash; Check if the running port of the Apache web server is port 80 or a particular port number specified for localhost.<\/li>\n\n\n\n<li><strong>Ensure Apache is running<\/strong> &ndash; Ensure the Apache web server is installed correctly too.<\/li>\n\n\n\n<li><strong>Go through browser settings<\/strong> &ndash; Enable connections to sites without SSL certificate, like your test site.<\/li>\n<\/ul><p>We hope this article helps you solve the &ldquo;localhost refused to connect&rdquo; error.<\/p><h2 class=\"wp-block-heading\" id=\"h-localhost-refused-to-connect-faqs\">&ldquo;Localhost Refused to Connect&rdquo; FAQs<\/h2><div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1682682223630\"><h3 class=\"schema-faq-question\">What is an alternative to localhost?<\/h3> <p class=\"schema-faq-answer\">One alternative to using<strong> localhost <\/strong>for local development is to use your computer&rsquo;s IP address as the host. You can find your IP address in your system preferences or by typing <strong>ipconfig<\/strong> in the <strong>Command prompt <\/strong>for Windows or <strong>ifconfig<\/strong> in the <strong>Terminal <\/strong>for Mac or Linux.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1682682232830\"><h3 class=\"schema-faq-question\">What is a localhost IP Address?<\/h3> <p class=\"schema-faq-answer\">A localhost IP address refers to the computer that the user is currently using. It is the IP address of the loopback network interface, which is typically assigned the IP address <strong>127.0.0.1<\/strong>. Users use this IP address to access the computer&rsquo;s own network services without connecting to an external network.<\/p> <\/div> <\/div>\n","protected":false},"excerpt":{"rendered":"<p>Among the different network connection errors you might encounter is &ldquo;localhost refused to connect&rdquo; or the &ldquo;ERR_Connection_Refused&rdquo; error. When you try to connect to an IP address, you usually try to connect to a different computer. However, since localhost uses the loopback address network, connecting to it means you&rsquo;re establishing a connection with your own [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/ca\/tutorials\/how-to-fix-localhost-refused-to-connect-error\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":187,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"Localhost Refused to Connect Error: 5 Confirmed Ways to Fix It","rank_math_description":"Localhost refused to connect error can be caused by an incorrectly configured port, insufficient permissions, or an inoperative web server.","rank_math_focus_keyword":"localhost refused to connect","footnotes":""},"categories":[22658],"tags":[],"class_list":["post-40288","post","type-post","status-publish","format-standard","hentry","category-website-development"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/how-to-fix-localhost-refused-to-connect-error","default":0},{"locale":"fr-FR","link":"https:\/\/www.hostinger.com\/fr\/tutoriels\/localhost-n-autorise-pas-la-connexion","default":0},{"locale":"es-ES","link":"https:\/\/www.hostinger.com\/es\/tutoriales\/que-es-nslookup-7","default":0},{"locale":"id-ID","link":"https:\/\/www.hostinger.com\/id\/tutorial\/cara-mengatasi-localhost-refused-to-connect","default":0},{"locale":"en-UK","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/how-to-fix-localhost-refused-to-connect-error","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/how-to-fix-localhost-refused-to-connect-error","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/how-to-fix-localhost-refused-to-connect-error","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/how-to-fix-localhost-refused-to-connect-error","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/how-to-fix-localhost-refused-to-connect-error","default":0},{"locale":"es-AR","link":"https:\/\/www.hostinger.com\/ar\/tutoriales\/que-es-nslookup-7","default":0},{"locale":"es-MX","link":"https:\/\/www.hostinger.com\/mx\/tutoriales\/que-es-nslookup-7","default":0},{"locale":"es-CO","link":"https:\/\/www.hostinger.com\/co\/tutoriales\/que-es-nslookup-7","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/how-to-fix-localhost-refused-to-connect-error","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/how-to-fix-localhost-refused-to-connect-error","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/posts\/40288","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/users\/187"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/comments?post=40288"}],"version-history":[{"count":34,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/posts\/40288\/revisions"}],"predecessor-version":[{"id":142061,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/posts\/40288\/revisions\/142061"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/media?parent=40288"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/categories?post=40288"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/tags?post=40288"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}