Question: How do I change Apache 2 default port under Debian / Ubuntu Linux? I've couple of public IPv4 address assigned by my ISP, how do I force Apache2 to listen to a specific IP address? How do I change Apache2 IP address binding?
Answer: You can easily change the port and other settings using following directives:
Apache Listen Directive
The Listen directive instructs Apache to listen to more than one IP address or port; by default it responds to requests on all IP interfaces, but only on the port given by the Port directive. You can use this directive multiple times.
Task: Change Apache port
Open /etc/apache2/ports.conf file, enter:
# vi /etc/apache2/ports.conf
OR
$ sudo vi /etc/apache2/ports.conf
To make the server accept connections on both port 8010, enter:
Listen 8010
To make the server accept connections on both port 80 and port 8010, use:
Listen 80
Listen 8010
Task: Accept connections on specific IP / interface port
You need to use network interfaces IP address. For example, to make the server accept connections on IP 202.54.1.2 and port 80, enter:
Listen 202.54.1.2:80
To make the server accept connections on two specified interfaces and port numbers, enter:
Listen 202.54.2.1:80
Listen 202.54.2.5:8010
Save and close the file. Restart Apache 2 webserver:
# /etc/init.d/apache2 restart
OR
$ sudo /etc/init.d/apache2 restart
How do I verify port and IP binding working ?
Use netstat command to find out if Apache is listening on a specific port or not, use:
# netstat -tulpn
# netstat -tulpn | grep :80
# netstat -tulpn | grep :8010
# netstat -tulpn| grep 202.54.1.2:80
Sample output:
tcp 0 0 202.54.1.2:80 0.0.0.0:* LISTEN 19306/apache2
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop








![Apache: [warn] _default_ VirtualHost overlap on port 80, the first has precedence Error and Solution](http://s13.cyberciti.org/images/shared/rp/3/14.jpg)





{ 12 comments… read them below or add one }
Great Post.
Simple and easy to understand.
But I was wondering how I could server multiple IPs,Ports.
How would the Virtual Hosts file look like?
Is it enough to change the
NameVirtualHost ?
cheers,
http://www.felipeferreira.net
Plz , i change port apache ia 81 but in address on browser my type is
localhst:81 or 127.0.0.1:81 not search foulder content php www
i edit port is 80 is ok
why ?? plz
I’m with the same problem…
my Apache server was not running but when i close all my start up programs like skype and utorrent then it work and apache server running.
start up programs sometimes use the port of apache!
They apparently forgot to say to change the following also:
sudo nano /etc/apache2/ports.conf
In file ports.conf, line 8.
Find:
NameVirtualHost *:80
Change to:
NameVirtualHost *:8080
And!
sudo nano /etc/apache2/sites-available/default
In file default, line 1.
Find:
Change to:
Eventually restart your apache2 server ;)
sudo /etc/init.d/apache2 restart
Good luck!
Kind regards,
Melroy van den Berg
oh thanks that helped alot
Using specific ip and port but getting:
===============
no listening sockets available, shutting down
Unable to open logs
Action ‘start’ failed.
The Apache error log may have more information.
failed!
==============
what is the difference between the port 80 and 8080?
Hi guys,
Like always, brilliant, simple and easy!!!
Thanks,
Luis
Something important!!!!
If you just change the port or add more ports here, you will likely also
have to change the VirtualHost statement in
/etc/apache2/sites-enabled/000-default
Regards
Hi.
I get the following error:
(99)Cannot assign requested address: make_sock: could not bind to address **.***.**.***:80
what can I do?
Hi Guys,
Thank you very much for all the information and the comments.