LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 04-25-2006, 05:59 AM   #1
Gins
Senior Member
 
Registered: Jul 2004
Location: Germany
Distribution: open SUSE 11.0, Fedora 7 and Mandriva 2007
Posts: 1,638

Rep: Reputation: 46
A simple PHP problem


I have installed PHP as well as MYSQL. I am running Mandriva Linux 2006 version. It is a 64 bit program.

I have written the following program using the 'vi' editor.

<html>
<body>

<?$today = date("d.m.y");?>

Todays date is: <? echo "$today"; ?>

</html>
</body>

The name of the program is '' php_testing1.html ''.

---------------------------------------------------------------

I opened it on Firefox browser.

The output is as follows:
--------------------------------
Todays date is:
--------------------------------

Why doesn't it show the date?

Your help is appreciated.
 
Old 04-25-2006, 06:08 AM   #2
zeitounator
Member
 
Registered: Aug 2003
Location: Montpellier, France, Europe, World, Solar System
Distribution: Debian Sarge, Fedora core 5 (i386 and x86_64)
Posts: 262

Rep: Reputation: 30
rename php_testing1.html to php_testing1.php
 
Old 04-25-2006, 06:10 AM   #3
reddazz
Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 74
PHP files need to be saved with a .php extension so that the php parser process the php parts of that page. I changed your html a little and the page works fine for me.
PHP Code:
<html>
<head>
<title>Todays Date</title>
</head>
<body>
<?php
$today 
date("d.m.y");
?>
Todays date is: <?php echo "$today"?>
</body>
</html>
 
Old 04-25-2006, 06:27 AM   #4
Gins
Senior Member
 
Registered: Jul 2004
Location: Germany
Distribution: open SUSE 11.0, Fedora 7 and Mandriva 2007
Posts: 1,638

Original Poster
Rep: Reputation: 46
Thanks zeitounator for taking time to reply me.

Now the name of the file is ' php_testing1.php '.

It refused to open on the browser.

It forced me to open on a text editor called 'gedit'. I have never ever used this 'gedit' program.

Would you try it on your browser?

What is the problem?
 
Old 04-25-2006, 06:32 AM   #5
Gins
Senior Member
 
Registered: Jul 2004
Location: Germany
Distribution: open SUSE 11.0, Fedora 7 and Mandriva 2007
Posts: 1,638

Original Poster
Rep: Reputation: 46
Thanks reddazz for helping me.

I saved your file as 'tock1.php'
---------------------------------------------
<html>
<head>
<title>Todays Date</title>
</head>
<body>
<?php
$today = date("d.m.y");
?>
Todays date is: <?php echo "$today"; ?>
</body>
</html>

----------------------------------------------------

It too forced me to open on the gedit program.

Why is this? Why are those files refused to open on the firefox browser?
 
Old 04-25-2006, 06:47 AM   #6
reddazz
Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 74
PHP files have to be accessed through your webserver so that they are parsed by the php intepreter. Save your php files to your apache document root or ~/public_html then access them from your web browser by doing something like, http://localhost/tock1.php or http://localhost/~username/tock1.php (if you are storing them in a subdirectory called public_html in your home directory).
 
Old 04-25-2006, 07:21 AM   #7
Gins
Senior Member
 
Registered: Jul 2004
Location: Germany
Distribution: open SUSE 11.0, Fedora 7 and Mandriva 2007
Posts: 1,638

Original Poster
Rep: Reputation: 46
Thanks reddazz again for the help.

Now I must go the gym for training afterwards I will go to work.

I will attend this tomorrow.
 
Old 04-25-2006, 08:36 AM   #8
muha
Member
 
Registered: Nov 2005
Distribution: xubuntu, grml
Posts: 451

Rep: Reputation: 37
you'll need to be able to start the apache-webserver and such, for some basic tips ~> nerdstuffs
 
Old 04-25-2006, 09:10 AM   #9
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
You also have to tell the webserver to parse php files; just check if similar lines occur in your http.conf, else add them.
Each line before #WimS is an existing line, each line after is what I added to get it working. So you can search for an existing line and add something after it.
Code:
LoadModule setenvif_module    libexec/apache/mod_setenvif.so
#WimS
LoadModule php4_module        libexec/apache/libphp4.so
Code:
AddModule mod_setenvif.c
#WimS
AddModule mod_php4.c
Code:
    #AddType application/x-gzip .gz .tgz
#WimS
    AddType application/x-httpd-php .php
If you use a different php version, the lines might be slightly different (i.e. use libphp5.so) instead of libphp4.so.

Once you have done this, you can make a simple page that calls the php function phpinfo() in the body
Code:
<?php
phpinfo();
?>
When you load that page, it will display info about php.
 
Old 04-26-2006, 05:56 AM   #10
Gins
Senior Member
 
Registered: Jul 2004
Location: Germany
Distribution: open SUSE 11.0, Fedora 7 and Mandriva 2007
Posts: 1,638

Original Poster
Rep: Reputation: 46
I just looked at the place where the file/folder 'localhost' is situated.


