Add PHP.ini to user directory

From James Dooley's Wiki
Revision as of 14:23, 25 March 2014 by Smsldoo (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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

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

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

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