Page 1 of 2

New to PHP 3 Problems/Questions

Posted: Thu Apr 06, 2006 12:38 am
by rf
Hi, I am new to PHP and am having trouble getting started :D

My setup: :)
Xandros Desktop 3.0.3 Business on i686 machine with 2 MB RAM
PHP 4.4.2 that works well from console
MySQL 5.0.18-pro-gpl that works well by itself from the console

My Object: :P
Trying to create a form that will input/extract data from MySQL

My Questions/Problems: :)

1. <?php
// set database server access variables:
$host = "localhost";
$user = "root";
$pass = "my correct password";
$db = "test";

// open connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to
...... ?>
gives me the error "access denied root@localhost (using password: YES)
Where is this error message getting the "YES" password - and is that my problem? How to fix it?

2. When I point my Firefox or Mozilla browser to file:////file.php it asks what text.editor I want to open to read the file. It does not run or execute the .php file. Why? How is that problem fixed?

3. When i point my browser to HTTP://localhost/path to file.php it tells me that connection was refused to localhost. Why? What to do?

Thanks much :D


Posted: Thu Apr 06, 2006 2:08 am
by bootup
Did you use a password when you setup "root" user @ localhost?
If you did is it the right one? Try connecting to MySql through command with your password and see if you can connect.

The mozilla file problem is when you initiate a PHP it must think it is a webpage. eg. http://localhost/user/phpinfo.php. Under file:/// it will think you want to edit it not view it.

Hope this helps


Posted: Thu Apr 06, 2006 11:45 am
by munky
1) mysql uses seperate auth. in mysql, user root has no password by default. try an empty password

2) because you're opening it as a file, php files are server side scripts that must be executed

3) because apache isn't running, or not listening on localhost

if you want to run a file without serving it through apache (or other web server), you can run php from a shell:
`php /path/to/my/file.php`

Posted: Sat Apr 08, 2006 12:04 am
by rf
Thanks for the advice/feedback.
This is just to say that I am working on the suggestions.
About the only thing I know at this point is that using the default settings as I have - it does not make any difference if I do or don't supply a password in the php script.
I have not had much time to work on this project - but will continue to do so and ask more questions or announce success when it has arrived - and what I did with your help. :D


Posted: Mon Apr 10, 2006 3:34 pm
by munky
FYI, it's a bad idea to use root in your php connection. better to create another login

mysql -uroot -p
>grant all privileges on mydatabase.* to myuser@localhost identified by 'mypassword';
>flush privileges;

Posted: Tue Apr 11, 2006 10:28 pm
by rf
:D Now I know some things!
What I have tried to solve the problems:
1. changed /etc/apache/httpd.conf from listen to
changed port 80 to 2112
usr rf
group MySQL
DocumentRoot to /home/rf/php
2. changed in /etc/php4/apache/php.ini, /etc/php4/cgi/php.ini, /etc/php4/cli/php.ini :
mysql.default_socket = (from blank to) /tmp/mysql.sock
mysql.default_host = (from blank to) localhost:2112
mysql.default_user = (from blank to) rf
3. Now to try this all out: :D
apache -v returns Apache/1.3.33 (Debian)
php -v returns php 4.4.2(cli) (built Mar 31st 2006)
php -l goes into never-never land until it is stopped!
$php test.php gives what is expected including phpinfo() which says php 4.3.10-9!
$php MySQLconnect.php -> unable to connect
attempts to connect Firefox browser to php gives various results:
https://localhost:2112/test.php gives !
https://localhost -> connection was refused
https://localhost:2112 or rf@localhost -> connection was refused
https://var/www/test.php - > !
localhost/test.php -> error bad request Try (the next line down)
https://P4-3200RF:80/ -> access denied
https://P4-3200RF:2112 -> connection refused
http://www.mysql_up.php -> could not be found

I am now using MySQL as user rf instead of root - That worked. Thanks much.
As far as I currently can tell apache, php, and MySQL are all installed and running OK but not talking to each other! :(

I am not sure why php -v and phpinfo() give different answers. Should I try to remove one of the versions of php? Any other suggestions to do or try? MySQL configuration file tells me that there is nothing to configure in this distribution.

Thanks much :)