[nissanka@c83-250-104-57 ~]$ su root
Password:
[root@c83-250-104-57 nissanka]# find / -name 'localhost'
/usr/share/doc/dhcp-common-3.0.3/doc/trustix/master/localhost
[root@c83-250-104-57 nissanka]#

Is the above correct?

------------------------------------------------------------




-----------------------------------------------------------------

Where do I find the apache document folder?

[root@c83-250-104-57 nissanka]# find / -name 'apache'
/home/nissanka/php-4.4.2/sapi/apache
/home/nissanka/php-4.4.2/scripts/apache
/usr/lib64/apache
/usr/src/php4-devel/sapi/apache
[root@c83-250-104-57 nissanka]#

----------------------------------------------------------

How do I find out whether apache is working?



---------------------------------------------------------

I tried in vain the following address:

http://localhost/php_testing1.php

The output was:

Not Found
The requested URL /php_testing1.php was not found on this server.

Last edited by Gins; 04-26-2006 at 06:06 AM.
 
Old 04-26-2006, 06:07 AM   #11
muha
Member
 
Registered: Nov 2005
Distribution: xubuntu, grml
Posts: 451

Rep: Reputation: 37
I think you want these settings to check your apache version and config, root folder:
Code:
httpd2 -V
Code:
/etc/init.d/apache2 status
OR
ps aux| grep httpd
To see whether apache is running.

Code:
apache2ctl start
In a konsole (as root): manually starts the apache server; stop for stopping; restart for restarting.
This is how it works for suse, i'm not sure if it's exactly the same for mandrake, give it a try or find the equivalent commands ...
 
Old 04-26-2006, 07:09 AM   #12
Gins
Senior Member
 
Registered: Jul 2004
Location: Germany
Distribution: open SUSE 11.0, Fedora 7 and Mandriva 2007
Posts: 1,638

Original Poster
Rep: Reputation: 46
Thanks Muha

[root@c83-250-104-57 nissanka]# httpd2 -V
bash: httpd2: command not found
[root@c83-250-104-57 nissanka]#

So it is not there.
-------------------------------------------------------

[root@c83-250-104-57 nissanka]# ps aux|grep httpd
root 7173 0.0 0.0 4136 704 pts/1 R+ 13:11 0:00 grep httpd
[root@c83-250-104-57 nissanka]#

What is the meaning of the above?

--------------------------------------------------------------

[root@c83-250-104-57 nissanka]# apache2ctl start
bash: apache2ctl: command not found
[root@c83-250-104-57 nissanka]#

-----------------------------------------------------

In the 'etc' folder, I found the following:

init.d@
initlog.conf



[root@c83-250-104-57 etc]# cat initlog.conf
# /etc/initlog.conf
#
# initlog configuration file
#
# lines preceded by a '#' are comments
#
# anything not recognized is ignored.

# This sets the default logging facility. (can override with command line arguments)
facility local7

# This sets the default logging priority. (can override with command line arguments)
priority notice

# ignore foo
# means to discard any output lines that match the regular expression foo

# This regexp is useful if you use fsck's -C option.
ignore [^:]+: \|[=]+
# This regexp is useful for fsck's feature of setting file types
ignore [^:]+: Setting filetype
# This regexp is useful for quotacheck
ignore ^[-\\\|\/]$
[root@c83-250-104-57 etc]#

Last edited by Gins; 04-26-2006 at 07:18 AM.
 
Old 04-26-2006, 07:45 AM   #13
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
Quote:
Originally Posted by Gins
I just looked at the place where the file/folder 'localhost' is situated.

[nissanka@c83-250-104-57 ~]$ su root
Password:
[root@c83-250-104-57 nissanka]# find / -name 'localhost'
/usr/share/doc/dhcp-common-3.0.3/doc/trustix/master/localhost
[root@c83-250-104-57 nissanka]#

Is the above correct?

Where do I find the apache document folder?
No, localhost is not a folder. It might possibly be /var/www/htdocs. The exact location for your system can be found in the file http.conf. Locate that file (possibly /etc/apache/httpd.conf) and search for DocumentRoot. That will be where you should put your html and php pages for the server.

Quote:
Originally Posted by Gins
How do I find out whether apache is working?

I tried in vain the following address:

http://localhost/php_testing1.php

The output was:

Not Found
The requested URL /php_testing1.php was not found on this server.
From the output, I guess that it's running.
Code:
ps -ef |grep httpd
Quote:
Originally Posted by Gins
[root@c83-250-104-57 nissanka]# ps aux|grep httpd
root 7173 0.0 0.0 4136 704 pts/1 R+ 13:11 0:00 grep httpd
[root@c83-250-104-57 nissanka]#

What is the meaning of the above?
That it's not running

Last edited by Wim Sturkenboom; 04-26-2006 at 07:47 AM.
 
Old 04-26-2006, 08:00 AM   #14
Gins
Senior Member
 
Registered: Jul 2004
Location: Germany
Distribution: open SUSE 11.0, Fedora 7 and Mandriva 2007
Posts: 1,638

Original Poster
Rep: Reputation: 46
Thanks Wim for taking time to reply me.

