RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Creating an oBAMP Stack: OpenBSD, Apache, MySQL, and PHP : Page 3

The OpenBSD, Apache, MySQL, and PHP (oBAMP) platform provides a powerful point of departure for the creation of dynamic web content. Learn the procedures for running OpenBSD 4.4 with Apache SSL, MySQL 5, and PHP 5.

Installation of the oBAMP Stack in Nine Steps
Now it's time to get down to business: Installing the basic oBAMP stack via the OpenBSD packages collection This procedure works on either i386 (Intel) or amd64 (64-bit) architectures:
  1. Install MySQL 5.0.51 as a package:
    $ sudo pkg_add -v mysql-server-5.0.51ap1.tgz
    Read the detailed instructions on how to install a MySQL database in /usr/local/share/doc/mysql/README.OpenBSD.
  2. Build the initial MySQL databases:
    $ sudo /usr/local/bin/mysql_install_db
  3. Start the MySQL 5 database server:
    $ sudo /usr/local/bin/mysqld_safe &
  4. Activate your MySQL production settings and follow the onscreen prompts to set a MySQL root password, removing anonymous users:
    $ /usr/local/bin/mysql_secure_installation
  5. Add the Suhosin Hardened PHP 5.2.6 package as an Apache module:
    $ sudo pkg_add -v php5-core-5.2.6.tgz
  6. Enable the php5 module with a symbolic link:
    $ sudo ln -s /var/www/conf/modules.sample/php5.conf /var/www/conf/modules
    Read the /var/www/conf/php.ini file for PHP hardening details and configuration options.
  7. Enable the PHP mySQLi functions to access MySQL servers version 4.1 and above:
    $ sudo pkg_add -v php5-mysqli-5.2.6.tgz
  8. Create a symbolic link to enable the mySQLi extension:
    $ sudo ln -fs /var/www/conf/php5.sample/mysqli.ini /var/www/conf/php5/mysqli.ini
  9. Edit the Section 2 'Main' Apache 1.3.29 /var/www/conf/httpd.conf file as follows:
    1. Change the email address for ServerAdmin to you@youraddress.com.
    2. Change your ServerName to a valid DNS entry. If you do not have a valid DNS name for your host, enter the IP address associated with your LAN (eg Type ifconfig –a to find the INET address associated with your working Ethernet card.
    3. Add index.php to the DirectoryIndex as follows:
            DirectoryIndex index.html index.php
    4. Find the line AddType application/x-httpd-php .php and delete the comment tag (#).

Congratulations. You have now installed the basic oBAMP stack via the packages collection.

Starting and Stopping the Apache Server as the SuperUser
To start Apache, use the following command:

$ sudo apachectl start     (c as in current, t as in table, l as in Linux)
To stop Apache, use this command:

$ sudo apachectl stop   (c as in current, t as in table, l as in Linux)
Start Apache now. Test your PHP installation by navigating to the htdocs directory, the default location from which Apache serves public files to the world:

$ sudo apachectl start
// change to the Apache public htdocs directory
$ cd /var/www/htdocs
// list all files in the directory
$ ls
To confirm that Apache is running locally, start the OpenBSD default text browser Lynx (http and https) to surf from your console to the Apache server running as localhost.

$ lynx
You should see the Apache default index.html congratulations screen. Enter q to quit Lynx.

Test PHP by creating a new index.php file that includes the line <?php phpinfo(); ?> $ sudo vi index.html.

Beneath the <body bgcolor="#ffffff"> tag, insert the line:

<?php phpinfo(); ?>

Then save the index.php file with your changes:

ESC:wq! index.php. 

Figure 1. Running OpenBSD-powered Apache, MySQL, and PHP Web Server: Apache is now loaded with the PHP module, and mySQLi provides the functions for MySQL database connectivity.

Test this out from the server console with the default installed Lynx text browser. For security reasons, OpenBSD does not ship with a graphical browser enabled. To further test that your Apache-powered OpenBSD machine is serving documents, enter the IP address of your server machine into a LAN-connected computer's browser URL field. Enter the server's LAN IP address or fully qualified domain name into your client machine browser URL field (this value was entered into the Apache httpd.conf file previously):

// secure lynx browser on localhost
$ lynx
// LAN connected Client Browser URL or http://www.fullyqualifieddomain.com

Depending on your configuration choices, you should now be serving the Apache congratulations screen with PHP information across your LAN or to the Internet at large.

Test index.php by using another computer on your local network and entering the IP address of the ServerName or DNS-resolving ServerName that was set in the Apache configuration file /var/www/conf/httpd.conf (for example,

Congratulations! Apache is now loaded with the PHP module, and mySQLi provides the functions for MySQL database connectivity (see Figure 1). You are now running an OpenBSD-powered Apache, MySQL, and PHP web server! See Listing 1. Auto Loading MySQL and Apache Https on Boot for an auto-load enhancement to your configuration.

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date