# Hosting on FreeBSD



## selhan (Apr 19, 2014)

Hello,
I bought a domain name, and I have FreeBSD 10 running in one server. Can anyone provide me any tutorial  on how to setup this server to be the hosting of my website? Is that possible?

Thank you!


----------



## asteriskRoss (Apr 19, 2014)

The FreeBSD handbook has a good starting page on setting up the Apache web server, though you could choose another web server such as www/lighttpd, www/aws, www/abyssws, www/fnord, www/microhttpd, www/hydra, www/jetty, www/cherokee or www/yaws (there are others).  Once your web server is up and running you will need to configure the DNS records for your domain to point to the server.  Your domain name provider likely offers a web application to allow you to configure this.


----------



## selhan (Apr 20, 2014)

Hi asteriskRoss,

Thanks for your reply,

As Apache is one of the most popular, then I installed Apache24 and PHP55, a page is displaying "It works!" when I browse for my local IP on the server: http://192.168.x.x.
I created a DNS record, pointing to my IPS IP.
I also created a port forwarding from my router to the static IP on my server (just in case).

Now, where do I have to configure to make my "domain.com" works instead my local server IP?

Thank you very much for your time!


----------



## SirDice (Apr 20, 2014)

selhan said:
			
		

> Now, where do I have to configure to make my "domain.com" works instead my local server IP?


Edit your domain and point the IP address to yours. Then configure Apache correctly. There are thousands of instructions to be found on setting up Apache. Setting up Apache on FreeBSD is no different from setting it up on Linux, Solaris or even Windows.


----------



## selhan (Apr 20, 2014)

Well that’s fine for me, I can do that, no matter how much instructions I have to see, but could you please confirm me which one of this configuration’s  file do I need to edit:
/usr/local/etc/apache24/httpd.conf? And/or /etc/host.conf? And/or /etc/hosts?

 Also if there something else (not mentioned above) that I need to edit.

Thank you for your patience, I appreciate that!


----------



## asteriskRoss (Apr 21, 2014)

Hi @selhan, congratulations on getting www/apache24 up and running on your FreeBSD system.  Did you find the Apache HTTP server documentation?  Your Apache configuration file can be found at /usr/local/etc/apache24/httpd.conf; this is what you need to edit to configure Apache.

If you want someone elsewhere on the Internet to be able to type "www.yourdomain.com" into their browser's address bar and reach your website, then you need to change the Domain Name System (DNS) records for your domain.  This isn't a setting on your system, but a setting on the DNS server for your domain.  The DNS server is likely owned and controlled by the company from whom you bought your domain name.  That company should have instructions on how to configure the DNS records on their server.  If you tell us which domain registrar you used, we may be able to point you to right place on their website.  You need to set up an "A" record that points "www.yourdomain.com" to the public IP address of your server.

In your post you mentioned that you had set up NAT port forwarding from your external router to your server's internal IP address, which you gave as being in the 192.168.0.0/16 private address range.  The IP address you enter as the record must be the public IP address of your external router (not something that looks like 192.168.x.x).  This address must also be static (that is, not changing) if you want people to continue to access your website.  You will likely know whether you have a static public IP address for your router.  Particularly for home broadband connections, most Internet Service Providers (ISP) provide dynamic IP addresses.  It is still possible, but more fiddly, to host a website on a dynamic public IP address using a Dynamic DNS service provided by a company like DynIP.com (a web search for "dynamic dns" will show many alternative companies).


----------



## selhan (Apr 21, 2014)

@asteriskRoss, 
Thanks for the valuable time you've devoted to me, your answer have cleared my mind, I just want you to confirm me if what I've done so far, is right.
As you asked, my domain's registrar is from godaddy.com, I created an "A" record from my domain.com to point to my public IP (my public IP is my ISP address, which is static). I also want to mention that my default Nameservers from godaddy are: NS29.domaincontrol.com and NS30.domaincontrol.com, should I change this to NS1.mydomain.com and NS2.mydomain.com?

Please, also confirm to me if this is ok, I have changed on /usr/local/etc/apache24/httpd.conf these lines:

```
Listen My-public-IP:80
ServerAdmin my-email
ServerName my-domain.com
AddType application/x-httpd-php .php
AddType application/x-httpd-source .php
DirectoryIndex index.php index.html <-- I added index.php to this line
```

Now I got this error when I start Apache:


```
Starting apache24.
(49)Can't assign requested address: AH00072: make_sock: could not bind to address MyPublicIP:80 <-- Please note: I replace my IP for the word MyPublicIP
no listening sockets available, shutting down
AH00015: Unable to open logs
/usr/local/etc/rc.d/apache24: WARNING: failed to start apache24
```

Thank you very much for your time!


----------



## asteriskRoss (Apr 22, 2014)

Glad to hear you're making progress.  I suggest that for the moment, you should leave the name server settings as they are.  If you prefer later on you could run your own DNS server as you are running your own web server, but that's a whole different adventure.  You've also already paid for GoDaddy to provide DNS services as part of your domain name purchase.

The Apache error you're receiving relates to the IP address you have configured with the Listen directive in /usr/local/etc/apache24/httpd.conf.  The IP address you have asked Apache to listen on isn't assigned to your server at all -- it's assigned to your router's external network interface.  Change the IP address here to the server's IP address, which you indicated was 192.168.something.something.  You mentioned you already configured port forwarding on your router, so through the magic of Network Address Translation (NAT), your router will make sure that traffic flows to and from your web server.

Once you're into Apache configuration, rather than FreeBSD configuration, you may find Apache's user support useful; as @SirDice said it doesn't matter which operating system you're running as configuring Apache is the same for all operating systems.


----------

