OBAMP Howto: OpenBSD - Apache - MySQL - PHP

Markie

OpenBSD Newbie
Ja hallo allerseits,

Wer OpenBSD in einem "production environment" als Webserver einsetzen will kommt meiner Meinung nach heutzutage oft nicht darum herum, neben Apache auch PHP und MySQL zu installieren.
Wer sich für OpenBSD entscheidet, tut dies wohl oft der Sicherheit wegen, nicht der guten, aktuellen Dokumentation oder einfachen Benutzerfreundlichkeit wegen ( Meine Meinung ;) ).
Ein Teil der Sicherheit eines OpenBSD Webservers kommt vom "chroot"-ing von Apache. Und diese Sicherheit will man, wenn man sich schon für OpenBSD und Sicherheit entscheidet, wohl nicht einfach aufgeben indem man Apache mit dem "-u" Argument ausserhalb des "chroot" laufen lässt, nur um PHP und MySQL normal benutzen zu können.

Wie also fügt man PHP und MySQL so hinzu, dass alles im normalen "chroot" des OpenBSD Apache Webservers laufen kann?

Diese Frage hat mir einiges Kopfzerbrechen und Sorgen bereitet und man findet leider auch sehr wenig gute und aktuelle Informationen dazu.
Das beste was ich dazu bisher gefuden habe stammt von www.freebsdforums.org (die im Moment ein Problem mit der Registrierung von Neumitgliedern zu haben scheinen). Der Sicherheit wegen poste ich das Tutorial hier (leicht editiert / formatiert), damit es sicher allen zur Verfügung steht:

########################################


OpenBSD https php mysql

( Your may publish this faq anywhere you want. Do what every you want with it. Print it out in doubles space font and turn it in as your CS project. I little credit would be nice though:-)

I'm new to OpenBSD, I compiled this faq to help others in my situation. I might not have all the packag dependicies needed. This is becasue I downloaded all the packages into the directory. So they might have added some packages I do not know about, like gettext.

Setting Up an OpenBSD 3.2 web server
Please install all the packages for base installation of OpenBSD, this will make things easier. I will assume that all packages will be in the /tmp directory. This document contains excerpts from man documents and sources sited at the end of the document.


************* Main Packages, order of install matters **************

autoconf-2.52p0 automatically configure source code on many Un*x platforms
bzip2-1.0.2 block-sorting file compressor, unencumbered
c-client-4.53 University of Washington's c-client mail access routines
gettext-0.10.40p1 GNU gettext
libiconv-1.8 character set conversion library
libtool-1.3.5p3 generic shared library support script
libxml-2.4.28 XML parsing library
mysql-client-3.23.55 multithreaded SQL database (client)
mysql-server-3.23.55 multithreaded SQL database (server)
netpbm-9.24 toolkit for converting images between different formats
p5-DBD-Msql-Mysql-1.22.19 MySQL drivers for the Perl DBI
p5-DBI-1.30 unified perl interface for database access
p5-Net-SSLeay-1.19 perl module for using OpenSSL
php4-core-4.2.3p1 server-side HTML-embedded scripting language
php4-imap-4.2.3 imap, pop3 and nntp extensions for php4
php4-mysql-4.2.3 mysql database access extensions for php4
php4-pear-4.2.3 collection of base classes for common PHP tasks
pico-4.4 small text editor
recode-3.6 convert files between character sets and usages

Packages not in OpenBSD
webmin-1.090.tar.gz web based administration http://www.webmin.com
phpMyAdmin-2.5.0-rc2-php.tar.bz2 php Administration http://www.phpMyAdmin.net

Tools you will need for win32 client side service will include Putty, and WinSCP2

