Install Apache in FreeBSD

Installing and configuring the Apache 2.2.x web server in FreeBSD.
Install
To begin the Apache installation process, log in like the superuser and enter the following commands:
cd /usr/ports/www/apache22 make install clean
A menu should appear to show options for Apache. Here you may leave default options, but If you need to build and install Apache with special modules then you have to choose them now. For example if you want your Apache to support the working with MySQL databases then you need to select it in the menu by pressing 'space'. After choosing needed options you can start to install Apache by pressing 'tab' and 'enter'.
Configure
We are going to configure Apache to start automatically at boot time. To do so, edit the /etc/rc.conf file and add the following line to the end of file:
apache22_enable="YES"
After this we will make base configuration which is enough to run Apache. Open the file /usr/local/etc/apache22/httpd.conf. In this file you need to find and set values for two options:
ServerAdmin admin@example.com ServerName host.example.com:80
Where options:
- ServerAdmin is email address of the person who will be maintaining the server.
- ServerName is hostname of your server
If you don't have hostname which pointed to server's IP then you may set any hostname, but then you will need to set this hostname and IP in your local PC which you use for browsing current server.
You need to add following line to file:
- for Windows C:\WINDOWS\system32\drivers\etc\hosts
- for Linux /etc/hosts
192.168.0.100 host.example.com
Where 192.168.0.100 is IP for your server where you are installing Apache.
After you completed configuring Apache you can check your config file for syntax errors by running this command:
/usr/local/etc/rc.d/apache22 configtest
If it returns "Syntax OK", continue below. If it finds a problem, it will list the filename, line number, and possible reasons for the error. Be sure to resolve any issues prior to continuing below.
After these you can run Apache by command:
/usr/local/etc/rc.d/apache22 start
Now you can open any browser and check how it works. For this example "host.example.com".
Log files
- /var/log/httpd-access.log contains a log of IP addresses, times, and activity on the HTTP server
- /var/log/httpd-error.log contains a log of error messages produced by the HTTP server