LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
LinkBack Search this Thread
Old 07-23-2010, 06:52 AM   #1
archerofthemoon
LQ Newbie
 
Registered: Mar 2010
Posts: 19

Rep: Reputation: 0
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?
 
Old 07-23-2010, 07:33 AM   #2
rsciw
Member
 
Registered: Jan 2009
Location: Essex (UK)
Distribution: Home: Debian/Ubuntu, Work: Ubuntu
Posts: 206

Rep: Reputation: 44
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.
 
Old 07-23-2010, 08:34 AM   #3
archerofthemoon
LQ Newbie
 
Registered: Mar 2010
Posts: 19

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by rsciw View Post
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.
 
Old 07-23-2010, 08:39 AM   #4
UnderV
Member
 
Registered: Mar 2010
Posts: 38

Rep: Reputation: 18
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";
?>
 
Old 07-23-2010, 09:06 AM   #5
archerofthemoon
LQ Newbie
 
Registered: Mar 2010
Posts: 19

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by UnderV View Post
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...
 
Old 07-23-2010, 09:16 AM   #6
rsciw
Member
 
Registered: Jan 2009
Location: Essex (UK)
Distribution: Home: Debian/Ubuntu, Work: Ubuntu
Posts: 206

Rep: Reputation: 44
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
 
Old 07-23-2010, 09:59 AM   #7
UnderV
Member
 
Registered: Mar 2010
Posts: 38

Rep: Reputation: 18
If You haven't php-mysql then no connection will be created.

Run as root:
yum install php-mysql
 
Old 07-26-2010, 03:02 AM   #8
thegerm
LQ Newbie
 
Registered: May 2007
Posts: 10

Rep: Reputation: 0
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
 
Old 07-26-2010, 05:41 AM   #9
Noway2
Senior Member
 
Registered: Jul 2007
Distribution: Ubuntu 10.10, Slackware 64-current
Posts: 2,120

Rep: Reputation: 776Reputation: 776Reputation: 776Reputation: 776Reputation: 776Reputation: 776Reputation: 776
@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?
 
Old 07-26-2010, 06:40 AM   #10
archerofthemoon
LQ Newbie
 
Registered: Mar 2010
Posts: 19

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Noway2 View Post
@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 View Post
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 View Post
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 View Post
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 View Post
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 View Post
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 View Post
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 View Post
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 View Post
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.
 
Old 07-26-2010, 08:25 AM   #11
UnderV
Member
 
Registered: Mar 2010
Posts: 38

Rep: Reputation: 18
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?
 
Old 07-26-2010, 08:34 AM   #12
archerofthemoon
LQ Newbie
 
Registered: Mar 2010
Posts: 19

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by UnderV View Post
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.
 
Old 07-27-2010, 04:37 AM   #13
Noway2
Senior Member
 
Registered: Jul 2007
Distribution: Ubuntu 10.10, Slackware 64-current
Posts: 2,120

Rep: Reputation: 776Reputation: 776Reputation: 776Reputation: 776Reputation: 776Reputation: 776Reputation: 776
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.
 
Old 07-29-2010, 02:54 PM   #14
archerofthemoon
LQ Newbie
 
Registered: Mar 2010
Posts: 19

Original Poster
Rep: Reputation: 0
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to seperate the mysql database from the apache host. microwaveparty Linux - Newbie 6 11-04-2009 04:59 PM
Permit an ODBC connection to my MYSQL database Squidek Ubuntu 2 08-27-2009 08:26 AM
Perl Mysql Database connection big Linux - Newbie 1 07-03-2009 12:41 AM
Apache/PHP not talking to mysql database BorgAssimilator Linux - Software 1 11-11-2005 03:12 AM
Using the MySQL Database for Authentication on Apache Server ruiseixas Linux - Security 1 03-12-2004 10:32 PM


All times are GMT -5. The time now is 04:02 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration