FAMP – Installing Apache2.2, MySQL, PHP on FreeBSD-8.1


Pre-Installation Tasks

Before installation of the components, Download the compressed snapshot of the ports collection, using the following command

# portsnap fetch

Now extract the snapshot into /usr/ports using the following command

# portsnap extract

Apache 2.2 – Installation and Configuration

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

Edit the apache configuration file i.e. /usr/local/etc/apache22/httpd.conf and make the following changes


ServerRoot "/usr/local"
ServerAdmin you@your.address
ServerName www.example.com
DocumentRoot "/usr/local/www/apache22/data"
Listen :80

Edit the /etc/hosts file and add the following line:

hostname.domain

eg:

192.168.1.1               host.example.org

Edit the file /boot/loader.conf and Add the following line:

accf_http_load="YES"

Add the following line to /etc/rc.conf

 apache22_enable="YES" 

Test the apache server installation using the following command:

# /usr/local/sbin/apachectl start

MySQL – Installation and Configuration

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

Start MySQL

 # /usr/local/etc/rc.d/mysql-server onestart 

Add the following line to the file  /etc/rc.conf

 mysql_enable="YES" 

Set password for my sql using the following command


# rehash
# mysqladmin -uroot password '<password>'

Configuring mysql

Use the following command

 # cp /usr/local/share/mysql/my-medium.cnf /etc/my.cnf 

Restart mysql using the following commands

# /usr/local/etc/rc.d/mysql-server restart

PHP – Installation and Configuration

Use the following commands to install PHP5 and other supporting packages


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

Check the option ‘Build Apache Module’ as shown in the image and continue
Apache module for PHP

# make clean

Copy the PHP configuration file using the following command

 # cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini 

Edit  /usr/local/etc/apache22/httpd.conf file and add the following lines under  /AddType


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

And add the following line under LoadModule section

LoadModule php5_module        libexec/apache/libphp5.so

Modify the line ‘DirectoryIndex index.html’ to the following

 DirectoryIndex index.php index.html 

Now restart the apache server by using the following command

# /usr/local/sbin/apachectl restart
Advertisements

6 thoughts on “FAMP – Installing Apache2.2, MySQL, PHP on FreeBSD-8.1

  1. Good how-to, well done!
    However, when you will try to run Apache without restarting server you will receive warning message regarding ‘httpready’ Accept Filter. You need to run ‘kldload accf_http’ command and this warning will be gone.
    Also, where is no such directories in FreeBSD ports collection like ‘/usr/ports/php5’ and ‘/usr/ports/mysql51-server’, must be ‘/usr/ports/lang/php5’ and ‘/usr/ports/db/mysql51-server’.

  2. =D
    thx for the blog entry, you might want to add php-extensions here to build the mysql plugin for php.

    could add the pkg_add -r alternatives man that would have samed me buckos of time since my webserver is a p4 with 512 ram and a 5400rp hard drive

    when i get around to making my own program language i’ma call it smiley and make people use smileys instead of curlys
    (= code =)
    D=

  3. Thanks for the step-by-step guide, it was helpful and got me through the process of adding all three of the ports. I have done this before but was not sure of the process entirely.

    Two minor errors to note:

    MySql is located at /usr/ports/databases instead of just /usr/ports
    PHP same issue .. /usr/ports/lang rather than just /usr/ports

    At least these were the locations on my system. 🙂

  4. in apache22 httpd.conf i’ve
    LoadModule php5_module libexec/apache22/libphp5.so

    and to get session module:
    cd /usr/ports/lang/php5-extension
    make config
    selecting session and other modules i need
    make install

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s