Monday, May 16, 2011

Creating a “Document Root” directory in Home directory on Ubuntu. ( Part 2 )

 ~*~ From the Part 1 ~*~

Make user that you have installed php5 in your system. If not execute following commands in terminal.

 sudo apt-get install php5  
 sudo a2enmod php5  

first line install the php5 and second line enables PHP in apache server. Then restart apache using,

 sudo /etc/init.d/apache2 restart  

At this point, Apache and PHP are installed and ready to go.

I’m using ubuntu lucid distribution,
A recent update to the Lucid distribution, however, requires a slight change to /etc/apache2/mods-available/php5.conf to re-enable interpretation in users' home directories, but previous distributions do not require this change.

Open give file using your favorite text editor. Here I am using gedit.

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

Comment out (or remove) the following lines:
 <ifmodule mod_userdir.c="">  
     <directory *="" home="" public_html="">  
       php_admin_value engine Off  
     </directory>  
 </ifmodule>  

After doing this change, restart apache using,
 sudo /etc/init.d/apache2 restart  

At this point, PHP should be successfully installed and working.

But this method will enable PHP for all user directories. For security reason this method is not a good practice. One thing can do is enable only for one user directory. To do this, follow this procedure.

Do not edit /etc/apache2/mods-available/php5.conf file and create a file (as root) called /etc/apache2/conf.d/php-in-homedirs.conf with the following contents:
 <ifmodule mod_userdir.c="">  
     <directory $username="" home="" public_html="">  
       php_admin_value engine On  
     </directory>  
 </ifmodule>  

Simply replace the $USERNAME with the user name of the user you wish to allow PHP access to. Also note that the <directory> section may be repeated as many times as is necessary. Save the file, and restart Apache with a
</directory>

 sudo /etc/init.d/apache2 restart  


And PHP should only be enabled for the users listed in this file.

~*~ End of Tutorial ~*~
=================================