For good measure, copy all the packages to the hard drive. It seems that some of the packages like installing there own dependencies. Go figure.
Use your favorite editor, vi or pico, take your pick. Pico is easier to use and more dangerous.
It is preferred that all changes be made to /etc/rc.conf.local instead of /etc/rc.local. Changes you make in the /etc/rc.conf.local file will override settings in /etc/rc.conf
Create SSl Certificate
Now it is time to generate the RSA certificate for ssl. This will be kept in /etc/ssl/ with a corresponding key in /etc/ssl/private/
To start off, you need to create your server key and certificate using OpenSSL:

code:
--------------------------------------------------------------------------------
# openssl genrsa -out /etc/ssl/private/server.key 1024
--------------------------------------------------------------------------------


The next step is to generate a Certificate Signing Request which is used to get a Certifying Authority (CA) to sign your certificate. To do this use the command:

code:
--------------------------------------------------------------------------------
# openssl req -new -key /etc/ssl/private/server.key -out /etc/ssl/private/server.csr
--------------------------------------------------------------------------------


This server.csr file can then be given to Certifying Authority who will sign the key. One such CA is Thawte Certification which you can reach at http://www.thawte.com/. Thawte can currently sign RSA keys for you. A procedure is being worked out to allow for DSA keys.
If you cannot afford this, or just want to sign the certificate yourself, you can use the following.

code:
--------------------------------------------------------------------------------
# openssl x509 -req -days 365 -in /etc/ssl/private/server.csr \
-signkey /etc/ssl/private/server.key -out /etc/ssl/server.crt
--------------------------------------------------------------------------------


With /etc/ssl/server.crt and /etc/ssl/private/server.key in place, you should be able to start httpd (apache) with the -DSSL flag, this will enable https transactions with your machine on port 443. We will activate them later.( add the ¡Vu to the apache flag if you have problems running certain web applications)

Main install ( Apache, Mysql, PHP, WebMin, phpMyAdmin)
Add pico and pine and other fun packages

code:
--------------------------------------------------------------------------------
# pkg_add p5-DBI-1.30.tgz
# pkg_add autoconf-2.52p0.tgz
# pkg_add pico-4.4.tgz
--------------------------------------------------------------------------------


Install Mysql Package

code:
--------------------------------------------------------------------------------
# pkg_add mysql-client-3.23.55.tgz
# pkg_add p5-DBI-1.30.tgz
# pkg_add p5-DBD-Msql-Mysql-1.22.19.tgz
# pkg_add mysql-server-3.23.55.tgz
--------------------------------------------------------------------------------


Add this to the end of the start up script /etc/rc.local. It will activate MySql on startup.

code:
--------------------------------------------------------------------------------
# vi /etc/rc.local

rm -R /var/www/var/run/mysql
mkdir -p /var/www/var/run/mysql

/usr/local/bin/mysqld_safe --user=_mysql -log &

sleep 10

ln /var/run/mysql/mysql.sock /var/www/var/run/mysql/mysql.sock
--------------------------------------------------------------------------------

(Sleep 10 is to make sure there is enough time for mysql.sock to be created.)
("rm -R /var/www/var/run/mysql" and "mkdir -p /var/www/var/run/mysql" are there to make sure there is a link to a fresh mysql.sock everytime it reboots.)
I know there are slicker ways of doing this. But, the above method seems to give me the least amount of problems.

Add the following to /etc/rc.conf or create it in a new file /etc/rc.conf.local. This will start your sftp, apache server, and start your Mysql. If you set MySql to know, it will not run the script to turn on mysql in rc.local. (If you do not want Apache to be chroot, then change httpd_flags to read httpd_flags="-u".)

code:
--------------------------------------------------------------------------------
# vi /etc/rc.conf.local
httpd_flags="-DSSL"
shlib_dirs="$shlib_dirs /usr/local/lib/mysql"
--------------------------------------------------------------------------------


Now since I don't like rebooting we are going do this. Start MySql and Change the password for root. Then copy MySql default setup file.

code:
--------------------------------------------------------------------------------
# /usr/local/bin/safe_mysqld &
# /usr/local/bin/mysqladmin -u root password 'new password'
--------------------------------------------------------------------------------


