Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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!");
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?
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"
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
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.
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.
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.
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
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.
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: 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.
Last edited by Carl Filby; 04-24-2010 at 12:27 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.
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)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.