Web - Installing Apache2, PHP, and MySQL from Source


2002-11-04
MySQL Get the latest stable copy of MySQL (get the default package) from http://www.mysql.com

Create the user and group “mysql” with the adduser command.

$ tar -zxmf mysql-3.23.53.tar.gz
$ cd mysql-3.23.53
$ ./configure
$ gmake
$ su
# gmake install
# mysql_install_db
# chown -R mysql /usr/local/var
# chgrp -R mysql /usr/local/var
# cp support-files/my-medium.cnf /etc/my.cnf

Start MySQL and set the database root password.

# safe_mysqld --user=mysql
# mysqladmin -u root password 'new-password'

Create a startup script for MySQL

# vi /usr/local/etc/rc.d/mysql_server.sh
#!/usr/local/bin/bash

case "$1" in
start)
if [ -x /usr/local/bin/safe_mysqld ]; then
/usr/local/bin/safe_mysqld --user=mysql > /dev/null & 2>&1 && echo -n ' mysqld'
fi
;;
stop)
/usr/bin/killall mysqld > /dev/null 2>&1 && echo -n ' mysqld'
;;
*)
echo ""
echo "Usage: `basename $0` { start | stop }"
echo ""
exit 64
;;
esac

# chmod 750 /usr/local/etc/rc.d/mysql_server.sh

Apache 2

The latest version of Apache can be obtained from http://www.apache.org

$ tar -zxmf httpd-2.0.43.tar.gz
$ cd httpd-2.0.43
$ ./configure --prefix=/usr/local/apache2
$ gmake
$ su
# gmake install

PHP
For FreeBSD you will need to install GNU Portable Threads.

# cd /usr/ports/devel/pth
# gmake install

Get the latest version of PHP from http://www.php.net

# tar -zxmf php-4.2.3.tar.gz
# cd php-4.2.3
# ./configure --enable-track-vars --enable-force-cgi-redirect --with-gettext --with-apxs2=/usr/local/apache2/bin/apxs --with-tsrm-pth --with-mysql
# gmake
# gmake install

Configuring httpd.conf
Add these lines to httpd.conf:

LoadModule php4_module        modules/libphp4.so
AddType application/x-httpd-php .php

And add index.php to the DirectoryIndex section…

DirectoryIndex index.html index.html.var index.php

Starting Apache

# /usr/local/apache2/bin/apachectl start

Make a startup script:

# vi /usr/local/etc/rc.d/apache.sh

#!/bin/sh
PREFIX=/usr/local/apache2

case "$1" in
start)
[ "ssl" = "ssl" -a -f "$PREFIX/conf/ssl.crt/server.crt" ] && SSL=ssl
[ -x ${PREFIX}/bin/apachectl ] && ${PREFIX}/bin/apachectl start${SSL} > /dev/null && echo -n ' apache2'
;;
stop)
[ -r /var/run/httpd.pid ] && ${PREFIX}/bin/apachectl stop > /dev/null && echo -n ' apache2'
;;
*)
echo "Usage: `basename $0` {start|stop}" >&2
;;
esac

exit 0

# chmod 750 /usr/local/etc/rc.d/apache.sh