LinuxQuestions.org
Visit Jeremy's Blog.
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
 
Search this Thread
Old 04-20-2010, 11:37 PM   #1
tklMe
LQ Newbie
 
Registered: Mar 2010
Posts: 22

Rep: Reputation: 16
Installing and configuring LAMP using yum


I have 3 virtual machines set up. 2 are servers and one is a client. On one of the servers I have installed apache, mysql, and php and mod_ssl. I can get to the web site on the server from my client system. I can even get to the info php site--the screen that shows everything about php (it's purplish!) I can also get to the secure https site. The one thing I can't do is get my table to display.

I have set up a new user in mysql. I have granted that user all privileges. I have created a table on a new database in mysql. I then set up php code within html code But every time I try to go to my test.php site it only gives me the header. It obviously cannot find the table array. This is the code and someone already told me it looked right to them. So I am not sure what I am doing wrong.

<$php
$conn = mysql_connect("server2", "user1", "password");
mysql_select_db("db1", $conn);
$sql = "SELECT * FROM tbl";
$result = mysql_query($sql, $conn);
echo "<table border= '1'>\n;
echo "<tr>\n";
echo " <td>ID</td>\n";
echo " <td>Name</td>n";
echo " </tr>\n";

while ($row = mysql_fetch_array($result)){
echo " <td>{$row["ID"]}</td>\n";
echo " <td>{$row["Name"]}</td>\n";
echo " </tr>\n";
}
echo "</table>\n";
?>

If anyone can help me with this or point me to something I can read to figure out what I am doing wrong I would appreciate it. Thanks.
 
Old 04-21-2010, 12:45 AM   #2
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Suggestion - "divide and conquer".

Try the following individual tests:
Code:
<?php
  // Test1: make sure PHP is working
  phpinfo ();
 ?>
Code:
<?php
  // Test2: make sure we see our table
  echo "<table border= '1'>\n";
  echo "<tr>\n";
  echo " <td>ID</td>\n";
  echo " <td>Name</td>n";
  echo " </tr>\n";

  echo " <td>{}</td>\n";
  echo " <td>{}</td>\n";
  echo " </tr>\n";
  echo "</table>\n";
?>
Code:
<?php
  // Test3: put it all together
  $conn = mysql_connect("server2", "user1", "password");
  mysql_select_db("db1", $conn);
  $sql = "SELECT * FROM tbl";
  $result = mysql_query($sql, $conn);
  echo "<table border= '1'>\n";
  echo "<tr>\n";
  echo " <td>ID</td>\n";
  echo " <td>Name</td>n";
  echo " </tr>\n";

  while ($row = mysql_fetch_array($result)){
    echo " <td>{$row["ID"]}</td>\n";
    echo " <td>{$row["Name"]}</td>\n";
    echo " </tr>\n";
  }
  echo "</table>\n";
?>
Use the standard "<?php ... ?>" syntax (I noticed "<$php": a typo?)

Double check to make sure you matched all quotes and double-quotes. I noticed a missing double-quote on this line: it's entirely possible this is the entire problem:
Code:
  // ERROR!  MISSING DOUBLE-QUOTE:
  echo "<table border= '1'>\n;
'Hope that helps .. PSM
 
Old 04-21-2010, 03:42 AM   #3
Blue_Ice
Member
 
Registered: Jul 2006
Location: Belgium
Distribution: Debian, Fedora, CentOS, Windows
Posts: 352

Rep: Reputation: Disabled
Stupid question maybe, but does your table contain data on the new server...? In other words have you tested the query that it returns data from server2...?

As a (database) developer, I always used stored procedures to execute queries and made sure that these worked in such a way that I don't have to do much of developing in the application (and it actually has security benefits). An added advantage is that you can return a line that says no data available.
 
Old 04-21-2010, 10:18 AM   #4
tklMe
LQ Newbie
 
Registered: Mar 2010
Posts: 22

Original Poster
Rep: Reputation: 16
I can get the phpinfo screen. I double checked and those were just typos into here. I have them typed correctly in the php/html script.I'm not seeing a table at all..just the heading--> ID and Name surrounded by a border.

Last edited by tklMe; 04-21-2010 at 10:24 AM.
 
Old 04-21-2010, 10:22 AM   #5
tklMe
LQ Newbie
 
Registered: Mar 2010
Posts: 22

Original Poster
Rep: Reputation: 16
Blue Ice: I am new to Linux and I have no clue as to how to test the query. How do I check that my table contains data on the new server? What are you referring to? I created a table and added the info and then checked it thru mysql and saw the table and info in the table. Please elaborate or point me to something I can read.
 
Old 04-21-2010, 04:01 PM   #6
Blue_Ice
Member
 
Registered: Jul 2006
Location: Belgium
Distribution: Debian, Fedora, CentOS, Windows
Posts: 352

Rep: Reputation: Disabled
Quote:
I can get the phpinfo screen. I double checked and those were just typos into here. I have them typed correctly in the php/html script.I'm not seeing a table at all..just the heading--> ID and Name surrounded by a border.
Quote:
Originally Posted by tklMe View Post
Blue Ice: I am new to Linux and I have no clue as to how to test the query. How do I check that my table contains data on the new server? What are you referring to? I created a table and added the info and then checked it thru mysql and saw the table and info in the table. Please elaborate or point me to something I can read.
I meant that you have checked if the database table contains data by executing the sql query (SELECT * FROM tbl) directly on the correct MySQL server.
To connect to the server you can use the commandline tools of MySQL. Usually these are installed when the server is installed.
Try the following:

Code:
mysql -h <hostname> -u <username> -p
Enter password: 

mysql> USE <your_database>
Database changed

mysql>SELECT * FROM tbl;
If this returns data, then that means you have everything you need on the database side. If not, then you need to insert the data. Be sure to use the correct server (mysql host).

By the way, your issue has nothing to do with linux itself. It is a problem within your database or php-code. In my previous post I asked if you had checked if there is data in the table.

When working with databases you best work in steps.
1. Load data in the database tables (if needed, use some bogus data)
2. Build and execute queries to test if data is returned.
3. Write php code to load the data and keep it simple (paulsm4 already showed how to do this).
 
Old 04-21-2010, 04:54 PM   #7
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

Quote:
I can get the phpinfo screen.
Good - an essential first step
Quote:
I double checked and those were just typos into here. I have them typed correctly in the php/html script.
Good - if the syntax is wrong, you won't see anything (except maybe an error msg - if you're luck )
Quote:
I'm not seeing a table at all..just the heading--> ID and Name surrounded by a border.
This means that you ARE seeing your table.

