Install Apache, MySQL And PHP On FreeBSD9

In this tutorial i will show you how to install AMP(Apache, MySQL, PHP ) in FreeBSD9.

Installing AMP in FreeBSD

System:

# uname -a 
FreeBSD Freebsd-unixmen 9.1-RELEASE FreeBSD 9.1-RELEASE #0 r243826: Tue Dec 4 06:55:39 UTC 2012 root@obrian.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC i386

1-Install Apache

cd /usr/ports/www/apache24
make install clean

Once Apache has been successfully installed, add the following line to /etc/rc.conf so that Apache will start automatically at system boot.

echo 'apache24_enable="YES"' >> /etc/rc.conf

Start Apache service.

# /usr/local/etc/rc.d/apache24 start
Performing sanity check on apache22 configuration:
Syntax OK
Starting apache24.

Open your browser and navigate to http://ip-address/.apache2-Install MySQL:

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

2-1. Open /etc/rc.conf with your editor and add the line shown below to enable starting mysql server on boot.

 mysql_enable="YES"

2-2. Start mysql manually.

/usr/local/etc/rc.d/mysql-server start
Starting mysql.

2-3. Set a password for the MySQL root user and login  by executing the command

# mysqladmin -u root password "my-password"
# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.13 Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>

3-Install PHP

we have  to install php55  and his extensions

 cd /usr/ports/lang/php55
 make config

You should select “Build Apache module”.menu-configThis line will be add automatically to you Apache config:

LoadModule php5_module        libexec/apache24/libphp5.so

Install  PHP55

make install  clean

check the installed php  version:

php --version
PHP 5.5.0 (cli) (built: Aug 12 2013 15:30:36) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0-dev, Copyright (c) 1998-2013 Zend Technologies

Install now php55-extensions

cd /usr/ports/lang/php5-extensions/
make config

Please  select “MySQL database support” and “MySQLi database support”, if you want later connect to Mysql databases.

make install  clean

Configure PHP  with Apache

cp /usr/local/etc/php.ini-development /usr/local/etc/php.ini

Edit /usr/local/etc/apache24/httpd.conf and find DirectoryIndex index.html, then add index.php:

DirectoryIndex index.html index.htm index.php

add the following lines too:

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

Restart Apache:

 /usr/local/etc/rc.d/apache24 restart

Check if php is installed well via phpinfo file.

vi  /usr/local/www/apache24/data/test.php

Add the following lines.

<?php
phpinfo(); 
?>

or

echo "<? phpinfo(); ?>" >> /usr/local/www/apache24/data/test.php

save and exit.

Open http://ip-address/test.php from your browser.php-freebsdEnjoy!!