Reboot computer
THIS SECTION ONLY APPLIES IF YOU CANNOT CONNECT TO MySQL using mysql -h 127.0.0.1 -u root -p , and you need to connect from 127.0.0.1. If that is the case, MySql is not allowing local loop back look up. Here is a fix ( thnx to alex lee for the help on this)

code:
--------------------------------------------------------------------------------
#mysql -u root -p

mysql>use mysql

mysql> INSERT INTO user (Host, User, Password, Select_priv, Insert_priv, Update_priv, Delete_priv, Create_priv, Drop_priv, Reload_priv, Shutdown_priv, Process_priv, File_priv, Grant_priv, References_priv, Index_priv, Alter_priv) VALUES('127.0.0.1','root',PASSWORD('yourpassword'),'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');

Query OK, 1 row affected (0.20 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.06 sec)

mysql> select host, user, select_priv, grant_priv, password from user;
+------------+------+-------------+------------+------------------+
| host | user | select_priv | grant_priv | password |
+------------+------+-------------+------------+------------------+
| localhost | root | Y | Y | 3a9eb1070a0130ca |
| yourhost | root | Y | Y | |
| localhost | | N | N | |
| yourhost | | N | N | |
| 127.0.0.1 | root | Y | Y | 3a9eb1070a0130ca |
+------------+------+-------------+------------+------------------+
5 rows in set (0.05 sec)

mysql> exit
--------------------------------------------------------------------------------


Check to see if user root has access to 127.0.0.1
If you make a mistake you can always delete user access by the following

code:
--------------------------------------------------------------------------------
mysql> use mysql;
mysql > delete from user where user = "user to delete";
--------------------------------------------------------------------------------


REMBER THAT FOR WEB ACCESS YOU MUST GIVE ACEES TO USER WHERE USER IS AT @WWW
Install PHP and modules for imap, MySql, and pear

code:
--------------------------------------------------------------------------------
# pkg_add libiconv-1.8.tgz
# pkg_add gettext-0.10.40p1.tgz
# pkg_add recode-3.6.tgz
# pkg_add php4-core-4.2.3p1.tgz
# /usr/local/sbin/phpxs -s
# cp /usr/local/share/doc/php4/php.ini-recommended /var/www/conf/php.ini

# pkg_add php4-mysql-4.2.3.tgz
# /usr/local/sbin/phpxs -a mysql

# pkg_add c-client-4.53.tgz
# pkg_add php4-imap-4.2.3.tgz
# /usr/local/sbin/phpxs -a imap

# pkg_add php4-pear-4.2.3.tgz
--------------------------------------------------------------------------------


We now need to make the pear libraries readable by a chroot'd apache server

