Install apache, php5, and mysql on FreeBSD 7.2 using ports

Last Updated on Sunday, 19 August 2012 12:26 Written by Admin Wednesday, 20 August 2008 18:11


Apache web server one of the most widely used. Apache can also be installed on freebsd. following way to install apache, PHP5, mysql the most easy to use ports.

1. Install Apache:

# cd /usr/ports/www/apache22
# make install clean

to start just type

# /usr/local/sbin/apachectl start

to enable apache on boot add apache22_enable="YES" following file /etc/rc.conf

check apache on your browser type localhost

2. Install PHP 5

# /usr/ports/lang/php5
# make install clean

make sure to build Apache module is checked

add these option on file /usr/local/etc/apache22/httpd.conf

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

Add Index.php to load auto index

    DirectoryIndex index.html index.php

create file php.ini by copy php.ini-dist

# cd /usr/local/etc/
# cp php.ini-dist php.ini

and then restart apache

# /usr/local/sbin/apachectl restart

create file php on /usr/local/www/apache22/data/

save as test.php

now test on your browser

Install Mysql 5

# cd /usr/ports/databases/mysql51-server
# make install clean

create database

# /usr/local/bin/mysql_install_db

change owner and group as mysql

# chown -R mysql /var/db/mysql/
# chgrp -R mysql /var/db/mysql/

run mysql daemon

/usr/local/bin/mysqld_safe user=mysql &;

change mysql password

/usr/local/bin/mysqladmin -u root password newpass

to automatic msyql enable when boot add /etc/rc.conf:


Install php5-mysql module

cd /usr/ports/databases/php5-mysql
make install clean

create file php to check mysql

    print "cant connect";                                            
    print "connected";                                               

save as test-db.php on /usr/local/www/apache22/data/ and go to your browser http://localhost/test-db.php