[nissanka@c83-250-104-57 etc]$ cd apache1
[nissanka@c83-250-104-57 apache1]$
[nissanka@c83-250-104-57 apache1]$ ls
conf/ lib64@ logs@ modules@ modules.d/
[nissanka@c83-250-104-57 apache1]$

----------------------------------------------

[nissanka@c83-250-104-57 apache1]$ ls
conf/ lib64@ logs@ modules@ modules.d/
[nissanka@c83-250-104-57 apache1]$ cd conf
[nissanka@c83-250-104-57 conf]$ ls
httpd.conf magic mime.types vhosts.d/ webapps.d/
[nissanka@c83-250-104-57 conf]$

--------------------------------------------------------


[nissanka@c83-250-104-57 conf]$ cat httpd.conf


#
# BindAddress: You can support virtual hosts with this option. This directive
# is used to tell the server which IP address to listen to. It can either
# contain "*", an IP address, or a fully qualified Internet domain name.
# See also the <VirtualHost> and Listen directives.
#
#BindAddress *

#
# Dynamic Shared Object (DSO) Support
#
# To be able to use the functionality of a module which was built as a DSO you
# have to place corresponding `LoadModule' lines at this location so the
# directives contained in it are actually available _before_ they are used.
# Please read the file http://httpd.apache.org/docs/dso.html for more
# details about the DSO mechanism and run `httpd -l' for the list of already
# built-in (statically linked and thus always available) modules in your httpd
# binary.
#
# Note: The order in which modules are loaded is important. Don't change
# the order below without expert advice.
#
# Example:
# LoadModule foo_module libexec/mod_foo.so
# LoadModule mmap_static_module modules/mod_mmap_static.so
LoadModule vhost_alias_module modules/mod_vhost_alias.so
LoadModule env_module modules/mod_env.so
LoadModule define_module modules/mod_define.so
LoadModule config_log_module modules/mod_log_config.so
# LoadModule agent_log_module modules/mod_log_agent.so
# LoadModule referer_log_module modules/mod_log_referer.so
#LoadModule mime_magic_module modules/mod_mime_magic.so
LoadModule mime_module modules/mod_mime.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule status_module modules/mod_status.so
LoadModule info_module modules/mod_info.so
LoadModule includes_module modules/mod_include.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule dir_module modules/mod_dir.so
LoadModule cgi_module modules/mod_cgi.so
LoadModule asis_module modules/mod_asis.so
LoadModule imap_module modules/mod_imap.so
LoadModule action_module modules/mod_actions.so
#LoadModule speling_module modules/mod_speling.so
LoadModule userdir_module modules/mod_userdir.so
LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule access_module modules/mod_access.so
LoadModule auth_module modules/mod_auth.so
LoadModule anon_auth_module modules/mod_auth_anon.so
#LoadModule dbm_auth_module modules/mod_auth_dbm.so
#LoadModule db_auth_module modules/mod_auth_db.so
LoadModule digest_module modules/mod_digest.so
LoadModule digest_auth_module modules/mod_auth_digest.so
LoadModule proxy_module modules/libproxy.so
#LoadModule cern_meta_module modules/mod_cern_meta.so
LoadModule expires_module modules/mod_expires.so
LoadModule headers_module modules/mod_headers.so
LoadModule usertrack_module modules/mod_usertrack.so
#LoadModule example_module modules/mod_example.so
#LoadModule log_forensic_module modules/mod_log_forensic.so
#LoadModule unique_id_module modules/mod_unique_id.so
LoadModule setenvif_module modules/mod_setenvif.so

# Reconstruction of the complete module list from all available modules
# (static and shared ones) to achieve correct module execution order.
# [WHENEVER YOU CHANGE THE LOADMODULE SECTION ABOVE UPDATE THIS, TOO]
ClearModuleList
# AddModule mod_mmap_static.c
AddModule mod_vhost_alias.c
AddModule mod_env.c

[ THE ABOVE IS A PORTION OF THE httpd.conf FILE'.]

Do I have apache working on my system?
 
Old 04-26-2006, 08:12 AM   #15
muha
Member
 
Registered: Nov 2005
Distribution: xubuntu, grml
Posts: 451

Rep: Reputation: 37
yep, looks like you have an older version of apache: apache1.
The current version is apache2. http://httpd.apache.org/
If you want to update you probably will want to use a package-manager to update apache ...

So, instead of all the .2 version commands i posted you should run:
Code:
httpd -V
apachectl start
/etc/init.d/apache status
I'm not sure about the last one ..

Last edited by muha; 04-26-2006 at 08:13 AM.
 
  


Reply

Tags
php


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
a simple problem about cookie(PHP) naihe2010 Programming 2 03-13-2006 12:36 PM
simple problem about php mohtasham1983 Programming 6 01-05-2006 10:09 PM
Simple PHP code aznita Programming 1 06-20-2005 12:50 AM
simple php question jfall Programming 1 05-03-2005 03:57 PM
Simple PHP Question jacksmash Programming 21 01-04-2004 09:31 PM


All times are GMT -5. The time now is 09:37 PM.

Main Menu
Advertisement
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