New to PHP 3 Problems/Questions

Post everything else here

Moderators: Website/Forum Admins, Other/Off Topic Moderators

rf
Posts: 30
Joined: Wed Apr 05, 2006 10:16 pm

New to PHP 3 Problems/Questions

Postby rf » Thu Apr 06, 2006 12:38 am

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
connect!");
...... ?>
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

rf
bootup
Posts: 3
Joined: Thu Apr 06, 2006 1:34 am

Postby bootup » Thu Apr 06, 2006 2:08 am

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

Matt
User avatar
munky
Site Admin
Posts: 826
Joined: Wed Jul 02, 2003 4:54 pm
Location: Phoenix AZ
Contact:

Postby munky » Thu Apr 06, 2006 11:45 am

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`
In God we trust,
Everyone else must have an X.509 certificate.
rf
Posts: 30
Joined: Wed Apr 05, 2006 10:16 pm

Postby rf » Sat Apr 08, 2006 12:04 am

:D
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

rf
User avatar
munky
Site Admin
Posts: 826
Joined: Wed Jul 02, 2003 4:54 pm
Location: Phoenix AZ
Contact:

Postby munky » Mon Apr 10, 2006 3:34 pm

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;
>quit
In God we trust,
Everyone else must have an X.509 certificate.
rf
Posts: 30
Joined: Wed Apr 05, 2006 10:16 pm

Postby rf » Tue Apr 11, 2006 10:28 pm

:D Now I know some things!
What I have tried to solve the problems:
1. changed /etc/apache/httpd.conf from listen 126.0.0.1:80 to 126.0.0.1:2112
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 http://www.jarkata.org !
https://localhost -> connection was refused
https://localhost:2112 or rf@localhost -> connection was refused
https://var/www/test.php - > http://www.gloriamuindi.org !
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
User avatar
munky
Site Admin
Posts: 826
Joined: Wed Jul 02, 2003 4:54 pm
Location: Phoenix AZ
Contact:

Postby munky » Wed Apr 12, 2006 12:20 pm

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 127.0.0.1, not 126.0.0.1.
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 127.0.0.1. (126.0.0.0/8 is owened by Softbank BB Corp of Japan)
In God we trust,
Everyone else must have an X.509 certificate.
rf
Posts: 30
Joined: Wed Apr 05, 2006 10:16 pm

Postby rf » Wed Apr 12, 2006 10:05 pm

Followup:

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

I changed /etc/apache/httpd.conf
Listen 126.0.0.1:2112 to 127.0.0.1:2112
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 http://www.jarkata.org)
https://var/www/test.php -> still gives http://www.gloriamundi.org!

"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.

Thanks

RF :D
wundr
Posts: 140
Joined: Sun Jul 06, 2003 11:34 pm
Location: Japan

Postby wundr » Thu Apr 13, 2006 12:08 am

rf wrote:Followup:

/etc/hosts has two entries:
129.168.0.101 P4-3200RF P4-3200RF
127.0.0.1 localhost
Perhaps you meant 192.168.0.101 ? 129.168.0.0/16 is owned by NASA, while 192.168.0.0/16 is used for private LAN addresses...
rf
Posts: 30
Joined: Wed Apr 05, 2006 10:16 pm

Postby rf » Thu Apr 13, 2006 12:15 am

:oops: You are correct. I meant 192.168.0.101
Thanks!

RF
User avatar
munky
Site Admin
Posts: 826
Joined: Wed Jul 02, 2003 4:54 pm
Location: Phoenix AZ
Contact:

Postby munky » Thu Apr 13, 2006 3:32 pm

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.
In God we trust,
Everyone else must have an X.509 certificate.
rf
Posts: 30
Joined: Wed Apr 05, 2006 10:16 pm

Postby rf » Fri Apr 14, 2006 5:14 pm

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 192.168.0.101 for ServerName
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
P4-3200RF:/usr/src/httpd-2.2.0#

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

Questions:
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!

RF
User avatar
munky
Site Admin
Posts: 826
Joined: Wed Jul 02, 2003 4:54 pm
Location: Phoenix AZ
Contact:

Postby munky » Sat Apr 15, 2006 5:55 pm

"Address already in use: make_sock: could not bind to address 0.0.0.0:80"

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
In God we trust,
Everyone else must have an X.509 certificate.
rf
Posts: 30
Joined: Wed Apr 05, 2006 10:16 pm

Postby rf » Tue Apr 18, 2006 4:21 pm

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:
http_core.c
mod_so.c
mod_macro.c
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

<html>
<head>
<title>PHP Test</title>
</head>
<body>
<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">
<html><head>
<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

ps

P4-3200RF:/var/www# ps ax | grep httpd | awk '{print $1}' | xargs kill -HUP
P4-3200RF:/var/www#
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

and
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 :)
:D
User avatar
munky
Site Admin
Posts: 826
Joined: Wed Jul 02, 2003 4:54 pm
Location: Phoenix AZ
Contact:

Postby munky » Wed Apr 19, 2006 1:24 pm

rf wrote: P4-3200RF:/var/www# ps ax | grep httpd | awk '{print $1}' | xargs kill -HUP
P4-3200RF:/var/www#
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)
In God we trust,
Everyone else must have an X.509 certificate.

Who is online

Users browsing this forum: No registered users and 1 guest