Difference between revisions of "Add PHP.ini to user directory"

From James Dooley's Wiki
Jump to: navigation, search
(Non SuPHP Version)
(SuPHP Version)
Line 8: Line 8:
  
 
===SuPHP Version===
 
===SuPHP Version===
<code>[bash,n]echo "User Name:"; read username;
+
<code>[bash,n]
  cp `php -i | grep php.ini | grep Loaded | awk '{print $5}'` /home/$username;
+
echo "User Name:"; read username; \
echo -e "\nsuPHP_ConfigPath /home/$username\n<Files php.ini>\n\torder allow,deny\n\tdeny from all\n</files>" >> /home/$username/.htaccess;
+
  cp `php -i | grep php.ini | grep Loaded | awk '{print $5}'` /home/$username; \
  chown $username. /home/$username/php.ini;
+
echo -e "\nsuPHP_ConfigPath /home/$username\n<Files php.ini>\n\torder allow,deny\n\tdeny from all\n</files>" >> /home/$username/.htaccess; \
  chown $username. /home/$username/.htaccess</code>
+
  chown $username. /home/$username/php.ini; \
 +
  chown $username. /home/$username/.htaccess
 +
</code>
  
 
===Non SuPHP Version===
 
===Non SuPHP Version===

Revision as of 20:05, 16 September 2011

Overview

This script is set up to copy the current php.ini file to a users directory and block web users from being able to view it in .htaccess.

There are two versions of this script, one for SuPHP one without.

Script

Script will ask for a user name every time this is run. If working with a list you can put it inside a loop and remove everything before the cp

SuPHP Version

[bash,n] echo "User Name:"; read username; \

cp `php -i | grep php.ini | grep Loaded | awk '{print $5}'` /home/$username; \

echo -e "\nsuPHP_ConfigPath /home/$username\n<Files php.ini>\n\torder allow,deny\n\tdeny from all\n</files>" >> /home/$username/.htaccess; \

chown $username. /home/$username/php.ini; \
chown $username. /home/$username/.htaccess

Non SuPHP Version

[bash,n]echo "User Name:"; read username; cp `php -i | grep php.ini | grep Loaded | awk '{print $5}'` /home/$username; \ echo -e "\n<Files php.ini>\n\torder allow,deny\n\tdeny from all\n</files>" >> /home/$username/.htaccess; \ chown $username. /home/$username/php.ini; chown $username. /home/$username/.htaccess

What to change

No real changes need to be made unless you want to read a list of users from a file then you could use something like

[bash,n]for username in $(cat users.txt); do cp `php -i | grep php.ini | grep Loaded | awk '{print $5}'` /home/$username; echo -e "\nsuPHP_ConfigPath /home/$username\n<Files php.ini>\n\torder allow,deny\n\tdeny from all\n</files>" >> /home/$username/.htaccess;

chown $username. /home/$username/php.ini; chown $username. /home/$username/.htaccess; done