code:
--------------------------------------------------------------------------------
mkdir /var/www/php
mkdir /var/www/php/includes
cp -pR /usr/local/lib/php/* /var/www/php/includes
--------------------------------------------------------------------------------


then edit the var in /var/www/conf/php.ini to read like this:

code:
--------------------------------------------------------------------------------
;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;

; UNIX: "/path1:/path2"
include_path = ".:/php/includes"
--------------------------------------------------------------------------------


Add php types in Apache

code:
--------------------------------------------------------------------------------
#pico /var/www/conf/httpd.conf

AddType application/x-httpd-php .php .php3 .htm .html .inc

DirectoryIndex index.html index.php
--------------------------------------------------------------------------------


Make your test file:

code:
--------------------------------------------------------------------------------
# pico /var/www/htdocs/phptest.html

add the lines:
<?php
phpinfo();
?>
--------------------------------------------------------------------------------


Save it and type and restart apache or reboot the computer. ( apachectl restart doesn¡&brvbar;t work well all the time, I always like rebooting the computer)

code:
--------------------------------------------------------------------------------
# apachectl restart
--------------------------------------------------------------------------------


Use your favorite web browser to check to see if it worked.
Now we will add Webmin

code:
--------------------------------------------------------------------------------
# pkg_add p5-Net-SSLeay-1.19.tgz
# cp webmin-1.090.tar.gz /usr/local
# cd /usr/local
# gunzip webmin-1.090.tar.gz
# tar xf webmin-1.090.tar
# rm webmin-1.090.tar
# cd webmin-1.090
# ./setup.sh
--------------------------------------------------------------------------------


Follow the prompts for the webmin setup. They are very self explanatory.
Finally add phpMyAdmin

code:
--------------------------------------------------------------------------------
# cp phpMyAdmin-2.5.0-php.tar.gz /var/www/htdocs
# cd /var/www/htdocs
# tar -xzvf phpMyAdmin-2.5.0-php.tar.gz
# rm phpMyAdmin-2.5.0-php.tar.gz
--------------------------------------------------------------------------------


Edit config.inc.php

code:
--------------------------------------------------------------------------------
# pico /var/www/htdocs/phpMyAdmin-2.5.0/config.inc.php
--------------------------------------------------------------------------------


Change the values for host, user, password and authentication mode to fit your environment.

code:
--------------------------------------------------------------------------------
$cfg['PmaAbsoluteUri'] = (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://'
. $_SERVER['HTTP_HOST']
. (!empty($_SERVER['SERVER_PORT']) ? ':'
. $_SERVER['SERVER_PORT'] : '')
. substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/')+1);


cfg['Servers'][$i]['host'] = '127.0.0.1'; // MySQL hostname$cfg
['Servers'][$i]['auth_type'] = 'cookie'; // config, http,cookie
$cfg['Servers'][$i]['user'] = 'root'; // MySQL user
--------------------------------------------------------------------------------


Quick note: to get mod_perl to work with apache you have to recreate the directory structure with the files in chroot.
Example:
chroot directory: /var/www
perl directory: /var/libdata/perl15
copy files to: /var/www/var/libdata/perl15

code:
--------------------------------------------------------------------------------
# mkdir -R /var/www/var/libdata/
# cp -R /var/libdata/perl15 /var/www/var/libdata/perl15
--------------------------------------------------------------------------------


All information was found through trial and error and these sites

http://php.fastmirror.com/manual/en/install.openbsd.php
http://nomoa.com/bsd/mysql.htm
http://www.openbsd.org
http://www.phpwizard.net/projects/phpMyAdmin/
http://www.phpmyadmin.net/
http://www.efn.org/~rzeller/mysql/mysql-etc.txt
http://www.lemure.net/~chuck/openbsd_help/dbmail.html


Last edited by spinaltoad on 08-25-2004 at 05:33 AM


########################################

Zuerst gefunden unter:
http://www.bsdforums.org/forums/showthread.php?s=&threadid=9986&highlight=https+php+mysql

(h**p://www.bsdforums.org/forums/showthread.php?s=&threadid=9986&highlight=https+php+mysql)

Da gibt's auch noch eine kleine Diskussion dazu.


Ich wäre sehr froh wenn andere ähnliche Tutorials zur Apache-MySQL-PHP-Einrichtung unter OpenBSD hier posten würden oder hier ihre Erfahrungen mitteilen würden.

Grüsse,
Markie
 
Zuletzt bearbeitet:
Hab das gerade meinen "Schülerlein" empfholen. Der Troll checkt es aber net. *fg*

Aber das wird schon noch. Vielleicht kennt ihr Ihn.. Ins0m.

-Falk
 
haha falk, unglaublich witzig, mit dieser tollen anleitung war es mir nach kanpp 20 minuten (mit der dl zeit von mysql etc.) tippen möglich alles perfekt zum laufen zu bringen. deinen sarkasmus und son kram kannste dir sparen...*grml*
 
Zuletzt bearbeitet von einem Moderator:
Tja...habe alles so gemacht, wie es im Tutorial steht und leider läuft php bei mir nicht. Habe 3-4 mal die httpd.conf und php.ini überprüft und es scheint alles in Butter zu sein. Aber php-skripte laufen nicht. Hat jemand mal einen Tip.

Laut Log startet apache mit PHP support. Nur wo liegt das Problem? Bin solangsam ratlos.

Die Einträge
Code:
AddType application/x-httpd-php .php .php3 .htm .html .inc
DirectoryIndex index.html index.php
stehen in der httpd.conf

Auch in der php.ini habe ich den include_path passend gesetzt.

Am chroot liegt es auch nicht, dass habe ich auch schon getestet.

Hat jemand mal einen Tip?
 
Zuletzt bearbeitet:
bossk schrieb:
Laut Log startet apache mit PHP support. Nur wo liegt das Problem? Bin solangsam ratlos.

Wie ich schon geschrieben haben steht das Modul drin.
Code:
LoadModule php4_module        /usr/lib/apache/modules/libphp4.so
 
Markie schrieb:
(...)
Add php types in Apache

code:
--------------------------------------------------------------------------------
#pico /var/www/conf/httpd.conf

AddType application/x-httpd-php .php .php3 .htm .html .inc

DirectoryIndex index.html index.php
--------------------------------------------------------------------------------

(...)


Warum alle .htm(l) Dateien durch den PHP Parser jagen? Das hat bei mir
die Ladezeiten von schlichten HTML-only Seiten hochgetrieben; ist allerdings schon gut lange her.
 
Weil ich leider ein total tolles CMS nutzen muss!
Darum komme ich auch leider mometan nicht herum. Leider
 
Mal ne Frage zu phpMyAdmin:
Hab es mir mit pkg_add installiert und musste leider festestellen, dass es nach /var/www/phpMyAdmin installiert wurde, obwohl der default DocumentRoot vom Apache /var/www/htdocs ist. Hab es deswegen (wies bei der Installtion geschrieben steht) mit einem

ln -s /var/www/phpMyAdmin /var/www/htdocs/phpMyAdmin

probiert an die richtige Stelle zu rücken, allerdings funktioniert es nicht. Wenn ich drauf gehe kommt immer ein 404 (hab auch auf Groß- und Kleinschreibung geachtet) oder ich werde auf http://hostname.domainname/phpMyAdmin weitergeleitet, was in einem "Server nicht gefunden" endet. Ich habe auch die Gruppe von phpMyAdmin-Ordner geachtet.
An was kann das liegen bzw. was habe ich falsch gemacht?
 
Oh ha, ne zwei Jahre alte Leiche ausgebuddelt...

Folgt Dein Indianer Symlinks? Der Link braucht ebenfalls die richtigen Rechte, nicht nur das Zielverzeichnis...
 
Ich meine das geht okay weil ich mich ja auch größtenteils an das Tutorial gehalten habe.

Also hab jetzt source und destionation directory an die richtige Gruppe übergeben und es kommt ein 404. In meiner httpd-conf steht zum Thema symlink folgendes:

Code:
<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>
 
das reicht nicht, es muß ein alias angegeben werden

Beispiel:
Alias /test/ /usr/local/mydocs/test/
<Directory /usr/local/mydocs/test>

phpMyAdmin gehört eigentlich nicht unter htdocs
 
Gesagt, getan:

Code:
Alias /phpMyAdmin /var/www/phpMyAdmin
<Directory /var/www/phpMyAdmin>
        Order allow,deny
        Allow from all
</Directory>

Dennoch funktioniert es nicht. :(
Wie gesagt, /var/www/phpMyAdmin und /var/www/htdocs/phpMyAdmin gehören auch beide der richtigen Gruppe an.
 
ich habs jetzt auch nicht genau im Kopf,
Alias /phpMyAdmin/ /var/www/phpMyAdmin/

mit dem Alias funktioniert, hängt an der Schreibweise der / ... hatte schon das gleiche Probs
 
Zurück
Oben