Skip to content

Instantly share code, notes, and snippets.

@syneart
Created May 17, 2016 13:04
Show Gist options
  • Save syneart/7f918d8ecbce2b5105a84609ef90705f to your computer and use it in GitHub Desktop.
Save syneart/7f918d8ecbce2b5105a84609ef90705f to your computer and use it in GitHub Desktop.
Turn On or Off php display_errors parameter on Ubuntu (to quick turn on display PHP error messages or not).
#!/bin/bash
DISPLAY_ERRORS_VAL=`grep display_errors.*=.* '/etc/php5/apache2/php.ini'`
clear
echo "Info: 目前 ${DISPLAY_ERRORS_VAL}";
echo "Info: 修改檔案需要權限, 請先輸入密碼 .."
sudo -v
if [ $? -eq 1 ]; then
clear
echo "Error: 未輸入正確密碼, 無法繼續執行"
sleep 3
exit 0
fi
clear
if grep -q -i Off <<<${DISPLAY_ERRORS_VAL} ; then
echo "Info: 已修改為 On";
sudo sed -i 's/display_errors = Off/display_errors = On/g' '/etc/php5/apache2/php.ini'
elif grep -q -i On <<<${DISPLAY_ERRORS_VAL} ; then
echo "Info: 已修改為 Off";
sudo sed -i 's/display_errors = On/display_errors = Off/g' '/etc/php5/apache2/php.ini'
else
echo "Error: php.ini 設定值有誤!!無法完成動作."
sleep 3
exit
fi
echo "Info: 重啟 apache2 服務中 ..."
sudo service apache2 restart
echo "Info: 完成!!"
sleep 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment