Home arrow Guides arrow Build a FreeBSD Web Server
Build a FreeBSD Web Server PDF
Saturday, 20 March 2010

This tutorial explains steps to build a FreeBSD Web Server with Apache, PHP and MySQL.

Step 1. Install FreeBSD
--------------------------------
Download a iso from ftp.freebsd.org of FreeBSD 8.0 i386 or amd64. Amd64 version is for 64 bits installation and it install a 64 bits FreeBSD on Intel or AMD 64 bit hardware. Don't be tricked by name amd64, it works on Intel 64 bits x86 too. In fact what in FreeBSD is amd64 in Linux is x86_64.

Tip: If you motherboard is not very old you can download a USB stick .img image that will install quicker and is more convenient than burning a CD.

After you've downloaded the image and you booted install FreeBSD. Choose "Developer without X.org".


Step 2. CVSUP FreeBSD sources to a newer version
------------------------------------------------------------------------

To do that look at the following tutorial http://www.freebsdonline.com/content/view/460/476/

After you've cvsuped to last stable, compile and install kernel and world as described in previous link tutorial.


Step 3. Install Apache22 from ports
--------------------------------------------------
cd /usr/ports/www/apache22
make install clean


Step 4. Install PHP
--------------------------
cd /usr/ports/lang/php5
make install clean

When you run make install clean a menu will appear. Choose APACHE MODULE, there. If you forget to do that, press Ctrl+C, and then do
make config
(check Apache module)
Then:
make install clean


Step 5. Install mysql server
---------------------------------------

cd /usr/ports/databases/mysql50-server
make install clean


Step 6. Configure FreeBSD to start Apache, PHP and MySQL at boot
---------------------------------------------------------------------------------------------
Edit /etc/rc.conf file and add the following:
apache22_enable="YES"
mysql_enable="YES"



Step 7. Configure Apache to run PHP scripts
--------------------------------------------------------------
Add the following lines to /usr/local/etc/apache22/httpd.conf (to load index.php and support PHP)
(If you already have dir_module section, just add ther index.php)

<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps


Step 8. Test the configuration
------------------------------------------

Do a reboot to make sure Apache and MySQL will start at boot time.
Create  test.php file in /usr/local/www/apache22/data with the following content:

<?php
phpinfo();
?>

Try to load that file accessing your http server using:
http://10.0.0.10/test.php

Where 10.0.0.10 is IP of your web server (replace 10.0.0.10 with your IP).


Step 9. Create an alias for a http resource
----------------------------------------------------------


If you want to install a particular php script and you do not want it installed in your main directory visible using apache to the world you can create an alias from apache:

Create /usr/local/etc/apache22/Includes/aliases.conf file with the following content:

Alias /myproject "/usr/local/www/myproject"
<Directory "/usr/local/www/myproject">
  Options Indexes FollowSymLinks
  RewriteEngine on
  AllowOverride All
  Order allow,deny
  Allow from all
</Directory>


Then create the directory:
mkdir /usr/local/www/myproject

And create index.php in that directory with the following content:
<?php
phpinfo();
?>

Then you will be able to access your project on the server using
http://10.0.0.10/myproject

If you want to install many php modules read this tutorial: PHP Modules For a FreeBSD Web Server.

Tips
-------

To restart apache do:   /usr/local/etc/rc.d/apache22 restart

Last Updated ( Tuesday, 03 May 2011 )
 
< Prev   Next >

Other BSD Systems

OpenBSD

Misc

Solaris

Polls

Best BSD firewall?