rf :D

Posted: Wed Apr 12, 2006 12:20 pm
by munky
the different versions of PHP are because your PHP binary and PHP library loaded by httpd.conf are different versions. check your configuration and installations.

localhost is, not
check your /etc/hosts to make sure you don't have any odd entries for jakarta or gloriamuindi.

the access denied on P4-3200RF:80 is because httpd is running on port 80, but does not have an index file to serve you.

based on all that you have said about your testing, it sounds like you have 2 versions of apache running. one is listening on P4-3200RF:80, the other is listening on port 2112 of what should be ( is owened by Softbank BB Corp of Japan)

Posted: Wed Apr 12, 2006 10:05 pm
by rf

/etc/hosts has two entries: P4-3200RF P4-3200RF localhost

I changed /etc/apache/httpd.conf
Listen to
and tried again with Firefox browser:
https://localhost -> connection refused
https://P4-3200RF:80 or :2112 -> access denied
https://localhost:2112/test.php -> access denied (rather than
https://var/www/test.php -> still gives!

"the access denied on P4-3200RF:80 is because httpd is running on port 80, but does not have an index file to serve you."

Question: How is this solved? I can make a file called index.html - but where do I put it? Or is that the wrong approach to the problem? It makes no difference whether I am in administrator mode or not.



Posted: Thu Apr 13, 2006 12:08 am
by wundr
rf wrote:Followup:

/etc/hosts has two entries: P4-3200RF P4-3200RF localhost
Perhaps you meant ? is owned by NASA, while is used for private LAN addresses...

Posted: Thu Apr 13, 2006 12:15 am
by rf
:oops: You are correct. I meant


Posted: Thu Apr 13, 2006 3:32 pm
by munky
after editing httpd.conf, make sure you HUP you httpd. either `apachectl graceful` or `/etc/init.d/httpd restart`

to know where to put index.html, `grep DocumentRoot /etc/apache/httpd.conf`

unless you're doing more typos, use http, not https. https is ssl on port 443 (default), where as http is plaintext on port 80 (default).

don't bother trying http://var/www/test.php
that will never work. you are trying to load the file "/www/test.php" on the server "var", which your nameserver is telling you is gloriamundi. if you want to load the file locally, you have to use file://var/www/test.php, but that will not give you the desired result, because as i said before, PHP is a server side scripting/programming language. it has to be parsed by the server to give anything useful. if you try to load it using file://, you will just get the source code spit out at you.

Posted: Fri Apr 14, 2006 5:14 pm
by rf
I have erased all the apache and php files (tedious) and am starting to re-install them.
Apache (httpd-2.2.0) installed sans warnings or errors. However when I tried to start it I got the following error message:

P4-3200RF:/usr/src/httpd-2.2.0# /usr/local/apache2/bin/apachectl start
httpd: Could not reliably determine the server's fully qualified domain name, using for ServerName
(98)Address already in use: make_sock: could not bind to address
no listening sockets available, shutting down
Unable to open logs

ps -A does not tell me what is using port 98.

1.What to do ?
Is the best plan to scratch Apache2 and try Apache 1.3.34? Or is there some way of solving the port problems? :)

2. "after editing httpd.conf, make sure you HUP you httpd. either `apachectl graceful` or `/etc/init.d/httpd restart`"
What does HUP mean?

Thank you for your patience and help!


Posted: Sat Apr 15, 2006 5:55 pm
by munky
"Address already in use: make_sock: could not bind to address"

this means apache is already running. like i said in a previous post, you have 2 (TWO) installations of apache.
in most linux distributions, apache is installed by default, and does not need to be installed manually unless you want to run a version other than what was already installed. if this is the case, you have to stop and disable the previous apache version.

HUP == hangup. it refers to sending the HUP signal to the apache process. apache catches this kill sig and re-reads it's configuration files.
`ps ax | grep httpd | awk '{print $1}' | xargs kill -HUP` should work on most any *nix system
`killall -HUP httpd` will work on most linux and freebsd systems.
`apachectl graceful` is just a lot easier

Posted: Tue Apr 18, 2006 4:21 pm
by rf
Follow up: Thanks for all your help.

