need help with PHP

Hi all,

I had to review website and i got whole website sent in ziped file. I extracted it in home directory and tried to view it with browser. Since all files are *.php browser instead of displaying them tried to download them. I went ahead and copied all files of website to /srv/www/htdocs and tried from browser localhos/index.php (index file of website) - it worked.

so my question is - how can i make this work without transferring all files into /srv/www/htdocs but instead, for example from /home/username/public_html

thnx in advance

Go to the URL http://localhost/~username/

it didn’t really work.
i went to localhost/nikom/public_html/website/index.php but got error page.

In that case you should go to http://localhost/~nikom/website/index.php

~nikom is short for /home/nikom/public_html

You should also take note of what the error was. Not all errors are the same although they might look the same to you. A 404 means that the URL doesn’t exist, but if you get a 403 that means you have a permission issue.

The file index.php must be readable to the world and all the directories leading to it must have read and search (r-x) permission for the world.

i’m getting 404 error. (and i checked permissions and they are r-x for world)
;(
still no go

Look in /var/log/apache2/error_log to see what the full pathname of the file you are trying to access is.

hmmm…this is interesting:

[Thu Oct 30 23:58:18 2008] [error] [client 127.0.0.1] File does not exist: /srv/www/htdocs/home

so it still looking in /srv/www/htdocs. Do i have to change somethig (add) in apache.conf? like to make apache read public_html folder in my home directory?

You need to enable userdir in /etc/sysconfig/apache2, variable APACHE_MODULES. Either use a text editor, or

a2enmod userdir

then reload apache (rcapache2 reload).

this iswhat i have:

nikoshiba:/home/nikom # a2enmod userdir
"userdir" already present
nikoshiba:/home/nikom #

still puzzled…

You’re not entering http://localhost/home/nikom/… are you?

When I write

http://localhost/~nikom/website/index.php

I mean that you should enter that into the location bar exactly as shown, with the tilde (~).

This assumes that you have put the file in

/home/nikom/public_html/website/index.php

if there is no website directory, then omit that part.

You’re not entering http://localhost/home/nikom/… are you?

:stuck_out_tongue: i was…
but still i get 404 error.
(and strange is tht i can’t even enter “~” in firefox address bar, in opera it ispossible to do so, but as i have sad - 404!!!

Something strange with your keyboard or browser charset in Firefox then.

What’s in /var/log/apache2/error_log when you go to http://localhost/~nikom/index.php with Opera? It should try to fetch from /home/nikom/public_html/index.php, and then you should check that you have allowed Apache to serve these files, and also the permissions of index.php and every directory on that path, that is to say: / /home /home/nikom /home/nikom/public_html should have read and search permission for others.

BTW if you are tired of figuring out the permission system, another way out is to create a directory owned by you, say /srv/www/htdocs/nikom, and then you can put your PHP scripts there. You could reduce typing by making a symlink to it.

sudo mkdir /srv/www/htdocs/nikom
sudo chown nikom:users /srv/www/htdocs/nikom
ln -s /srv/www/htdocs/nikom ~/mywebsite

then you can cd mywebsite and do your work there.

In Apache, the URL would be:

http://localhost/nikom/

As before, make sure that the directory is read and search enabled for others, and that any files are read enabled for others.

BTW if you are tired of figuring out the permission system, another way out is to create a directory owned by you, say /srv/www/htdocs/nikom, and then you can put your PHP scripts there. You could reduce typing by making a symlink to it.

i’m doing it already…it’s just killing me WHY OH WHY i can’t put public_html folder to work…>:( >:( >:( >:(
all read rights are r-x to world, all modules are loaded…WHAT ELSE DO YOU WANT FROM ME???

(ken_yap thnx for you help, really appreciated…and i’m not going to give up…dean it.
this frustration of mine wasn’t directed to you, i hope it was clear that my php and apapache configuration are the reason)