LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Installing and configuring LAMP using yum (https://www.linuxquestions.org/questions/linux-server-73/installing-and-configuring-lamp-using-yum-803197/)

paulsm4 04-22-2010 09:55 PM

Hi -

Cool - thanx for the followup!

Here's where we're at:
Quote:

1. Of the million different things that *could* have been going wrong, we've narrowed the problem down to "mysql logon". We've verifies that mySQL, PHP and Apache are all OK; we've verified that you've got valid data, and we've verified that you can access that data from the mysql client. That's all progress - cool :)

2. The main things I tried to show in my last example were:
a) setting up the database (I kind of guessed you already had that squared away ... but I didn't want to "assume" anything ;))

b) calling mysql from PHP (a "simple as possible" example)

c) PHP error handling (the "or die()" stuff)
... and ...
d) "Simple as possible" HTML (no tables: just text and "<br/>" tags)
Try this:
1. Please just use "localhost" as the server name (you'll recall everything is on the same PC. "Localhost" is an alias for the loopback address, 127.0.0.1).

2. Use your simple login name (instead "server-or-ip@name").
EXAMPLE: let's say your login is "fred", and your password "flintstone". Please try this:
Code:

  $conn = mysql_connect("localhost", "fred", "flintstone")
    or die ("mysql_connect failed!");

'Hope that helps .. PSM

tklMe 04-22-2010 11:56 PM

PaulSM4: I actually did try it with just localhost and not server2.lambott.local and that didn't work.

I also used the drop command to remove the other user. I then just added tklamb without the IP. Granted all the privileges and then used the Flush command. (so a simple user name with a simple password)

AMP is installed on the same virtual machine, however, I am logging into it from a different machine. Regardless it doesn't work on either system. And just to make certain I opened up the browser on server2 and tried to connect. Got the same message regardless of whether I used server2.lambott.local or localhost.

Is there anything else you can suggest for me to try?

paulsm4 04-23-2010 12:52 AM

Hi -

EXAMPLE:
hostname: bedrock
username: fred
password: flintstone
test file: test.php

1. Q: PHP, Apache, and MySQL are all running on "bedrock", correct?

2. Q: does it work if you
a) log in to "bedrock" as user "fred"?
b) mysql -ufred -pflintstone cats
<= Q: are you able to log on to database "cats" this way, on this server?
c) select * from mine;
<= Q: do you see the expected data?

3. While you're in mysql, also do this:
use mysql;
select Host,User from user;
<= Make sure User "fred" is in here, with Host "localhost" or "%"

4. Find out what user your Apache server is running as
EXAMPLE: "ps -eaf|grep http", or "ps -eaf|grep apache"
<= Usually, the Apache user will be "nobody"

Verify that user (e.g. "nobody" belongs to the group "mysql")
EXAMPLE: "groups nobody"
<= should return "mysql" as one of the groups

5. Change your PHP code ("test.php") to this:
Code:

$conn = mysql_connect("localhost", "fred", "flintstone")
    or die ("mysql_connect failed!");

Save and exit.
Double-check the PHP file to make sure it's changed.

6. Point your browser to "http://bedrock/test.php"
Be sure to "refresh" every time you change and save "test.php"

7. Report back what you find.

'Hope that helps .. PSM

Blue_Ice 04-23-2010 07:46 AM

I would use mysql_error() instead of your own custom message. This way we get the actual MySQL error. Although I am not sure if it works this way...

Quote:

Originally Posted by paulsm4 (Post 3944846)
5. Change your PHP code ("test.php") to this:
Code:

$conn = mysql_connect("localhost", "fred", "flintstone")
    or die (mysql_error());

Save and exit.
Double-check the PHP file to make sure it's changed.

Are you sure that you need to add user nobody to the group mysql? I never do that. Seems to be a bit pointless as MySQL runs with its own user. Apache or actually I should say php contacts MySQL as a client, not as a daemon. I don't know what adding nobody to the mysql group implies for the security of MySQL.

The rest is a good procedure to follow, of course.

Please also check the MySQL log. Usually it can be found at /var/log/mysqld.log.

paulsm4 04-23-2010 09:43 AM

C'mon Blue_ice: I'm just trying to cover all the bases to get tklMe going as quickly as possible: just trying to make sure we leave *nothing* to chance.

Yes, I would definitely recommend adding the Apache user (which may or may not be "nobody" on his system) to the "mysql" group.

And yes, looking at /var/log/mysqld.log is also a good idea. Looking at /var/log/messages and the Apache access and error logs wouldn't hurt, either ;)

But the main thing is to make sure the combination of "host" and "username" he's using exactly matches a "Host/User" logon tuple in his MySQL "user" table.

And that was the main gist of my suggestion.

IMHO .. PSM

Blue_Ice 04-23-2010 11:45 AM

