MySQL Server and PHP
daniel Sun, 08/27/2006 - 9:15pm
PHP server
The install for php is very simple. All you need to do is add the following package to OpenBSD to get php to work with apache and mysql.
pkg_add ftp://some.openbsd-mirror/.../php4-mysql-4.3.8.tgz
Copy over the recommended php configuration from the php documentation to the web server's configuration files.
#cp /usr/local/share/doc/php4/php.ini-recommended /var/www/conf/php.ini
Now enable the php server.
#/usr/local/sbin/phpxs -s
Enable mysql module of php.
#/usr/local/sbin/phpxs -a mysql
In /www/conf/httpd.conf, uncomment, and add .html to end of line where
AddType application/x-httpd-php .php .html
MySQL Server
MySQL server is a bit more difficult to configure. I installed mysql using Nomoa as a reference. There are some points where I deviated. Check both out!
Install the mysql package using pkg_add.
pkg_add /[path-to-package]/mysql-server-[version#].tgz
The package automatically creates the user '_mysql' (on my system with uid 502) and group '_mysql' (gid 502) which are used for running the sql server.
Setting the Library Configuration
Somewhere in the life of mysql development, the libraries were moved from /usr/local/lib to their own directory /usr/local/lib/mysql. Because of this, we need to specify its location for the machine startup routines. We make these changes in rc.conf.local by modifying the reference to shlib_dirs: Edit rc.conf.local and add the following line.
shlib_dirs="$shlib_dirs /usr/local/lib/mysql" # extra directories for ldconfig
I recommend copying a basic config file from the mysql support files to /etc/mf.cnf. This isn't necessary though, the machine will just use the defaults without the file. There are different files in this directory to optimize mysql for different uses. I chose mysql for medium use.
cp /usr/ports/databases/mysql/w-mysql-3.23.42/mysql-3.23.42/support-files/my-medium.cnf /etc/mf.cnf
Setting the Password
Priority 1: Set the root access password for the database. Temporarily start mysql. /usr/local/bin/mysqld_safe &
Then issue the following commands:
/usr/local/bin/mysqladmin -u root password 'new-password'
/usr/local/bin/mysqladmin -u root -h computer.domain.com password 'new-password'
From mysql manual under "after setup to do list": Security Notice: MySQL installs anonymous login access from the localhost with its default installation, you may or may not consider this a security issue. If you do consider it a problem then you can remove the anonymous access by using commands similar to that shown below:
# /usr/local/bin/mysql -u root -p
Enter password: mypassword
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6 to server version: 3.22.32
Type 'help' for help.
mysql > use mysql
mysql > delete from user where user = "";
Query OK, 2 rows affected (0.08 sec)
Testing the installation.
Verify the server is running by using the 'fstat' in the following example:
fstat | grep "*:" | grep mysql
Should display the following:
_mysql mysqld 22190 5* internet stream tcp 0xd0bc25a4 *:3306
Now we know through fstat that the mysql daemon (mysqld) is running with user privileges of _mysql and listening on port 3306.
Can we access the server?
Our first test for validating the installation is to access the MySQL database server and look at the server maintenance database 'mysql.' We log in to the system through mysql interactive interface to the server.
# /usr/local/bin/mysql -u root -p
Enter password: mypassword
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5 to server version: 4.0.18
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
The mysql> prompt allows sql statements and MySQL commands to be entered. Most commands are completed by using the ";" semi-colon delimiter. We check whether the initial database creation was successful (mysql, and test.) Use the show databases; command. The MySQL package should have successful created the system database 'mysql' and a sample database 'test'.
mysql> show databases;
+----------+
| Database |
+----------+
| mysql |
| test |
+----------+
We can check whether the mysql database has been installed by looking at the installed tables which should look like the below.
mysql> use mysql;
mysql> show tables;
Grabbing a set of information from the user table lets us see who has been given access to the system. The machine I have mysql installed on is called iwill, and you should see a similar result to the select query on your machine. Note the "blank" users is used by mysql for 'anonymous' and at the beginning only --user=root has privileges to do anything on the system. Note that the password field is encrypted with a one-way encryption system similar to but not the unix crypt() function.
mysql> select host, user, password from user;
+-----------+------+------------------+
| host | user | password |
+-----------+------+------------------+
| localhost | root | 162eebfb6477e5d3 |
| iwill | root | |
| localhost | | |
| iwill | | |
+-----------+------+------------------+
mysql> quit
Starting MySQL with each start-up.
To configure OpenBSD to automatically start mysql add the following to rc.local.
After the 'starting local daemons' and before the following echo '.', Insert the following:
if [ -x /usr/local/bin/mysqld_safe ]; then
echo -n " mysqld"
/usr/local/bin/mysqld_safe --user=_mysql --log &
sleep 4
rm -f /var/www/var/mysql/mysql.sock
ln -f /var/run/mysql/mysql.sock /var/www/var/run/mysql/mysql.sock
fi
I have found that installing phpMyAdmin made mysql much easier to manage. Try it! Or install the package!
- Log in to post comments