freebsd Install apache2 + php5 + mysql

Posted: December 10, 2009 in Freebsd

Install apache, php5, and mysql on FreeBSD using ports

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/apache222

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 http://localhost

Loading the accf_http module

On FreeBSD you must load the accf_module before you can start apache, otherwise you are sure to get an httpready error.

To load the module use kldload

# kldload accf_http

If it loaded successfully then it will not give any errors or output. To have it load on boot add this to your /boot/loader.conf file


Starting Apache

Apache is controlled with apachectl, some examples of its usage are

# apachectl start

# apachectl restart

# apachectl graceful

# apachectl stop

The graceful option has the same result as restart, it just does it in a nice way as opposed to restart forcefully restarting the server.

Before restarting or starting Apache it is best to run the configtest to check for errors in the httpd.conf

# apachectl configtest

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
<IfModule dir_module>

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/

<?php phpinfo();?> save as test.php
now test on your browser
3. 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:


4. 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

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s