Of course, you are right... I was just wondering why you added the apache user to the mysql group, as both can be on different machines. Maybe I have expressed myself in a wrong way. Sorry for that...

Actually, the die(mysql_error()) part is pretty interesting as it might return useful information on why the connection failed. Log files are interesting as well. We have never asked for it and tklMe hasn't posted it either.

paulsm4 04-23-2010 01:23 PM

Hi again, Blue_ice -

The reason I suggested adding the Apache user to the mysql group is because it's possible to get a "can't open socket /var/lib/mysqld.sock" error unless the filesystem permissions (i.e. Linux group memberships) line up. Not saying it *is* what's happening - but definitely saying it *can* be an issue. And that it's no sweat to resolve (simply make sure the Apache user belongs to the mysql group).

And yes, I totally agree about adding "mysql_error()" to the user-defined error message - great suggestion :)

Your .. PSM

PS:
TklMe - good luck, and keep us posted!

tklMe 04-23-2010 07:30 PM

PaulSM4:

1. Q: PHP, Apache, and MySQL are all running on "bedrock", correct? --> yes, if by bedrock you mean server2.lambott.local which is the hostname listed in the network configuration screen.

2. Q: does it work if you
a) log in to "bedrock" as user "fred"? --> into server2.lambott.local as tklamb, yes

b) mysql -ufred -pflintstone cats
<= Q: are you able to log on to database "cats" this way, on this server?--> no
c) select * from mine;
<= Q: do you see the expected data? --> only if I log in without the above and change to the database and then select the table.

3. While you're in mysql, also do this:
use mysql;
select Host,User from user;
<= Make sure User "fred" is in here, with Host "localhost" or "%"-->user tklamb is listed with a %.

4. Find out what user your Apache server is running as
EXAMPLE: "ps -eaf|grep http", or "ps -eaf|grep apache"
<= Usually, the Apache user will be "nobody" --> all this is showing me is either root or apache not sure where it is suppose to show me a user. Remember I am new to this stuff.

Also, I tried blueice's suggestion and changed the error code to the mysql_error() and I'm either getting an "access denied" or an "unknown MySQL server host" error depending on whether I am logging in under localhost or server2.lambott.local. The localhost (even if I try to log in as root) will give me the access denied and the server2.lambott.local will give me the unknown server error.

paulsm4 04-23-2010 09:11 PM

OK - please go into mysql and cut/paste the output of these commands:

Quote:

use mysql;
select Host,User from user;

tklMe 04-23-2010 11:18 PM

PaulSM4: I am going to start from scratch and install from source. Hopefully this will fix the issue I am having.

Carl Filby 04-23-2010 11:44 PM

OP
I am not by any definition of the word a php man or webmaster but I do see a couple discrepancies in your php code
http://www.linuxquestions.org/questions/attachment.php?attachmentid=3409&d=1271893671

echo " <td>{$row[age]}</td>\n";
echo " <td>{$row[id]}</td>\n";

"age" & "id" are not in quotes like name & sex is. Could that explain why execution of your script is failing to produce output after first table.

tklMe 04-24-2010 12:18 AM

Carl: I actually did try without the quotes but that didn't work either. Installing mysql from an rpm has proven to be a pain in the arse. The mysql command comes back with an error. Where the heck did it put this program? AAARRRGGGHHH!

Carl Filby 04-24-2010 12:23 AM

Quote:

Originally Posted by tklMe (Post 3946026)
Carl: I actually did try without the quotes but that didn't work either. Installing mysql from an rpm has proven to be a pain in the arse. The mysql command comes back with an error. Where the heck did it put this program? AAARRRGGGHHH!

Ok
good luck and keep us posted..I am bookmarking this thread to monitor.
I am particularly interested because I testing out Centos 5.4 now. I took a class on org RedHat back in 2004 but this is different lol.

Blue_Ice 04-24-2010 12:54 AM

By default you cannot log in with root on a server remotely. This means the server name must be localhost when logging in. To see if your other usesers have access to the server, you have to run 'select Host,User from user;' as suggested by paulsm4.
The unknown server error could mean that it was not possible to resolve the computername, so you might want to try the ipaddress there.

tklMe 04-24-2010 01:48 AM

PaulSM4: I gave up on the source install...too much of a headache right now. I was having issues with the mysql install and I figured I would also have issues with the ssl. So, back to the beginning. Here is the output:
mysql> use mysql;
Database changed
mysql> select Host, User from user;
+-----------------------+---------+
| Host | User |
+-----------------------+---------+
| % | lambott |
| % | tklamb |
| 127.0.0.1 | root |
| localhost | |
| localhost | root |
| server2.lambott.local | |
| server2.lambott.local | root |
+-----------------------+---------+
7 rows in set (0.00 sec)

mysql>


All times are GMT -5. The time now is 09:35 PM.