0

So basically I'm having issues creating a subdomain on my server. I'm running apache2 on a Ubuntu 12.04 server and have dynamic IP set up with No-IP.com.

I have mydomain.com working, but want to create test.mydomain.com directing towards a subfolder in my /var/www/ directory (where everything for my website is located).

I modified the code on apache vhosts examples page and put this in my httpd.conf file:

# Ensure that Apache listens on port 80
Listen 80

# Listen for virtual host requests on all IP addresses
NameVirtualHost localhost:80

<VirtualHost localhost:80>
DocumentRoot /var/www/
ServerName mydomain.com

# Other directives here

</VirtualHost>

<VirtualHost localhost:80>
DocumentRoot /var/www/test
ServerName test.mydomain.com

# Other directives here

</VirtualHost>

When I try and restart the service:

sudo /etc/init.d/apache2 restart

 * Restarting web server apache2                                                                                                                                                                            apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
Action 'start' failed.
The Apache error log may have more information.

Any help is greatly appreciated. Please let me know if I'm forgetting to include any necessary information.

Update I tried using *:80 but I still got an error, that's why I switched to localhost.

sudo /etc/init.d/apache2 restart
 * Restarting web server apache2                                                                                                                                                                            apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[Thu Nov 21 15:03:51 2013] [warn] NameVirtualHost *:80 has no VirtualHosts
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[Thu Nov 21 15:03:51 2013] [warn] NameVirtualHost *:80 has no VirtualHosts
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
Action 'start' failed.
The Apache error log may have more information.

UPDATE I figured out what was going on. I had a matching configuration entry in my ports.conf file. Once I removed that, everything worked fine.

Gino
  • 13
  • 11

2 Answers2

0

Your apache conf seems correct if you replace localhost with *. That means that you should use NameVirtualHost *:80 and <VirtualHost *:80>

However, you must tell the DNS server to forward subdomains to your dynamic IP. Since you have a .com domain from a paid DNS service, you must login to your DNS provider and setup A records or CNAME records to your IP (add the same settings you have in your main .com domain). If you use the a ddclient or similar client to automatically update the domains, you can configure it to update the subdomain as well.

In any case, use command nslookup yourdomain.com and nslookup subdomain.domain.com to see if the subdomain is updated successfully. Note that updates in DNS may take hours before they are actually in effect.

EDIT:

Sorry just noticed : (98)Address already in use: make_sock: could not bind to address 0.0.0.0:80. This means that somebody else is already using port 80, so the apache server cannot bind to that address. Use sudo netstat -anltp | grep :80 to see which program has bound port 80. Also, check your conf files to make sure that you have no more NameVirtualHost *:80 directives.

Last, apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName is not an error, it's just a warning so you shouldn't be worried about this

foibs
  • 3,258
  • 1
  • 19
  • 13
0

Possible that there a service using port :80 Try netstat -tulpn |grep :80 on command line to see which service is occupying this port. In my case, it was nginx. I stopped the service then started the one I wanted to use (apache2).