Skip to content

Instantly share code, notes, and snippets.

@rushipkar90
Created September 5, 2016 21:03
Show Gist options
  • Save rushipkar90/72e110cd45d7af96043d97f305562af7 to your computer and use it in GitHub Desktop.
Save rushipkar90/72e110cd45d7af96043d97f305562af7 to your computer and use it in GitHub Desktop.
PHP Upgrade Script
#/bin/bash
set -x
echo > /usr/local/src/customphpini.txt;
echo > /usr/local/src/commentphp.txt;
thetime=`date +"%Y-%m-%d-%S"`;
php -m > /usr/local/src/modules.txt
echo "================================" >> /usr/local/src/modules.txt
/usr/local/apache/bin/apachectl -M >> /usr/local/src/modules.txt
cp -ar /usr/local/apache/conf/httpd.conf /usr/local/apache/conf/httpd.conf_$thetime;
cp -ar /usr/local/lib/php.ini /usr/local/lib/php.ini_$thetime;
cp -ar /var/cpanel/easy/apache/profile/_main.yaml /var/cpanel/easy/apache/profile/_main.yaml_$thetime;
cat /var/cpanel/easy/apache/profile/_main.yaml | sed 's/"Cpanel::Easy::PHP5::5_38": 1/"Cpanel::Easy::PHP5::6_25": 1/g' > /var/cpanel/easy/apache/profile/custom/custom_hp_mod.yaml;
/scripts/easyapache --build --profile=custom_hp_mod.yaml;
CP_ACCOUNTS=`ls -1A /var/cpanel/users/ | grep -v "root"`
for user in `echo -n $CP_ACCOUNTS`
do
#echo $user;
maindomain=`cat /etc/trueuserdomains | grep "$user" | cut -d : -f1`;
homedir=`cat /var/cpanel/userdata/$user/$maindomain | grep homedir | cut -d / -f2`;
echo "$homedir";
if [ "$homedir" = home ]; then
find /home/$user -type d -name mail -prune -o -name "php.ini" -print >> /usr/local/src/customphpini.txt;
#find /home/$user -type f -name 'php.ini' | grep -v mail >> /usr/local/src/customphpini.txt;
else
#find /home2/$user -type f -name 'php.ini' | grep -v mail >> /usr/local/src/customphpini.txt;
find /home2/$user -type d -name mail -prune -o -name "php.ini" -print >> /usr/local/src/customphpini.txt;
fi
done
for j in `cat /usr/local/src/customphpini.txt`; do
#echo "$j";
cp -ar "$j" "$j"_$thetime;
phppath=`echo "$j" `;
for k in "$phppath "; do
replace "/usr/local/lib/php/extensions/no-debug-non-zts-20121212" "/usr/local/lib/php/extensions/no-debug-non-zts-20131226" -- $k;
replace "/usr/local/Zend/lib/Guard-7.0.0/php-5.5.x/ZendGuardLoader.so" "/usr/local/Zend/lib/Guard-7.0.0/php-5.6.x/ZendGuardLoader.so" -- $k;
replace "ioncube_loader_lin_5.5.so" "ioncube_loader_lin_5.6.so" -- $k;
done;
done;
php -m > /usr/local/src/upgrade_modules.txt
echo "================================" >> /usr/local/src/upgrade_modules.txt
/usr/local/apache/bin/apachectl -M >> /usr/local/src/upgrade_modules.txt
set +x
--------------------
I have uploaded a script “upgradephp.sh” on all shared servers under the location “/usr/local/src/”. You just need to run the script to upgrade PHP on the specified servers using the below command from the salt server:
salt -L <hostname>,<hostname2>,<hostname3> cmd.run "sh /usr/local/src/upgradephp.sh" ;
for e.g. salt -L hp90.hostpapa.com,hp97.hostpapa.com,hp107.hostpapa.com,
Note there should be no space between hostname and “,”.
The scripts performs the below actions:
1. Records the PHP and Apache modules before upgrade
2. Creates a backup of php.ini and httpd.conf files.
3. Creates backup of “/var/cpanel/easy/apache/profile/_main.yaml” file and updates the file with “PHP 5.6.25” version enabled and performs easyapache using the updated profile.
4. Once easyapache is complete, it looks for custom php.ini files on the server and updates the PHP extension path, ZendGuardLoader and ioncube_loader extension paths for all the custom php.ini files.
5. Records the PHP and Apache modules again after the upgrade.
Once the script has been executed successfully, kindly check the PHP version on the server and some sites randomly to ensure there are no errors after the upgrade. Further, monitor the apache error logs for some time.
--------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment