Click to See Complete Forum and Search --> : Configuring PHP 4 to work with MySQL


Prionic
12-11-2003, 12:45 AM
I'm having a problem. I am using RedHat 9.0 with the basic server instalation. I have gotten Apache up and running and now I am trying to install phpBB2 forums on my server but the problem is I can't get php to access MySQL. I didn't install PHP myself, it was with the instalation on RedHat but I did download and try instaling PHP and unfortunatly, I didn't have the compliers required to do so. So basicly doing the ./config --with-mysql option won't work for me. Does anybody have a solution or could you offer any insight on how I might get this to work?

theN
12-11-2003, 03:09 AM
Hi

Did you install all the RPMs?

Search on Google for all the RPMs you need to install (or) use your Red Hat CDs and install all RPMs including the *-devel RPMs too.

BTW, do you have a working Apache?

regards
akr

Prionic
12-11-2003, 03:19 AM
Thanks for the quick response! Yes, Apache is working, PHP is working, and MySQL is working, just they're not working together. I've tried to install the necesary files so that I could compile my own PHP using the --with-mysql argument but I can't seem to get that to work either (keep getting errors for dependicies and when I try to install the dependicies they have dependencies ans so on and so forth). If anybody could let me know where to get the necesary RPMs that would be great. Thanks again!

theN
12-11-2003, 09:12 AM
Hi

Download synaptic-0.42-1.fr.src.rpm (http://ftp.freshrpms.net/pub/freshrpms/redhat/9/synaptic/synaptic-0.42-1.fr.src.rpm). Synaptic is a front-end to Apt.

Install as root. Its very easy to use.

regards
akr

Prionic
12-11-2003, 04:00 PM
Well, I managed to get ProgreSQL working with PHP (I think) by restarting Apache. I don't get the configuration error anymore, now I get:

Warning: pg_connect() unable to connect to PostgreSQL server: FATAL: user "apache" does not exist in /web/phpBB2/db/postgres7.php on line 79
phpBB : Critical Error

Could not connect to the database

That's when I try to access the DB through PHP in phpBB2. I have tried different usernames, passwords, creating new ones, making a new DB, but I still can't connect. I'm sure there's something I'm doing wrong but I can't figure it out. Thanks again for all your help.

theN
12-12-2003, 02:39 AM
Hi

Please post the relevant lines of code from 'postgres7.php'. Lets see if we can indentify the problem :)

regards
akr
PS: when ever you're posting a problem with your code, make sure you post the problem-causing code too.

Prionic
12-12-2003, 04:37 PM
Thanks, but I managed to fix it! Turns out I needed to allow tcp/ip connections in the PostgreSQL config file as well as set my IP address to host. Everything works great now (except my server sucks and I start lagging with 20 users online, but that's not Linux's fault). Thanks again, I didn't think I'd ever get this thing working.

crow2icedearth2
12-15-2003, 09:39 AM
im also trying to get PHP to work with MYSQl

i have my webserver with PHP and apache installed then i have my database server wtih mysql. im trying to connect them together using php

how would i go about doing this any good documents for connecting two servers ?

db369
12-15-2003, 12:40 PM
to see whether php was installed with mysql support, try creating a file, call it test.php, with the following:

<?php
phpinfo();
?>

then load the file in your browser -- scroll down and look for mysql.

if its there, then chances are you didn't create a user with appropriate permission for the mysql database the phpbb (or whatever app you're using).

if you're new to mysql, i'd recommend using phpmyadmin. it's relatively quick and easy to set up. just read the config instructions.

also, what version of apache are you using? if php is not configured to support mysql, you may need/want to download the apache source files.... not sure though. i needed them, but i installed the latest version of apache, php, mysql and openssl from source on a debian platform. it was actually quite easy too. maybe thats worth a shot.

hope this (rambling) was helpful...

crow2icedearth2
12-15-2003, 12:45 PM
yeah i have two server machines i want one with php,apache, and the other server to run mysql .....
im running

apache 1.3.29

and i compiled it and it works
and compared php

how do i compile php to work with my mysql server becasuse php when compliled u have to tell give it the path to the mysql database

