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? |
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. |
Quote:
|
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"; ?> |
Quote:
|
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 |
If You haven't php-mysql then no connection will be created.
Run as root: yum install php-mysql |
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 |
@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? |
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
|
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? |
Quote:
|
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"); 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. |
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. |