Wednesday, December 28, 2011

Configuring Apache in FreeBSD (using localhost)

I had a pretty tough time configuring and starting Apache 2.2 in my FreeBSD. Now that I have configured it properly, I wanna share the procedure with you guys.

Here's the procedure (Be patient. Look for typos if things don't work.)


A. Install apache22 package

Apache 2.2 can be installed from FreeBSD ports.

1. Use the following commands to get the FreeBSD ports:

#portsnap fetch
#portsnap extract
#portsnap update

2. Use the following commands to install apache

#cd /usr/ports/www/apache22

#make install



(If there is any kind of problem with the installation try the following command:

#make NO_CHECKSUM="yes"

)

B. Configure the files

1. You need to edit /etc/rc.conf so that apache22 gets started whenever the machine is turned on. You can do this by using the following commands:


 #vi /etc/rc.conf


Add the following line to the file:

apache22_enable="YES"

Then save and quit.

2. Now you need to configure /usr/local/etc/apache22/httpd.conf file. Again, use the following commands:



 #vi /usr/local/etc/apache22/httpd.conf

Change the existing line starting with ServerName with the following line:

ServerName 127.0.0.1:80

Save and Quit.

3. Next, we need to define a host.

#vi /etc/hosts

Now comment the following two lines by inserting # before each line:

::1 localhost localhost.my.domain
127.0.0.1 localhost localhost.my.domain


After that, add the following lines:

::1 myname.my.domain myname

127.0.0.1 myname.my.domain myname



4. Next step is to define the host in /etc/rc.conf

#vi /etc/rc.conf

Add the following line:

hostname="myname"

Save and quit.

C. Final Steps:

1. Turn off the machine and turn it on again. This will allow the changes made in /etc/rc.conf to work.

2. Open a browser in your host Windows or Linux or any other virtual machine.

Type in

http://IP_ADDRESS:80

(where, IP_ADDRESS is the IP address the FreeBSD which you just configured).

If the server is running you should see a message which states something like: you have been denied access to the page. This means that the server is running.


But you still have to change permission settings to view the pages. I am feeling really sleepy at this point. Leave a comment if you want to learn how to change permissions and tweak other things.


Important!!: If it does not work then try the following command in FreeBSD to check if apache is running or not:

#/usr/local/etc/rc.d/apache22 status

If it is not running then well then bad luck.. Try google!






All the best!



No comments:

Post a Comment