By Default, Apache runs on port 80 in XAMPP. Sometimes you may need to change this port number for security purposes. In this article, we will look at the steps to change XAMPP Apache server port number.
How to Change XAMPP Apache Server Port
Here are the steps to change XAMPP apache server port. Please make sure that the port number you use is actually free, and there are no other applications running on it. You can use netstat command to find free ports in your system.
1. Update Apache configuration file
Open Apache configuration file located at C:\xampp\apache\conf in Windows or /etc/apache2/httpd.conf in Linux. For linux users, the apache configuration file may also be present at any of the following locations depending on their installation.
/etc/apache2/apache2.conf
/etc/httpd/httpd.conf
/etc/httpd/conf/httpd.conf
Look for the following lines.
Listen 80 ServerName localhost:80
Replace it with your free port number (e.g. 9000)
Listen 9000 ServerName localhost:9000
Save and close the file.
Also read : How to Fix Apache Not Executing PHP Files
2. Edit http-ssl.conf
Similarly, edit http-ssl.conf file located at C:\xampp\apache\conf\extra in Windows or /etc/apache2/mods-available/ssl.conf in Linux. If Linux users are unable to find the ssl configuration file at the mentioned path, then refer to this link to find it on your system
Look for the following lines
Listen 443
<VirtualHost _default_:443>
ServerName localhost:443
Replace 443 with the new port number for ssl (e.g. 9001)
Listen 9001
<VirtualHost _default_:9001>
ServerName localhost:
9001
Also read : How to Uninstall NGINX in CentOS
3. Update XAMPP configuration
We need to also update the above port numbers in XAMPP configuration, so that both XAMPP and Apache are able to communicate over the right port numbers. For this, do the following.
- Open Xampp Control Panel
- Go to Config ► Service and Port Settings ► Apache
- Replace the Main Port and SSL Port values with those chosen (e.g. 9000 and 9001).
- Save Service settings
- Save Configuration of Control Panel
Also read : How to Set UTF-8 Encoding in Tomcat Server
4. Restart Apache Web Server
Restart Apache web server to apply changes.
Now open web browser and go to http://localhost or http://your-domain.com to access it via your new port numbers.
That’s it. In this article, you have seen how to change apache server port number in XAMPP.
Also read : How to Use NGINX try_files
Related posts:
Sreeram has more than 10 years of experience in web development, Python, Linux, SQL and database programming.