LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Apache Connection to MySQL Database (https://www.linuxquestions.org/questions/linux-server-73/apache-connection-to-mysql-database-821676/)

archerofthemoon 07-23-2010 06:52 AM

Apache Connection to MySQL Database
 
So I went through last week and backed up an old system that I had php script talking to some mysql databases I created. The original system was the latest version of Ubuntu with all of the files stored in /var/www. Due to some other functions I require I needed to reinstall these applications to another distro, Redhat 4.8 (this is mandatory and cannot change.) With that in mind I ran the install and tried to hop the files to the same directory to which they were on the other system. I found one issue that the php files would not execute unless in the child directory of http. But now thats working I'm running into a larger problem, the php script I have will not contact the mysql databases which I created. I have a feeling its another directory issue, but I'm not too sure about that. These scripts worked fine in Ubuntu but after the hop it seems that they won't talk. And yes, the services for Apache as well as Mysql have been started :)

Ideas?

rsciw 07-23-2010 07:33 AM

could be anything from path issues, different versions (RHEL 4.x iirc uses PHP4 and some older apache too), to file permissions, etc.

I'd check all of those, especially the differing versions compared to those on the Ubuntu box.

archerofthemoon 07-23-2010 08:34 AM

Quote:

Originally Posted by rsciw (Post 4042968)
could be anything from path issues, different versions (RHEL 4.x iirc uses PHP4 and some older apache too), to file permissions, etc.

The Ubuntu box was more or less my testing box. I had an idea and implemented it on a box I had. Ubuntu and Redhat both have the same permissions as everything being done is through the root account. Path issues are more concerning as I'm not sure what path is needed for Redhat. As for PHP, isn't it dependent on Apaches release? And the versions of Apache and MySQL can be changed with a simple run of the latest rpm, that is if it modifies the current directories rather then install new ones.

UnderV 07-23-2010 08:39 AM

Hello!
My suggestion is to check if all necessary packages are installed.
Are You sure You have installed package: php-mysql?

If packages are installed then check your MySQL server for permissions (maybe server have IP address limitations or user accounts are limited to specific IP).

You always could check connection with php:
<?php
mysql_connect("Mysql IP", "username", "password") or die(mysql_error());
echo "Connected to MySQL";
?>

archerofthemoon 07-23-2010 09:06 AM

Quote:

Originally Posted by UnderV (Post 4043026)
Are You sure You have installed package: php-mysql?

I didn't install it off the bat, no. So that might be an issue. How do you check to see if that package is installed? Through Ubuntu right off the fresh install I ran apt-get install mysql and apt-get install apache and from there it worked. I've been trying to do the same and currently am looking for an install process for apt-get and or yum. I've gone through a few procedures but apt-get fails to grab packets. And yum just hangs after the install for yum install mysql...

rsciw 07-23-2010 09:16 AM

right, forgot about php-mysql, that could be it too.

no, php is not dependent on apache releases, two completely separate projects.

which paths exactly are you talking about?
most paths are similar, but stuff like PHP PEAR have different paths on RH and Ubuntu.

doc_roots can be set through the appropriate config files

UnderV 07-23-2010 09:59 AM

If You haven't php-mysql then no connection will be created.

Run as root:
yum install php-mysql

thegerm 07-26-2010 03:02 AM

I have a similar problem on Ubuntu 10.04.
However when I try to run "apt-get install php-mysql", then system responds with -

sudo apt-get install php-mysql
[sudo] password for da:
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Couldn't find package php-mysql

Any ideas??

thegerm

Noway2 07-26-2010 05:41 AM

@Thegerm, please start your own thread rather than posting to a similar discussion. The package your looking for is called php5-mysql, not php-mysql.

@archerofthemoon, When you performed the new install what process did you use for the packages? Also, how did you copy the database? I ask because supposedly the database is just a set of files that can be copied, but I have had poor luck with that and instead found that doing a mysql "dump" and "source" a more reliable means of creating the database.

Actually, lets take things one step at a time.
1 - Can you access web pages from the new server, i.e. is apache running?
2 - Can you create a basic PHP page and does it properly execute?
3 - Can you log into mysql via the monitor and access your data base using the root account?
4 - Can you do the same thing using the user account specified in your php files?
5 - Does your application require any PEAR plugins, like mail, that may be missing?
6 - I was reading that a lot of applications broke with the recent release of php5.3 as certain things got deprecated. This appears to be a real problem with Ubuntu. You may be having compatibility troubles. What version of PHP are you running?
7 - Are you getting any error messages when you try to execute your scripts? Make sure that errors are turned on if not.

Also, dumb question, but you are you sure your installing RPMs on the Red Hat?

archerofthemoon 07-26-2010 06:40 AM

Quote:

Originally Posted by Noway2 (Post 4045542)
@archerofthemoon, When you performed the new install what process did you use for the packages? Also, how did you copy the database? I ask because supposedly the database is just a set of files that can be copied, but I have had poor luck with that and instead found that doing a mysql "dump" and "source" a more reliable means of creating the database.

The databases were recreated after the fresh install. It was more simple to just go through and create the new databases and tables under the fresh install.

Quote:

Originally Posted by Noway2 (Post 4045542)
1 - Can you access web pages from the new server, i.e. is apache running?

Yes, all the php pages are accessible. Before trying to connect I run "service httpd start"

Quote:

Originally Posted by Noway2 (Post 4045542)
2 - Can you create a basic PHP page and does it properly execute

Depends what you mean by execute. I can access the pages by typing in the url "localhost/php_filename.php" but the php script does not interact with the databases like its suppose to. For example, one page has a login that is suppose to contact a database and record the amounts of login attempts etc etc but it doesn't record squat.

Quote:

Originally Posted by Noway2 (Post 4045542)
3 - Can you log into mysql via the monitor and access your data base using the root account?

Yes - I can access mysql through the root account as well as the accounts I created under mysql. I am able to read and write to the databases I create through the mysql command line.

Quote:

Originally Posted by Noway2 (Post 4045542)
4 - Can you do the same thing using the user account specified in your php files?

This might be the issue. How do I access this option? The only two parts I have been working with are apache and mysql. More clarification on this would be appreciated.

Quote:

Originally Posted by Noway2 (Post 4045542)
5 - Does your application require any PEAR plugins, like mail, that may be missing?

I don't believe so. The server allows remote access viewing of a specific program.

Quote:

Originally Posted by Noway2 (Post 4045542)
6 - I was reading that a lot of applications broke with the recent release of php5.3 as certain things got deprecated. This appears to be a real problem with Ubuntu. You may be having compatibility troubles. What version of PHP are you running?

Let me get back to you on that.

Quote:

Originally Posted by Noway2 (Post 4045542)
7 - Are you getting any error messages when you try to execute your scripts? Make sure that errors are turned on if not.

I've checked to see if there were any errors and nothing was logged.

Quote:

Originally Posted by Noway2 (Post 4045542)
Also, dumb question, but you are you sure your installing RPMs on the Red Hat?

I have been purely using the RPM's included in the install as I've been having other issues regarding YUM. I know I can just go out and search for RPM's but YUM usually grabs the latest release which usually reduces compatibility issues I have run into in the past.

UnderV 07-26-2010 08:25 AM

I still doesn't get answer: Have You installed php-mysql?
Under Debian based systems (for example Ubuntu) it is called php5-mysql.

You have problem on RedHat system?

archerofthemoon 07-26-2010 08:34 AM

Quote:

Originally Posted by UnderV (Post 4045702)
I still doesn't get answer: Have You installed php-mysql?

I'm trying to fix my yum application, that install is in the works.

Noway2 07-27-2010 04:37 AM

Re #4: "Can you do the same thing using the user account specified in your php files?" \

This is pretty easy to check. Using a terminal, try to access you database using the user and password specified in the PHP application. Code: mysql -u <user> -p. There is one caveat here that bears mentioning. The MySQL will automatically append @<host> to the user. Are the database and Apache on the same server? If yes, the user will automatically be <user>@localhost. If not, you will need to specify the host of the server with MySQL on it in your command as: mysql -u <user> -h <host> -p. this can get tricky if apache and mysql are on different servers, so it is best to do this from the server running Apache. Then try to do some basic operations like use <database> and show tables, select * from tables, etc, using that user. That will verify that the permissions are set up correctly. You can also look in the users table to see if the PHP user is configured correctly.

If that works, I would go into your PHP files and if it is not there already put in some checks to look at the return value of the mysql connect and database select and access functions. The easiest way to do this is to use an if like this:
Code:

if (!($connection = mysqli_connect("<host>", "<user>", "password"))) die("Cannot Connect");
which will display the message 'cannot connect' if it fails and halt the script.

You may also need to verify that php errors are turned on (they are usually off in production servers) and what the error logging level is. You can test this by deliberatly creating an error and see if you get error messages on your screen.

archerofthemoon 07-29-2010 02:54 PM

The php-mysql update fixed a majority of these issues. Now I'm just having an issue with upgrading from 4.3.X to 5.2 PHP.


All times are GMT -5. The time now is 01:23 AM.