Contact us

Installing Apache, PHP, and MySQL

We must take note that in OpenBSD Apache web server is running in chroot jail this will give us a hard time with MySQL to function properly with Apache. This guide will help us in having a work around with this issue.

First we need to install the following packages with its Corresponding command directives.

  • pkg_add p5-DBI-<version>.tgz
  • pkg_add autoconf-2.52p0.tgz
  • pkg_add mysql-server-<version>
  • pkg_add p5-DBI-<version>
  • p5-DBD-mysql-<version>
  • pkg_add libiconv-<version>
  • pkg_add gettext-<version>
  • pkg_add recode-<version>
  • pkg_add php4-core-<version>

[mylogin@hostname folder]# /usr/local/sbin/phpxs -s

[mylogin@hostname folder]# cp /usr/local/share/examples/php4/php.ini-recommended /var/www/conf/php.ini

 

  • [mylogin@hostname folder]# pkg_add php4-mysql-<version>[mylogin@hostname folder]# /usr/local/sbin/phpxs -a mysql

Install additional packages:

  • [mylogin@hostname folder]# pkg_add php4-mcrypt-<version>
    [mylogin@hostname folder]# /usr/local/sbin/phpxs -a curl
    [mylogin@hostname folder]# /usr/local/sbin/phpxs -a mcrypt
  • [mylogin@hostname folder]# pkg_add php4-mhash-<version>
    [mylogin@hostname folder]# /usr/local/sbin/phpxs -a mhash
  • [mylogin@hostname folder]# pkg_add php4-imap-<version>
    [mylogin@hostname folder]# /usr/local/sbin/phpxs -a imap
  • [mylogin@hostname folder]# pkg_add php4-domxml-<version>
    [mylogin@hostname folder]#/usr/local/sbin/phpxs -a domxml
  • [mylogin@hostname folder]# pkg_add php4-pear-<version>
  • [mylogin@hostname folder]# pkg_add php4-gd-<version>
    [mylogin@hostname folder]# /usr/local/sbin/phpxs -a gd
  • [mylogin@hostname folder]# pkg_add php4-curl-<version>
  • [mylogin@hostname folder]# pkg_add p5-Net-SSLeay-<version>

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

[mylogin@hostname folder]# mkdir /var/www/php

[mylogin@hostname folder]# mkdir /var/www/php/includes

[mylogin@hostname folder]# cp -pR /usr/local/lib/php/* /var/www/php/includes

Now edit the var in /var/www/conf/php.ini

;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;

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

Add php types in Apache /var/www/conf/httpd.conf

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

DirectoryIndex index.html index.php

Apache Chroot jail

The default install of Apache runs inside a chroot(2) jail, which will restrict PHP scripts to accessing files under /var/www. You will therefore need to create a /var/www/tmp directoryfor PHP session files to be stored, or use an alternative session backend.

[mylogin@hostname folder]# mkdir -p /var/www/tmp

[mylogin@hostname folder]# chown -R www /var/www

MySQL's default socket location is in /var/run/mysql/mysql.sock. This causes a problem sinceapache can't "see" the /var/run directory. To overcome this, we need to make a hard link tothe mysql.sock socket file.

[mylogin@hostname folder]# mkdir -p /var/www/var/run/mysql

[mylogin@hostname folder]# ln -f /var/run/mysql/mysql.sock /var/www/var/run/mysql/mysql.sock

Edit /etc/rc.conf.local

# apache with ssl support
httpd_flags="-DSSL"
# this enable mysql to start
mysql=YES

Edit /etc/rc.local reboot after adding this lines

#### MySQL ####
if [ X"${mysql}" == X"YES" -a -x /usr/local/bin/mysqld_safe ]; then
echo -n " mysqld"; /usr/local/bin/mysqld_safe --user=_mysql --log --open-files-limit=256 &
for i in 1 2 3 4 5 6; do
if [ -S /var/run/mysql/mysql.sock ]; then
break
else
sleep 1
echo -n "."
fi
done
# Apache chroot Settings
mkdir -p /var/www/var/run/mysql
sleep 10
ln -f /var/run/mysql/mysql.sock /var/www/var/run/mysql/mysql.sock
fi

####

MySQL configuration

/usr/local/bin/mysqladmin -u root password mypassword

Test if you can logon to mysql server as root user

mysql -uroot -p

Make a test files

vi /var/www/htdocs/phptest.html

add the lines:

<?php
phpinfo();
?>

vi /var/www/htdocs/mysql.php

add this lines:

<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'test';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
echo "Connection to MySQL is OK";
?>

If will there are some DNS errors, you will need to do the following :

mkdir /var/www/etc

cp /etc/resolv.conf /var/www/etc

 

MySQL after install

Please remember to set password of the MySQL root user in-order to avoid errors.

To do so, start the server, then issue the following commands:

/usr/local/bin/mysqladmin -u root password 'new-password'

/usr/local/bin/mysqladmin -u root -h hercules.booom.com.ph password 'new-password

That's it...

Bookmark and Share RSS News Feed