Difference between revisions of "Configuring a LAMPP server for PHP development/Linux server"

From Joomla! Documentation

< Configuring a LAMPP server for PHP development
(Created page with "{{underconstruction}} ==== Method 1: Implementing suPHP ==== suPHP is an Apache module used to execute PHP scripts with the permissions of their file owners This is how th...")
(No difference)

Revision as of 18:59, 5 September 2012

Documentation all together tranparent small.png
Under Construction

This article or section is in the process of an expansion or major restructuring. You are welcome to assist in its construction by editing it as well. If this article or section has not been edited in several days, please remove this template.
This article was last edited by Enav (talk| contribs) 11 years ago. (Purge)


Method 1: Implementing suPHP[edit]

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
echo "<?php echo 'whoim = '.exec('/usr/bin/whoami');?>" | tee /home/youruser/lamp/public_html/whomi.php
  • 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
sudo find /home/youruser/lamp/ -type f -exec chmod 644 {} \;
sudo find /home/youruser/lamp/ -type d -exec chmod 755 {} \;
sudo chown youruser:youruser -R /home/youruser/lamp/

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

Those commands enforce a secure and correct file and folder permission and also set a correct user and group ownership for all of them

  • Open your browser and navigate to "localhost/whomi.php", you should see something like this
whomi = youruser

That means the script is being executed with your user and not the Apache user unless you specified so