How To Change The Apache Port In XAMPP?

Published September 12, 2024

Problem: Changing Apache Port in XAMPP

XAMPP uses port 80 for Apache by default. This can cause conflicts with other apps or services. You might need to change this port to fix conflicts or meet server setup needs.

How to change the Apache port in XAMPP?

Step 1: Locate the configuration file

To change the Apache port in XAMPP, find the httpd.conf file. On Windows, it's usually in C:\xampp\apache\conf. For Linux users, check the bin/apache directory.

Step 2: Edit the httpd.conf file

Open httpd.conf with a text editor. Find the "Listen" directive, which sets the port number. Change it to your desired port, like this:

Listen 8012

Tip: Choose an Available Port

When selecting a new port for Apache, make sure it's not already in use by another application. You can check for available ports using the command prompt or terminal. On Windows, use the command 'netstat -an' to list all active ports.

Step 3: Update ServerName directive

Find the ServerName directive in the same file. Update its port to match the new Listen port:

ServerName localhost:8012

Step 4: Save changes and restart Apache

Save the edited httpd.conf file. Then, restart the Apache service using the XAMPP control panel to apply the changes.

Verifying the port change

After changing the Apache port in XAMPP, verify that the change was successful:

Check the XAMPP control panel for the new port number:

  1. Open the XAMPP control panel
  2. Look at the Apache module
  3. The new port number should appear next to the Apache service

Access localhost using the new port in your web browser:

  1. Open your web browser
  2. Enter the following URL:
http://localhost:8012

Replace "8012" with your new port number. If Apache is running on the new port, you'll see the XAMPP welcome page or your website's homepage.

If you can't access the page:

  1. Check your configuration file for typos or errors
  2. Make sure Apache is running in the XAMPP control panel
  3. If problems continue, review the Apache error logs for more information

Tip: Check for port conflicts

Use the command prompt to check if the new port is already in use by another application. Open the command prompt and type:

netstat -ano | findstr :8012

Replace "8012" with your new port number. If the command returns results, it means the port is already in use, and you should choose a different port for Apache.