Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Apache with PHP/MySQL Access

Status
Not open for further replies.

jasek78

Programmer
Nov 5, 2001
298
US
I use Plesk 7.5 to do most of the maintenance on my web server (red hat fedora core 2 w/ Apache server). I also SSH into the server to do stuff that Plesk won't let me, although my Linux/Apache knowledge is limited (I'm learning though!) First, I made a fairly simple mail form script in PHP that runs perfectly.

After this I wanted to implement a database to store emails of people that sign up for a newsletter. I created the DB using the PHPMyAdmin and set up a user and password for it.
Then I created a PHP script to insert a name and email into a MySQL database. I finally got it to do *something* and got this error message:

Code:
Access denied for user: 'apache@localhost' (Using password: NO)

This baffled me as I don't use a 'apache' user to log in to the database, so I'm thinking its the webserver (i.e. php) trying to access the database as itself. Is there a permission somewhere I need to set in order to access the database via the script?

Thanks all!

Jason
 
Hi

Jason said:
This baffled me as I don't use a 'apache' user to log in to the database
If you do not specify a user name, then the current will be used. In httpd.conf is a [tt]User[/tt] setting to specify with which user's permission to run the server. The CGIs will run with this user's permissions too.

I think your problem is pure PHP. Please post the connection part of your script. Until then, you can check the mysql_connect() function's parameters.

Feherke.
 
I do specify a user name and password to access the database. Here's the code:

Code:
<?
//initialize PHP

//POST checking
print '<pre>';
print_r ($_POST);
print '</pre>';

//insert records

   //connect as user
   //change user and password to your mySQL name and password
   mysql_connect("localhost","phpuser","password");
    
   //select which database you want to edit
   mysql_select_db("signupdb");

   //convert all the posts to variables:
   $name = $_POST['name'];
   $email = $_POST['email'];
   
   //Insert the values into the correct database with the right fields
   $result=MYSQL_QUERY("INSERT INTO newsletter (name,email) VALUES ('$name', '$email')");

    //confirm
 ?>
<div align=center>
Thank you <? $name ?> for signing up for the Newsletter.

</div>

 


    
</body>
<script>resizeTo(300, 300)</script>

I recieve as output a page that contains the POST[ed] variables and then the above error code.

Jason
 
CLI Version? I'm not sure I follow. I can ssh onto the server but I don't know how to pull up the PHP CLI version. I would assume so, because I believe it to be an error with some permissions, or perhaps the way the webserver is loading the database (which boils down to a permission issue).

Jason
 
Hi

CLI means Command Line Interface. Is the one runnable from command line. Just give it the script file name as parameter. Will not really work in absence of [tt]$_POST[/tt] but for debugging the connection problem is good enough.
Code:
[blue]master #[/blue] php subscribe.php


Feherke.
 
I tried this, and it still gives me the error. Do I need to give the user 'apache' (the web server instance) permissions to access the database, or edit a config file somewhere? Any other guidance is appreciated.

Jason
 
Hi

Sorry, I know MySQL just vaguely, can not help with this. The one thing I would try, is to access the MySQL database with it's interactive terminal :
Code:
[blue]master #[/blue] mysql -h localhost -u apache
[gray]# or[/gray]
[blue]master #[/blue] mysql -u apache
Between the two above commands could be difference, depending on configuration.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top