Hi! I'm going to show you how to change the apache and mysql port number in xampp localhost. In case you wonder why you should change the port number of a web server, here is the answer. It's not unlikely for you to run multiple PHP versions on a same machine or to run IIS or JBoss simultaneously with Apache.
When you start a web server, it occupies the default HTTP port '80'. If you try to run the second one, it will fail since the port is already occupied. So unless you change the port for the latter, you can't run more than one web server at once. Below we will see the ways to change the port no. for apache and mysql.
To Change Apache Port Number:
Stop Apache server and exit XAMPP control panel if it is already running.
First you must change the HTTP port.
Go to [path-to-xampp-folder]/apache/conf folder and open http.conf file.
The default port for Apache is '80'. Unless you have changed it, this is the port number you must replace.
Now look for the line,
Listen 80
And then change the port no. to some unused port like this,
Listen 8012
Then search for the line,
ServerName localhost:80
And replace '80' with the new port no like this,
ServerName localhost:8012
Save the file.
Next you must change the SSL port.
Open [path-to-xampp-folder]/apache/conf/extra/httpd-ssl.conf file and search for the lines,
Listen 443
<VirtualHost _default_:443>
ServerName localhost:433
Replace '443' port with something else,
Listen 444
<VirtualHost _default_:444>
ServerName localhost:444
Save the file.
Done! Now restart Apache and access the url http://localhost:8012
on browser. If everything goes fine, you will see the xampp home page.
Please remember to use the port number along with local host to access it. This is not required when you leave apache to run on the default port itself.
To Change MySQL Port:
Just like Apache, you can also change the default port used by MySQL Server which is '3306'.
To do this, go to [path-to-xampp-folder]/mysql/bin/ and open the file my.ini.
Locate the line containing '3306' no. and change it to '3310' or something else and save. Please make sure the new port number is not used by any other service.
You can use 'Netstat' to check all used ports on your system.
That's it. You have successfully changed the default port numbers of apache and mysql server on xampp server. The same procedure can be applied for 'WAMP' and 'LAMP' stacks. For LAMP, you can locate the files on 'usr/bin/apache' directory.
Read Also: