Installing PHP / MySql / Mod_SSL / Apache 1.3 on BSD

To set up/Install PHP, MySQL, Apache, Mod_SSL on a FreeBSD box.


1. Install Mysql

# cd /usr/ports/databases/mysql323-server/
or
# cd /usr/ports/databases/mysql40-server

# make install

Optional:

# cd /usr/ports/databases/mysql323-client/
# make install

2. Configure MySQL and launch it (still working on this part for docs).

If you wish to limit MySQL to localhost connections, copy /usr/local/share/mysql/my-large.cnf to /etc/my.cnf then edit /etc/my.cnf and add the following line under [mysqld]:

bind-address = 127.0.0.1

Start My SQL:

# cd /usr/local ; /usr/local/bin/safe_mysqld &  [for 3.2.3]
or

Add the following lines to /etc/rc.conf  [for 4.0]
# MYSQL
mysql_enable=YES
mysql_limits=YES
mysql_dbdir=/var/db/mysql

# /usr/local/etc/rc.d/mysql-server.sh start

Set Root Password for MySQL:

# /usr/local/bin/mysqladmin -u root password <new-password>
# /usr/local/bin/mysqladmin -u root -h localhost password <new-password>

Add the following if you plan to allow external connections
# /usr/local/bin/mysqladmin -u root -h <hostname> password <new-password>

Notes:
  To stop sql (You will be prompted for a password):

# /usr/local/bin/mysqladmin -u root -h zone -p shutdown

  To create a database (You will be prompted for a password):

# /usr/local/bin/mysqladmin -u root -p create <database name>

  To create a user for a database (You will be prompted for a password):

# /usr/local/bin/mysqlaccess -u <username> -p <password> -d <database> -U root -P <Root's MySql Password>

  To check rights to a database:

# /usr/local/bin/mysqlaccess <user> <database> -U root -P <Root's MySql Password>


3. Download source code and extract

# cd /usr/local/src
# fetch http://apache.secsup.org/dist/httpd/apache_1.3.34.tar.gz
# fetch ftp://ftp.modssl.org/source/mod_ssl-2.8.25-1.3.34.tar.gz
# fetch ftp://ftp.openssl.org/source/openssl-0.9.7i.tar.gz
# fetch http://us2.php.net/get/php-4.4.2.tar.gz/from/us3.php.net/mirror
# fetch ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
# fetch http://prdownloads.sourceforge.net/mhash/mhash-0.9.2.tar.gz
# fetch ftp://ftp.gnu.org/gnu/aspell/aspell-0.60.2.tar.gz
# fetch http://curl.haxx.se/download/curl-7.15.1.tar.gz
# fetch http://superb.dl.sourceforge.net/sourceforge/pcre/pcre-6.3.tar.gz
# mv mirror php-4.3.10.tar.gz
# gzip -d -c apache_1.3.34.tar.gz | tar xvf -
# gzip -d -c mod_ssl-2.8.25-1.3.34.tar.gz | tar xvf -
# gzip -d -c openssl-0.9.7i.tar.gz | tar xvf -
# gzip -d -c php-4.4.2.tar.gz | tar xvf -
# gzip -d -c libmcrypt-2.5.7.tar.gz | tar xvf -
# gzip -d -c mhash-0.9.2.tar.gz | tar xvf -
# gzip -d -c aspell-0.60.2.tar.gz | tar xvf -
# gzip -d -c curl-7.15.1.tar.gz | tar xvf -
# gzip -d -c pcre-6.3.tar.gz | tar xvf -

4. Make OpenSSL

# cd /usr/local/src/openssl-0.9.7e
# ./config
# make
# make test

5. Make Mod_SSL

# cd /usr/local/src/mod_ssl-2.8.25-1.3.34
# ./configure \
    --with-apache=../apache_1.3.34\
    --with-ssl=../openssl-0.9.7i\
    --activate-module=src/modules/standard/mod_info.c\
    --activate-module=src/modules/standard/mod_so.c\
    --activate-module=src/modules/experimental/mod_auth_digest.c

6. Compile/Configure Apache

# cd /usr/local/src/apache_1.3.34
# make

Optionally add this step (if you don't you'll need your own certificate...):
# make certificate

Continue with install
# make install

7. Install LIBMCRYPT

# cd /usr/local/src/libmcrypt-2.5.7
# ./configure
# make
# make install

8. Install LIBMHASH

# cd /usr/local/src/mhash-0.9.2
# ./configure
# make
# make install

9. Install Aspell

# cd /usr/local/src/aspell-0.60.2
# ./configure
# make
# make install

If this fails, install the port:

# cd /usr/ports/textproc/aspell
# make
# make install

10. Install PCRE

# cd /usr/local/src/pcre-6.3
# ./configure
# make
# make install

11. Install cURL

# cd /usr/local/src/curl-7.15.1
# ./configure
# make
# make install

12. Compile Mod_PHP

Note: You'll want to add/remove any additional options to your php configure command before continuing. In this case, I had already added the necessary libraries for zlib, jpeg, and gd before running the configure command below.

# cd /usr/local/src/php-4.4.2/
# ./configure \
    --prefix=/usr/local\
    --enable-module=so\
    --with-mcrypt\
    --with-mhash\
    --with-pspell\
    --with-mysql\
    --with-pcre-regex\
    --with-openssl\
    --with-curl\
    --with-zlib\
    --with-jpeg-dir=/usr/local/lib\
    --with-gd\
    --disable-posix-threads\
    --with-apxs=/usr/local/apache/bin/apxs
# make
# make install

13. Configure PHP in Apache

# vi /usr/local/apache/conf/httpd.conf

Add/verify the following line under the LoadModule section:

LoadModule php4_module libexec/libphp4.so

  or

AddModule mod_php4.c

Add/verify the following line under the AddType section:

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

Find the following line:

    DirectoryIndex index.html

And change it to:

    DirectoryIndex index.html index.htm index.php