./configure --with-mysql=/path --with-apxs=path


i run slackware 9.1 on both machines

thanks

db369
12-15-2003, 12:59 PM
i'm not sure. when i compiled it, i used the --with-mysql tag without specifying the path. i think, in that case, php compiles with internal mysql headers. perhaps that's worth a try for you.

also, did you try phpinfo()? that way you can confirm that the php install is the problem and not your mysql user.

crow2icedearth2
12-15-2003, 01:06 PM
yes i did that and it works
php is working mysql and apache

db369
12-15-2003, 01:11 PM
fantastic! hope i helped! have fun with it!

crow2icedearth2
12-15-2003, 01:30 PM
im getting this error when i try to connect to the mysql server

Warning: mysql_connect(): Host '192.168.1.104' is not allowed to connect to this MySQL server in /www2/installed/apache_1.3.29/htdocs/db_connect.php on line 2
Host '192.168.1.104' is not allowed to connect to this MySQL server

db369
12-15-2003, 01:41 PM
ah. now again, i'm not sure as i'm pretty new to this too, but when you create a user to connect to the database, you have to select the host. if you don't, it either defaults to 'localhost' or the pc's hostname. you might try reconfiguring the user and specify the host as '192.168.1.104'.

this page might be helpful (http://www.mysql.com/doc/en/Adding_users.html). i find phpmyadmin incredibly helpful (considerably les comlicated) with these things though.

crow2icedearth2
12-15-2003, 03:02 PM
i still have no clue to how to get them to work with each other ...

i have two servers

server 1 ( slackware9.1 , apache and php compiled from source with php compilied with mysql support) that server works ok php and apache both work


server 2 ( slackware 9.1 mysql compiled.........



i cant get them to connect
what steps do i need to take to get them to work with each other as well as what php script should i write to test it ?

both servers work independate of each other...... all the docs i read on with php,apache and mysql set up on the same machine and i dont want that setup.....

any help or good documents on what i want to do would be a big help

db369
12-15-2003, 03:23 PM
try this:

1) add a new user using the process described in the link i provided earlier. there's an example there, only instead of using 'monty@localhost', use 'monty@192.168.1.104' where 'monty' is the username of your choice. also, instead of granting all proviledges on *.*, just use 'test', which is created when you first install mysql.

2) follow the process here (http://www.mysql.com/doc/en/Creating_tables.html) to create a table in the 'test' database.

3) try using the example here (http://us4.php.net/manual/en/ref.mysql.php) to try to access it.

-or-

just set up whatever app you're using to use that username/pw/host.

good luck!

theN
12-16-2003, 03:47 AM
Hi

crow2icedearth2 check the GRANT syntax in the MySQL manual. Thats exactly what you're looking for.

Just to give you a general idea -

GRANT ALL | [privileges_list] on 'some_database'.* TO 'some_user'@'some_ip_address' IDENTIFIED BY 'some_password'

strings like host name, user name, database name etc. are single-quoted for convenience.

Hope you get the picture.

regards
akr
PS: You should've started a new thread!! would've got more attention :)

crow2icedearth2
12-16-2003, 07:41 AM
thanks ill check it out and try to get it working today....

crow2icedearth2
12-16-2003, 06:04 PM
still no luck i cant ge the grant command to do anything give me errors

crow2icedearth2
12-16-2003, 06:17 PM
THANKS GUYS I FINALLY GOT IT TO WORK !! took some work ..... i have to read the mysql manual guide to see how it works ..... any good ideas on any good books for it

theN
12-17-2003, 03:17 AM
Hi

Please do tell how you solved the problem. We can go back and maybe identify the problem (for posterity's sake).

BTW, did you issue GRANT as mysql-root?

regards
akr

crow2icedearth2
12-17-2003, 04:51 AM
i didnt issue the grant statement as mysq-root i set up another user and did it from that user..... it works fine now

theN
12-17-2003, 09:16 AM
Hi

IIRC on a default install of MySQL, the mysql-root is only user with the GRANT privilege i.e. he's the only one capable of GRANTing privileges to another user.

BTW, GRANT is also used to add a user!

Good that you got your problems sorted our :)

regards
akr