Home arrow Guides arrow Install PHP Modules for a FreeBSD Production Web Server
Install PHP Modules for a FreeBSD Production Web Server PDF
Sunday, 03 April 2011
Let's say we want to build a FreeBSD Production Web Server with a list of php modules that will be installed after we install PHP, Apache and MySQL. Here is a script to do that, very usefull if we will install many servers in the future.

So in order to install a FreeBSD Production Web Server we will have to:

1. Install FreeBSD
---------------------
Get the last IMAGE of FreeBSD from ftp.freebsd.org. You can use USB version which is easely to install. Install it, then cvsup to the stable version.

You can do that using this tutorial: http://www.freebsdonline.com/content/view/460/476/


2. Install PHP and Appache
-----------------------------
  cd /usr/ports/www/apache22
  make install clean

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


Then, compile php.

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


Don't forget check APACHE MODULE before compiling, then compile and install, so your Apache would be able to run PHP scripts.

You must configure Apache to run PHP.


3. Install MySQL Server and Client
-----------------------------------
To install MySQL Server and Client use:

cd /usr/ports/databases/mysql51-client
make install clean

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


4. Install PHP modules
--------------------------
Well this is the interesting part of this tutorial. We will use a list of PHP modules, saved in php_modules.conf file.
And then we will have a script: compile_php_modules.sh that will do the task of compiling php modules from ports and installing on our system.

# ------- php_modules.conf ------------

# php modules
php5-bz2
php5-bcmath
php5-ctype
php5-curl
php5-dom
php5-extensions
php5-filter
php5-gd
php5-gettext
php5-hash
php5-iconv
php5-json
php5-ldap
php5-mbstring
php5-mcrypt
php5-mysql
php5-openssl
php5-pdo
php5-pdo_sqlite
php5-posix
php5-session
php5-simplexml
php5-soap
php5-sockets
php5-sqlite
php5-tokenizer
php5-xml
php5-xmlreader
php5-xmlwriter
php5-zip
php5-zlib

# ------- eof php_modules.conf -------

And our script compile_php_modules.sh :

#!/bin/sh

MAKE_PARAMS=""

confFile="php_modules.conf"
confFileWithPath="php_modules_with_path.conf"
confLine=""
confLineWithPath=""
check_if_installed=""

rm php_modules_with_path.conf

while [ 1 ]
do
read confLine || break
if [ "`echo $confLine | cut -c1`" = "#" ] ; then
  echo "Processing: "$confLine
else
  echo "Generating path for:"$confLine
  confLineWithPath=`whereis $confLine | cut -d" " -f2`
  err=$?
  if [ "$err" -ne 0 ]
  then
    echo "Error running make install, err:"$err"--->"$confLineWithPath
    echo "Error running make install "$err"-"$confLineWithPath >>error_php_modules_with_path.log
    exit 1;
  fi
  check_if_installed=`pkg_info | grep $confLine`
  err=$?
  if [ "$err" -ne 0 ]
  then
    echo "$confLineWithPath" >>php_modules_with_path.conf
  else
    echo "Package installed. Skipping... "$err"--->"$confLineWithPath
    echo "Package installed. Skipping... "$err"-"$confLineWithPath >>error_php_modules_with_path.log
  fi
fi
done < $confFile

while [ 1 ]
do
read confLine || break
if [ "`echo $confLine | cut -c1`" = "#" ] ; then
  echo "$confLine"
else
  cd $confLine
  echo "Compile & Install: "$confLine
  make  install $MAKE_PARAMS BATCH=yes
  err=$?
  if [ "$err" -ne 0 ]
  then
    echo "Error running make install, err:"$err"--->"$confLine
    echo "Error running make install "$err"-"$confLine >>error_php_modules.log
    exit 1;
  fi
fi
done < $confFileWithPath


After installing PHP modules, don't forget to restart Apache.

If you want more modules you can add them to php_modules.conf file.

 

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

Other BSD Systems

OpenBSD

Misc

Solaris

Polls

Best BSD firewall?