At the beginning of 2008, I posted how to get
Apache, PHP, and MySQL running on OpenBSD 4.2. This is commonly known as
LAMP when running under Linux. I call this
OAMP.
I decided to AMP my OpenBSD 4.4 rig, and followed those instructions. No surprise, things have changed a little bit.
Before installing packages
First and foremost, make sure you can easily install packages. In this case, I've added the FTP repository to the PKG_PATH environment variable, then I've made sure my user-level account has access to sudo.
OpenBSD's package system has finally become a little less flaky about remote packages and dependencies, so I finally added this to my user-level account's .profile:
PKG_PATH=ftp://ftp.openbsd.org/pub/OpenBSD/4.4/packages/i386/
export PKG_PATH
My user-level account is also in the wheel group, and the following line was uncommented from
/etc/sudoers:
%wheel ALL=(ALL) SETENV: ALL
That means anyone in wheel can run anything with sudo as any other user (
root by default)
Installing packages
Obviously, you've got OpenBSD 4.4 installed and patched. If not, you'd better get crack-a-lacking, homeslice! OpenBSD comes with Apache, so you're basically halfway there by installing OpenBSD.
The following command will install php5-mysql and mysql-server (obviously)
That will grab all the dependencies in one swoop, including the mysql-client package and php5-core. I'll snip the output to only display the relevant stuff, and address that afterwards
-bash-3.2$ sudo pkg_add php5-mysql mysql-server--- php5-core-5.2.6 -------------------
To enable the php5 module please create a symbolic
link from /var/www/conf/modules.sample/php5.conf
to /var/www/conf/modules/php5.conf.
ln -s /var/www/conf/modules.sample/php5.conf \
/var/www/conf/modules
The recommended php configuration has been installed
to /var/www/conf/php.ini.
Don't forget that the default OpenBSD httpd is chrooted
into /var/www by default, so you may need to create support
directories such as /var/www/tmp for PHP to work correctly.
--- php5-mysql-5.2.6 -------------------
You can enable this module by creating a symbolic
link from /var/www/conf/php5.sample/mysql.ini to
/var/www/conf/php5/mysql.ini.
ln -fs /var/www/conf/php5.sample/mysql.ini \
/var/www/conf/php5/mysql.ini
Configuring Packages
As shown above, there's some work to do in order to make PHP work with Apache and make the PHP module load the MySQL client library.
I'm not a huge fan of symbolic links to sample files. I opted to copy them.
sudo cp /var/www/conf/modules.sample/php5.conf \ /var/www/conf/modules/
sudo cp /var/www/conf/php5.sample/mysql.ini \
/var/www/conf/php5/
Install the default database and start MySQL, then assign a password for the MySQL root user with the following commands (the output doesn't really matter)
sudo /usr/local/bin/mysql_install_db
sudo /usr/local/share/mysql/mysql.server start
sudo /usr/local/bin/mysqladmin \
-u root password 'your-password'
Now, we want to make sure that both Apache and MySQL start automatically.
Find the "httpd_flags" line in /etc/rc.conf and set it to literally two quotes: "" or, if you want to disable chroot (not recommended, but can make OAMP life much easier for you when you go to install webapps) set it to "-u":
sudo vi /etc/rc.conf
(find httpd_flags once editing the file)
# use -u to disable chroot, see httpd(8)
httpd_flags=""
-or-
httpd_flags="-u"
You can launch apache easily from the command line now by executing httpd, so you don't need to reboot. Use -u if you specified it in /etc/rc.conf.
sudo httpd
This is kind of a cheap and non-official way to do make MySQL start, but it works just fine and it's how I always do it. You're supposed to make an rc function and all that so you can enable/disable it in /etc/rc.conf. Bah. Add the following line to the end of /etc/rc.local.
sudo vi /etc/rc.local
(add the following line to the end)
/usr/local/share/mysql/mysql.server start
At this point, you have OpenBSD set up to start Apache and MySQL at boot, and both should be running. Additionally, the PHP module should be loaded. To test MySQL, use mysql_setpermission, a perl script that lets you manage and create databases and users.
mysql_setpermission -u root
Password for user root to connect to MySQL: your-password
######################################################################
## Welcome to the permission setter 1.4 for MySQL.
## made by Luuk de Boer
######################################################################
What would you like to do:
1. Set password for an existing user.
2. Create a database + user privilege for that database
and host combination (user can only do SELECT)
3. Create/append user privilege for an existing database
and host combination (user can only do SELECT)
4. Create/append broader user privileges for an existing
database and host combination
(user can do SELECT,INSERT,UPDATE,DELETE)
5. Create/append quite extended user privileges for an
existing database and host combination (user can do
SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,INDEX,
LOCK TABLES,CREATE TEMPORARY TABLES)
6. Create/append full privileges for an existing database
and host combination (user has FULL privilege)
7. Remove all privileges for for an existing database and
host combination.
(user will have all permission fields set to N)
0. exit this program
Make your choice [1,2,3,4,5,6,7,0]:
If it shows the menu, then MySQL is running and the password you configured is working.
Test PHP and Apache by creating a phpinfo.php file in /var/www/htdocs/phpinfo.php:
<?php
phpinfo();
?>
Hit it with your web browser to make sure it loads. It should show you information about your PHP installation, including the MySQL module.
If you experience problems installing *AMP-based web apps, try:
- Making a hard link to /var/run/mysql/mysql.sock within /var/www somewhere, and editing the php.ini file accordingly
- Disabling apache chroot by setting httpd_flags="-u"
- Checking the php, mysql, and apache error logs for more information about what went wrong