Method 1: Implementing suPHP

suPHP is an Apache module used to execute PHP scripts with the permissions of their file owners

This is how the server will work thanks to suPHP

If a PHP file have the owner "dexter" suPHP will execute that file as "dexter" and not as the Apache user aka "www-data",

If another file PHP file have the owner "adam" suPHP will execute that file as "adam" and not as the Apache user aka "www-data"

If another file PHP file have the owner "www-data" suPHP will execute that file as "www-data" which is the Apache user

If a folder have the owner "dexter" and it have a PHP file inside it with the owner "adam" the server will throw a "500" error when some one tries to request that file because it does not belong to "dexter"

If a any PHP script tries to read or write files or folders outside the server's document root, then the server will deny the action

If a file have too permissive permissions such as "chmod 666", then the server will throw a "500" error because suPHP don't allow too permissive permissions for security reasons

We already have suPHP installed, to Configure it follow this steps:

Open a terminal and Type

sudo gedit /etc/suphp/suphp.conf

Find the option "docroot" and set the location of your public_html folder, like this

docroot= /home/youruser/lamp/public_html

NOTE: You can place your new site folders on any location you desire, this is just an example, replace "youruser" with your actual Linux username

Save changes

Type in your terminal

sudo gedit /etc/apache2/mods-available/php5.conf

On your editor create a new empty line at the first line of the document and add this text there

<Directory /usr/share>

Then at the end of the document create another empty line and add this text there

</Directory>

As you can see we just enclosed the original content withing those lines

Save changes

Type in your terminal

sudo service apache2 restart

Lets create a file to do a quick test to see if suPHP is working correctly, type in your terminal

Open your browser and navigate to "localhost/whomi.php", most likely the browser will show you a "500" server error, this is because suPHP does not allow too permissive file and folder permissions and also does not allow mixed file and folder ownership, to correct this type in your terminal