Doing It With Debian
Debian is my favorite distribution because of the control it allows me over what packages are installed. It is also one of the more challenging packages to get installed. In the case of PHP it is complicated by some incorrect entries in the Debian 2.1 (slink) /etc/php/apache/php.ini configuration file.
The Packages
This is not a file on how to install Debian. I am going to assume you are basically familiar with the "dselect" program and have somehow managed to get Apache or some other HTTP server installed. First, you will have to add the MySQL database and the PHP support. Here are the packages you will have to install. The "dselect" package will take care of the dependant packages, but this is the minimum of what you will need.
For MySQL
Package: mysql-server Depends on: mysql-base, libc6, libstdc++2.9
For PHP with Apache
Package: php Depends on: libc6, libgdbmg1, zlib1g, mime-support, apache Package: php-mysql Depends on: php, libc6, mysql-base
For PHP with some other web server or Apache as CGI
Package: php-cgi Depends on: libc6, libgdbmg1, zlib1g, mime-support Package: php-cgi-mysql Depends on: php, libc6, mysql-base
Configuration
Once you get the packages installed and configured you are almost ready to go. There are two files you will have to edit to get the PHP support in Apache. The first one is the Apache configuration file /etc/apache/httpd.conf where you will have to find and uncomment the following line:
LoadModule php_module /usr/lib/apache/1.3/libphp.so
The second is the PHP configuration file. It is located at /etc/php/apache/php.ini -or- /etc/php/cgi/php.ini depending on whether or not you are going to run it as an Apache module or as a CGI program. In either case, look for the following line in the file and change it to match the line below it.
;extension=php_mysql.so extension=mysql.so
You will want to verify that the php .php and .phtml extensions are configured in the /etc/apache/srm.conf configuration file. Mine were, but if I misremember check for yourself. It is certainly in there, but it may be commented out. Next time I do a clean install I'll check.
Restart Apache
Lastly, go to the /etc/init.d directory and run:
./apache restart
This will restart the Apache server and should allow you to use PHP and MySQL. The following code will allow you to test it.
<HTML> <HEAD> <TITLE>PHP Test</TITLE> <BODY BGCOLOR="white"> <? = phpinfo(); echo ; ?> </BODY> </HTML>
The code generates this page of detailed information which proves useful in more ways that testing if PHP works. Look for the section called "MySQL" in the "Extensions" area. If you see it you are in good shape.
Database Accounts
On the Pair Networks database servers they create three accounts for your use to allow for secure access to your database. One account has full control over the database and allows you to create and delete tables as well as select, insert and update data. The second account can only perform select queries and the last account is only allowed to write or update date. The reasoning is that by using the most restrictive account to do a particular task you lessen the degree of havoc you can wreak if the code does something unexpected.
Database Account Creation
Since most of the appications I develop will end up running on Pair Networks servers, I duplicate this structure on my systems. Creating accounts and defining permissions is as easy as inserting data into a database, because that is all there is to database securing.
You will have to use the 'mysql' program or a replacement GUI manager to issue these commands. The command line to use the mysql program is:
mysql -uroot -ppassword mysql
This connects to the database service and selects the database called 'mysql'. It contains 4 tables used to manage access to the other databases created. The tables are 'user', 'db', 'host', and 'func', but I have never actually used the 'func' table for anything.
The user table defines user names and passwords for authentication purposes and has a set of defined permissions that can be applied globally to all databases. Typically, all the permissions are left as "No" in the 'user' table because you want to assign permissions based to each database individually. The commands to create a new user account and password is:
INSERT INTO user (host,user,password) VALUES('%','username_r',PASSWORD('password'));
INSERT INTO user (host,user,password) VALUES('%','username_w',PASSWORD('password'));
INSERT INTO user (host,user,password) VALUES('%','username',PASSWORD('password'));
The PASSWORD() function generates a DES encoded string that is stored in the database and is used to check that the same password was given when a password is required. The passwords issued by pair are different in each account. The next set of statements are equivilent, but depending on what versions of MySQL you are using, the GRANT function may not actually work. I tend to use the INSERT function statements just to avoid it issue since they will work on any version.
Older or Newer Versions of MySQL
INSERT INTO db (host,db,user,Select_priv) VALUES('%','database','username_r','Y');
INSERT INTO db (host,db,user,Insert_priv,Update_priv) VALUES('%','database','username_w','Y','Y');
INSERT INTO db VALUES('%','database','username','Y','Y','Y','Y','Y','Y');
Newer Versions of MySQL Only
GRANT SELECT ON tator_awtrey TO tator_r; GRANT INSERT,UPDATE ON tator_awtrey TO tator_w; GRANT ALL ON tator_awtrey TO tator;
Once you have successfully added these entries it it necessary to tell the MySQL service to reload the authentication tables. To do that you must issue this command from the commandline, not within the mysql program:
mysqladmin -uroot -ppassword reload
This will allow the new accounts and permissions to take effect. I recommend trying to connect and select the database in question to verify it works before spending time programming in PHP. The command to do that is:
mysql -uusername -ppassword database
Try it with each account (admin, read-only and write-only) to make certain a problem that appears later is not caused by a simple authentication issue.