I just re-installed my Mint system and now I can't get php to work. I've tested apache and it seems to be working just fine, entering localhost into the URL brings up that default page in /var/www/ but when I created a small php file called testphp.php with nothing but phpinfo() function between to opening and closing braces all I get from the browser is NOT FOUND The requested URL /testphp.php was not found on this server. Any ideas what might have changed? After re-installing all I did was enter sudo apt-get install apache2 and sudo apt-get install php5

Check the ownership and the permissions of the script, by writing the file into /var/www/ you probably used sudo, correct? That gave root:root to the script. Apache needs access to read and execute the file, so you can switch the group to www-data:

sudo chown root:www-data script.php

Then, if your user is part of the www-data group, you can change the permission to allow your edits without using sudo:

sudo chmod 775 script.php

The above is valid for development in localhost, not for production, in that case the rules must be more restrictive.

I just changed the group for www and all sub files to www-data but I'm still getting the same result. Any other ideas? I just found something by looking at the log file. It's looking in /var/www/html/file.php instead of just /var/www/file.php. I've never seen that before. Where is the apache config file I need to make that change in?

Check the settings of /etc/apache2/sites-available/default or in apache2.conf and adjust the DocumentRoot to your desired path, then reload apache.

I had to move all of my php and html files into /var/www/html/ instead of just /var/www/ and now it seems to be working just fine. I've never seen apache use /var/www/html/ by default before, why is it doing it now?

It seems the default value for the new versions of debian & derivates:

Currently I don't have a new installation to verify, but you should be able to change the default value back to /var/www through the config files in /etc/apache2.

You could also move everything to your profile /home/lewashby/www/, it's just a matter of preferences.

Recursive set owner www-data for all www directories:

sudo chown -R 33 /var/www

Recursive set user group to YOU for all www directories:

sudo chgrp -R 1000 /var/www

Recursive set properties for owner and group - execute directories and read-write files, but other users read files and execute directories (lower rw and upper X set read-write files such as 0644 and execute dir such as 0755):

sudo chmod -R ug=rwX,o=rX /var/www

This 3 lines you can write in to the shell script file e.g. "properties.sh" (the file properties set executable) and call this file from command line always when you insert new files in to the /var/www

Sorry, 0775 for directories and 0664 for files

Thanks guys. I'll take a look at changing the root in the config file. Is there any reason not to use a web folder in my home directory instead of /var/www/ ? So for I've changed the owner to myself and the group to www-data, moved everthing to /var/www/html/ and it's working, just don't like changing from www to html.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.