The table just doesn't have any data in it .

Which goes back to what Blue_Ice has been trying to tell you:

* Check the database: make sure it has data (even bogus data)
* Double-check your PHP query
* Double-check your PHP results

'Hope that helps .. PSM
 
Old 04-21-2010, 04:59 PM   #8
tklMe
LQ Newbie
 
Registered: Mar 2010
Posts: 22

Original Poster
Rep: Reputation: 16
Blue Ice: yes, I can see the data in the table. I will double check my code again. Thanks.
 
Old 04-21-2010, 06:56 PM   #9
tklMe
LQ Newbie
 
Registered: Mar 2010
Posts: 22

Original Poster
Rep: Reputation: 16
I am going to attach what I have. Unfortunately they are just screen shots. I'm sure the error is somewhere in the database/how I am creating my user. Remember these are all virtual machines. Server1 is used as my dns server. They can see each other. I have the "AMP" portion installed on server2. From my client I type in the server2 address and it brings up the web page I've created.

Since there is a password, shouldn't it be asking for one when I try to get the table via the web? Also, I may even be setting up the user and password wrong in mysql. The screen shot will show my latest attempt. I've tried it without the "@ portion" too. And I've tried it from just mysql without changing to the database. The user is also just in mysql (and on my client system) but nowhere else on the server2.

The other issue may have to do with the client location. The name I have listed as the user is the same as what I use to log into my client system and the static IP used on that system. However, the hostname is different for the client system. Another issue may have to do with the browser. I think I may have read somewhere that mysql and mozilla don't get along.

