Build a Dynamic Web and Email Serving Platform

General Information

Using FreeBSD, Apache-modSSL, MySQL, PHP, Sendmail and CuCiPop, you can setup an open source solution that will have you serving dynamic web pages and email quickly, reliably, securely, and efficiently without any out-of-pocket expense.

Install CVsup to Stay Current

If you have just installed the ports collection using a CD-ROM, you must upgrade to the latest releases of the ported software you need.

# cd /usr/ports/net/cvsup-without-gui
# make
# make install
# make clean

As root, copy /usr/share/examples/cvsup/ports-supfile to a new location. In this case, copy to /root on your home directory:

# cp /usr/share/examples/cvsup/ports-supfile /root/ports-supfile

Notice the space between ports-supfile and /root/ports-supfile.

# ee /root/ports-supfile

Change the ports-supfile (line 50 or so) to look something like the following:

*default host=cvsup.au.FreeBSD.org.
*default base=/usr
*default prefix=/usr
*default release=cvs
*default delete use-rel-suffix
*default tag=.
src-all

After you’ve done this, press Escape and then Return to leave editor. Press Enter to save your changes. Now it’s time to run CVsup:

# cvsup -g -L 2 /root/ports-supfile

This command upgrades all the skeletons in your ports collection. Depending on your Internet connection speed, the upgrade can take an hour or longer.

Install Perl5

Enter the following commands one at a time, waiting for the command prompt between each command.

# cd /usr/ports/lang/perl5
# make
# make test
# make install
# make clean
# cd ~
# rehash
# use.perl port

Install MySQL

# cd /usr/ports/databases/mysql40-server
# make
# make install
# make clean
# ee /etc/make.conf

Add the following two lines, one on top of the other as shown:

WITH_BDB_VER=40
WITH_MYSQL_VER=40

Press Escape to exit, and the Enter to save your changes before you leave the editor.

Install Apache-mod_ssl

# cd /usr/ports/www/apache13-modssl
# make
# make certificate TYPE=custom

Press Enter to create an [R]SA server key. Enter correct details for each question. The process will then run through a second time. When asked to encrypt this key, choose [Y]es and then type an encryption password. This password must be entered each time the Apache server is restarted.

# make install
# make clean
# ee /etc/rc.conf

Add the following line to the end of the file

apache_enable="YES"

Press Escape and then Enter to exit and save changes

# ee /usr/local/etc/apache/httpd.conf

Remove the ‘#’ comment from the beginning of the ServerName line and change it to suit (ie: www.mydomain.com).

Find the line that says ServerAdmin and put your postmaster e-mail address there.

# ee /etc/hosts

Add the server to the list of hosts

192.168.1.254    webserver    www.mydomain.com

Install PHP

# cd /usr/ports/www/mod_php4
# make

When prompted to choose installation preferences, simply choose OK.

# make install
# make clean

Install PHP Extensions

# cd /usr/ports/lang/php4-extensions
# make install distclean

When prompted to choose installation preferences, simply choose OK.

Enable Apache to serve PHP

# cd ~
# ee /usr/local/etc/apache/httpd.conf

Add the following lines to the bottom of the Apache httpd.conf file

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

You must now restart the apache server

# apachectl stop
# apachectl startssl

Test the PHP installation (Optional)

# cd ~
# ee /usr/local/www/data/index.php

Add the following code to the file you just opened






Press Escape and then Enter to leave the editor and save changes. Using another computer, navigate to your server in Internet Explorer (ie http://192.168.1.254). If installation was successful you should see the PHP information page.

Start and Configure MySQL

# ee /etc/rc.conf

Add the following line to the bottom of the file

mysql_enable="YES"

Press Escape and then Enter to leave the editor and save changes.

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

The default password is blank so simply press Enter when prompted. For security reasons we should now secure the intial user accounts. Remember that all MySQL commands end with a semicolon.

DELETE FROM mysql.user WHERE User = '';
FLUSH PRIVILEGES;

Next we will set a default password for the root account.

UPDATE mysql.user SET Password = PASSWORD('newpwd') WHERE User = 'root';
FLUSH PRIVILEGES;

Finally we must add an account for remote access.

GRANT ALL PRIVILEGES ON *.* TO 'root'@'<  >' IDENTIFIED BY '<  >' WITH GRANT OPTION;

You can now exit the MySQL server.

quit;

Test MySQL and PHP (Optional)

# ee /usr/local/www/data/mysql.php

Add the following code to the editor window (don’t forget the semi-colons)




Press Escape then Enter to exit and save changes. Using another computer, navigate to this page (ie http://192.168.1.254/mysql.php). If installation was successful you should see the PHP information page.

Install and Configure Sendmail

# cd /usr/ports/mail/sendmail
# make
# make install
# make clean
# cd /usr/mail/
# cp access.sample access
# ee aliases

Change the file to look like the following:

192.168 RELAY
YOURDOMAIN RELAY

Press Escape then Enter to exit and save changes.

# ee local-host-names

Change the file to look like the following:

mail.YOURDOMAIN
YOURDOMAIN
YOURIPADDRESS

Press Escape then Enter to exit and save changes.

Install and Configure CuCiPop

# cd /usr/ports/mail/cucipop
# make
# make install
# make clean
ee /urs/local/etc/rc.d/cucipop.sh

Add the following code to the editor window. The second line should not be split as below.

#!/bin/sh
[ -x /usr/local/libexec/cucipop ] && /usr/local/libexec/cucipop -Y && echo "CuCiPop started"

Press Escape then Enter to exit and save changes.

# chmod 750 /usr/local/etc/rc.d/cucipop.sh
# killall -hup inetd

Final Restart

# shutdown -r now

The server will now restart, after which you should login as root. The above applications must now be started.

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

You’re finished!

Adapted from Gregory L. Magnusson’s “Build a Dynamic Web Serving Platform with FreeBSD”. Updated by Scott Forbes in February 2006.

Speak Your Mind

*