Sometimes, you may need to run Apache on a different port because you need to run reverse proxy on port 80. Here’s how to change port number in Apache in Ubuntu. You can also use these steps to change Apache port number in Windows, CentOS and other Linux systems.
How To Change Port Number in Apache in Ubuntu
Here are the steps to change port number in Apache in Ubuntu from 80 to 8080.
1. Open Apache Config File
Open terminal and run the following command to open Apache server configuration file.
$ sudo vi /etc/httpd/conf/httpd.conf
$ sudo vi /etc/apache2/ports.conf
Bonus Read: How to Hide Server Name in Apache Header
2. Change Apache Port Number
You will find the following line binding Apache to port 80
Change it to
Bonus Read : How to Enable ZIP Compression in Apache
3. Open Virtual Host Configuration (for Ubuntu/Debian)
When you change port number in Apache on Ubuntu/Debian systems, you need to also change port number in virtual host configuration file
If you have configured virtual host for your website (e.g www.mysite.com) at /etc/apache2/sites-enabled/mysite.conf then you can open that file instead.
$ sudo vi /etc/apache2/sites-enabled/mysite.conf
Otherwise, open the default virtual host configuration file at
$ sudo vi /etc/apache2/sites-enabled/000-default.conf
You will find the following line
Change it to
In redhat/fedora/centos systems, Apache automatically applies the changes to default virtual host file. If you have setup your own virtual host, then you will have to update port number in it, as described above.
Bonus Read : How to Install mod_evasive in Apache
4. Restart Apache Server
Restart Apache Server to apply changes
$ sudo systemctl restart apache2 #SystemD $ sudo service apache2 restart #SysVInit
Open browser and enter http://your_ip_adress:8080 (e.g http:192.168.1.102:8080). You will see the Apache default page
That’s it! Now Apache will run on a different port, 8080.
That’s it! Now Apache will run on a different port, 8080. By the way, if you want to create charts & dashboards to monitor your business or website, you can try Ubiq. We offer a 14-day free trial.