I hope someone can point me in the right direction. Thanks.
Attached Images
File Type: jpg table.jpg (75.1 KB, 5 views)
File Type: jpg php.jpg (68.3 KB, 3 views)
File Type: jpg web.jpg (140.6 KB, 6 views)
 
Old 04-21-2010, 09:58 PM   #10
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi, again -

I could only read the first screenshot, but why did you query DB "cats" and table "mine"? Why not "use server2.db1" and "select * from tbl", like in your PHP script?

SUGGESTION:
1. Make sure you have the mysql client on the same host as your web server.

2. Query the database from "mysql" EXACTLY as you're trying to do it from PHP.

3. Post the results.
Cut/paste your query and the results. Do *not* use a screenshot.
Use code blocks (the little "#" icon on the toolbar when you post a reply.

Please keep us posted .. PSM
 
Old 04-21-2010, 11:06 PM   #11
tklMe
LQ Newbie
 
Registered: Mar 2010
Posts: 22

Original Poster
Rep: Reputation: 16
PaulSM4: I created a new db and a new table just in case I made some errors. This is what I have for the table info:

mysql> use cats
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select * from mine;
+----+---------+------+------+
| id | name | age | sex |
+----+---------+------+------+
| 1 | Leather | 21 | F |
| 2 | Zoey | 4 | F |
| 3 | Tavi | 2 | M |
| 4 | Tiki | 2 | M |
+----+---------+------+------+
4 rows in set (0.00 sec)

mysql> GRANT ALL ON cats.mine TO 'tklamb'@'192.168.139.129' IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.03 sec)

Here is the php code:

<html>
<head>
<title> Testing PHP/MySQl Connection </title>
</head>
<body>
<?php
$conn = mysql_connect("server2.lambott.local", "tklamb@192.168.139.129", "password");
mysql_select_db("cats", $conn);
$sql = "SELECT * FROM mine";
$result = mysql_query($sql, $conn);
echo "<table border='5'>\n";
echo " <tr>\n";
echo " <td>id</td>\n";
echo " <td>name</td>\n";
echo " <td>age</td>\n";
echo " <td>sex</td>\n";
echo " </tr>\n";

while ($row = mysql_fetch_array($result)){
echo " <tr>\n";
echo " <td>{$row[id]}</td>\n";
echo " <td>{$row["name"]}</td>\n";
echo " <td>{$row[age]}</td>\n";
echo " <td>{$row["sex"]}</td>\n";
echo " </tr>\n";
}
echo "</table>\n";
?>
</body>
</html>

As for the commands being the same, I'm pretty sure they are except maybe the capitalization part. Also I'm not sure I know what you mean by "Make sure you have the mysql client on the same host as your web server." If you mean where mysql is installed, then yes, it is installed on server2 along with Apache and php. None of these are installed on server1 or client.

I hope the cut and paste provides you with more info. Thanks for helping me by the way. I do appreciate it.
 
Old 04-21-2010, 11:58 PM   #12
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi, again -

