Difference between revisions of "Add PHP.ini to user directory"
From James Dooley's Wiki
| (5 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
| + | [[Category:One Liners]] | ||
==Overview== | ==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. | 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. | ||
| Line 8: | Line 9: | ||
===SuPHP Version=== | ===SuPHP Version=== | ||
| − | < | + | <source lang='bash'> |
| + | 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 | ||
| + | </source> | ||
===Non SuPHP Version=== | ===Non SuPHP Version=== | ||
| − | < | + | <source lang='bash'> |
| − | + | 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 | ||
| + | </source> | ||
==What to change== | ==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 | 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 | ||
| − | < | + | <source lang='bash'> |
| + | 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 | ||
| + | </source> | ||
Latest revision as of 14:23, 25 March 2014
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