1. Complete reinstall of OS to make a fresh start. Setup now is:
P4-3200RF:/var/www# uname -a
Linux P4-3200RF 2.6.11-smp #1 SMP Mon Apr 25 12:42:02 EDT 2005 i686 GNU/Linux

P4-3200RF:/var/www# apache -v
Server version: Apache/1.3.33 (Debian GNU/Linux)
Server built: Feb 8 2005 03:32:49

P4-3200RF:/var/www# apache -l
Compiled-in modules:
suexec: disabled; invalid wrapper /usr/lib/apache/suexec

P4-3200RF:/var/www# php -v
PHP 4.4.2 (cgi) (built: Apr 17 2006 06:58:33)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies

P4-3200RF:/usr/local/mysql# bin/mysql -h localhost -u mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4 to server version: 5.0.20-pro-gpl

2. What's happening:
P4-3200RF:/var/www# php test.php
X-Powered-By: PHP/4.4.2
Content-type: text/html

<title>PHP Test</title>
<p>This is an HTML line.\n
<p>This is a PHP line
</p><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<style type="text/css">
body {background-color: #ffffff; color: #000000;}
etc etc i.e get a copy of the HTML source with PHP activity wich is what I can see from my browser as well.
Q Is this what I am supposed to see? If I pipe it into another file and call it <file>.html and look at it with the browser - I get the pretty table instead of the source file data (see below). Is this what is supposed to happen?
If I point my browser to http://localhost/test.php It simply asks me what I want to do with the file - open it with what text editor or save it. If I point it to the file made:
P4-3200RF:/var/www# php test.php > test.html I get this output pointing the browser to localhost/test.html:
X-Powered-By: PHP/4.4.2 Content-type: text/html

This is an HTML line.\n

This is a PHP line
PHP Logo
PHP Version 4.4.2

System Linux P4-3200RF 2.6.11-smp #1 SMP Mon Apr 25 12:42:02 EDT 2005 i686
Build Date Apr 17 2006 06:57:59
Configure Command './configure' '--with-mysql=/usr/local/mysql'
Server API CGI
Virtual Directory Support disabled
Configuration File (php.ini) Path /usr/local/lib
PHP API 20020918
PHP Extension 20020429
Zend Extension 20050606
Debug Build no
Zend Memory Manager enabled
Thread Safety disabled
Registered PHP Streams php, http, ftp

Zend logo This program makes use of the Zend Scripting Language Engine:
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies
etc etc

This is not what I expect to happen exactly. Am I missing a module or something not to get the table output directly and not to be able to point my browser to a php file and get it to run it?

Thanks much
:D rf


P4-3200RF:/var/www# ps ax | grep httpd | awk '{print $1}' | xargs kill -HUP
does nothing I can determine on this machine.

P4-3200RF:/var/www# ps ax | grep httpd | awk '{print $1}' | xargs killall -HUP httpd
httpd: no process killed
11951: no process killed
11953: no process killed

P4-3200RF:/var/www# /usr/sbin/apachectl graceful
/usr/sbin/apachectl graceful: httpd gracefully restarted

Thanks. I assume all three do the same thing. I agree that graceful is easier :)

Posted: Wed Apr 19, 2006 1:24 pm
by munky
rf wrote: P4-3200RF:/var/www# ps ax | grep httpd | awk '{print $1}' | xargs kill -HUP
does nothing I can determine on this machine.
it does, you just don't see any output (except maybe "####: no process killed", which is because sometimes the 'grep' show itself. this is not a problem)
rf wrote: P4-3200RF:/var/www# ps ax | grep httpd | awk '{print $1}' | xargs killall -HUP httpd
httpd: no process killed
11951: no process killed
11953: no process killed
it should be just `killall -HUP httpd`
like before, you won't see any output
rf wrote: P4-3200RF:/var/www# /usr/sbin/apachectl graceful
/usr/sbin/apachectl graceful: httpd gracefully restarted
this is normal

as far as viewing the PHP in your web browser:

now you have a working apache/php.
try pointing your webbrowser to http://localhost/test.php
running `php test.php` is for running php files at command line (it's possible to write scripts/programs in PHP, or use it from command line to test if it is working properly before using it in a web browser)