1. I created a test table as follows (you've already done the same, successfully):
Quote:
mysql -uMY_USER -pMY_PASSWORD mysql

use test;

create table mine (
id integer not null auto_increment,
name char(10) not null,
age integer not null,
sex char(1) not null,
primary key (id)
);
Code:
Query OK, 0 rows affected (0.00 sec)
insert into mine (name,age,sex) values ('Leather', 21, 'F');
insert into mine (name,age,sex) values ('Zoey', 4, 'F');
insert into mine (name,age,sex) values ('Tavi', 2, 'M');
insert into mine (name,age,sex) values ('Tiki', 2, 'M');

select * from mine;
Code:
+----+---------+-----+-----+
| id | name    | age | sex |
+----+---------+-----+-----+
|  1 | Leather |  21 | F   |
|  2 | Zoey    |   4 | F   |
|  3 | Tavi    |   2 | M   |
|  4 | Tiki    |   2 | M   |
+----+---------+-----+-----+
4 rows in set (0.00 sec)
2. I then created a test .php script, (cleverly named "test.php" ):
Code:
<html>
<head>
<title> Testing PHP/MySQl Connection </title>
</head>
<body>
<?php
  $conn = mysql_connect("localhost", "MY_USER", "MY_PASSWORD") 
    or die ("mysql_connect failed!");
  mysql_select_db("test", $conn)
    or die ("mysql_select_db failed!");
  $sql = "SELECT * FROM mine";
  echo "sql=" . $sql . "...<br/>\n";
  $result = mysql_query($sql, $conn)
    or die ("mysql_query failed!");
  $irow = 1;
  while ($row = mysql_fetch_array($result)){
    echo "row[" . $irow . "]: id=" . $row[id] . ",name=" . $row["name"] . ",age=" . $row[age] . "...<br/>\n";
    $irow++;
  }
  echo "Done.<br/>\n";
?>
</body>
</html>
Finally, I ran it:
Quote:
pointed browser to http://MYSERVER/test.php =>
Code:
sql=SELECT * FROM mine...
row[1]: id=1,name=Leather,age=21...
row[2]: id=2,name=Zoey,age=4...
row[3]: id=3,name=Tavi,age=2...
row[4]: id=4,name=Tiki,age=2...
Done.
'Hope that helps .. PSM
 
Old 04-22-2010, 12:43 AM   #13
tklMe
LQ Newbie
 
Registered: Mar 2010
Posts: 22

Original Poster
Rep: Reputation: 16
PaulSM4: I noticed your code looked a bit different from mine. I will check it out tomorrow to see if it works. Also, you used localhost and I am assuming that is the name of the current system? It would be found under network and dns tab? Plus I didn't see how you created your user. I do have how I created mine and the IP is the system I am logging in from. Should it not ask for the username or password? The server2 has a different IP of 192.168.139.133 (this is where AMP are installed). Did I even create it correctly? Was it okay to put the client IP since that is where I am logging in from? Or should I be putting the server2 IP? (am I even making sense now?!) Thanks again for your help. (Did you check to see if my code worked at all?)

Last edited by tklMe; 04-22-2010 at 12:45 AM.
 
Old 04-22-2010, 01:48 AM   #14
Blue_Ice
Member
 
Registered: Jul 2006
Location: Belgium
Distribution: Debian, Fedora, CentOS, Windows
Posts: 352

Rep: Reputation: Disabled
After you have created a user and granted privileges, you best execute the following query in MySQL:
Code:
FLUSH PRIVILEGES;
You are also using the following username in your php code tklamb@192.168.139.129. The tklamb part is the actual username. The rest is used by MySQL to determine from which computers a client can access. So you can only connect from a computer with the ipaddress 192.168.139.129. You might want to create the user with the following query:
Code:
GRANT ALL ON cats.mine TO 'tklamb'@'192.168.139.%' IDENTIFIED BY 'password';
This will allow access from all computers within 192.168.139.0/24.
 
Old 04-22-2010, 09:23 PM   #15
tklMe
LQ Newbie
 
Registered: Mar 2010
Posts: 22

Original Poster
Rep: Reputation: 16
PaulSM4: I copied what you had, just changed the user name to tklamb and password to password and the name of the database to cats. And the error I got was mysql_connect failed! I tried changing the localhost to server2.lambott.local and still got the same thing. Any more suggestions?
(I dropped the other user, created just user tklamb and flushed privileges after using the grant command.)
 
  


Reply

Tags
configuration, lamp


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Installing LAMP, easier said than done? rjo98 Linux - Newbie 4 08-24-2009 10:52 AM
Need help configuring YUM zak4u Linux - Newbie 5 03-23-2009 06:32 AM
Installing lamp umwai Linux - Newbie 3 09-16-2008 11:58 PM
Configuring YUM taborekle Fedora 3 02-23-2006 01:35 PM
help configuring yum J0sep Fedora 1 01-13-2005 02:00 PM


All times are GMT -5. The time now is 04:11 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