Configuring a LAMPP server for PHP development/Linux server

From Joomla! Documentation

< Configuring a LAMPP server for PHP development
Copyedit.png
This Article Needs Your Help

This article is tagged because it TECHNICAL REVIEW. You can help the Joomla! Documentation Wiki by contributing to it.
More pages that need help similar to this one are here. NOTE-If you feel the need is satistified, please remove this notice.

Reason: Needs updating to latest PHP/MySQL Versions


Open a terminal and type: sudo apt-get install apache2 php5-mysql libapache2-mod-php5 mysql-server phpmyadmin libapache2-mod-suphp

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 has the owner dexter, suPHP will execute that file as dexter and not as the Apache user, www-data.
  • If another PHP file has the owner adam, suPHP will execute that file as adam and not as the Apache user www-data.
  • If another PHP file has the owner www-data, suPHP will execute that file as www-data which is the Apache user.
  • If a folder has the owner dexter and it has a PHP file inside it with the owner adam, the server will throw a 500 error when someone 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, the server will deny the action.
  • If a file is too permissive permissions such as chmod 666, the server will throw a 500 error because suPHP doesn't allow too permissive permissions.

We already have suPHP installed. To configure it follow these 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. 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:

<Directory /usr/share>

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

</Directory>

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

Save the changes.

Type in your terminal:

sudo service apache2 restart

Let's 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 file and folder permissions that are too permissive 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 in any location. This is just an example. Replace youruser with your actual Linux username.

Those commands enforce a secure file and folder permissions and also set a correct user and group ownership for all.

Open your browser and navigate to localhost/whomi.php. You should see something like this:

whomi = youruser

That means the script is being executed by your user and not the Apache user unless you specified that.