Last active
October 2, 2020 07:21
-
-
Save fchaussin/f77c3addacbb702abff48207d826abc1 to your computer and use it in GitHub Desktop.
Update php.ini local IP for Xdebug with PHP-FPM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# 2020 - @fchaussin [FCN] | |
if [[ $(/usr/bin/id -u) -ne 0 ]]; then | |
echo -e "Please exec this bash as superuser, with -E to keep your user environnement variables: | |
\e[32msudo -E ./xDebugIp.sh\e[39m" | |
exit | |
fi | |
php_version="7.2" | |
mysqlRestart=0 | |
xDebugRemoteEnable=1 | |
#remote_ip="10.1.1.149" | |
remote_ip=`sudo echo ${SSH_CLIENT%% *}` | |
if [[ $remote_ip == "" ]]; then | |
echo -e "Please use sudo with -E to keep your user environnement variables: | |
\e[32msudo -E ./xDebugIp.sh\e[39m" | |
exit | |
fi | |
echo -e "\e[90mUpdate xdebug.remote_host value in php.ini then restart concerned service. | |
- Use sudo -E (--preserve-env) to get your IP (currently\e[39m $remote_ip\e[90m) | |
- Use -d (--disable) to set remote_enable=0. (avoiding -d will auto set remote_enable=1) | |
- Use -m (--mysql-restart) to restart mySQL after all changes. | |
- Edit this bash script to change PHP version, if needed (currently\e[39m $php_version\e[90m)\e[39m | |
" | |
for arg in "$@" | |
do | |
if [ "$arg" == "--mysql-restart" ] || [ "$arg" == "-m" ] | |
then | |
mysqlRestart=1 | |
fi | |
if [ "$arg" == "--disable" ] || [ "$arg" == "-d" ] | |
then | |
xDebugRemoteEnable=0 | |
fi | |
done | |
# sed -i "s/xdebug\.remote_host\=.*/xdebug\.remote_host\=$ip/g" /etc/php/$php_version/cli/php.ini | |
# sed -i "s/xdebug\.remote_host\=.*/xdebug\.remote_host\=$ip/g" /etc/php/$php_version/apache2/php.ini | |
sed -i "s/xdebug\.remote_host\=.*/xdebug\.remote_host\=$remote_ip/g" /etc/php/$php_version/mods-available/xdebug.ini | |
sed -i "s/xdebug\.remote_host\=.*/xdebug\.remote_enable\=$xDebugRemoteEnable/g" /etc/php/$php_version/mods-available/xdebug.ini | |
echo "IP replaced in file:" | |
echo -e "\e[90m/etc/php/$php_version/mods-available/xdebug.ini\e[39m" | |
echo ----------------------------------- | |
echo -e "\e[90mxdebug.remote_enable=\e[32m$xDebugRemoteEnable\e[39m" | |
echo -e "\e[90mxdebug.remote_host=\e[32m$remote_ip\e[39m" | |
echo ----------------------------------- | |
# echo "Restart apache to apply changes" | |
# service apache2 restart | |
echo "Restart php $php_version FPM" | |
eval "service php${php_version}-fpm restart" | |
if [ $mysqlRestart == 1 ] | |
then | |
echo "Restart mysql service" | |
service mysql restart | |
fi | |
echo -e " | |
\e[36mLet's debug now!\e[39m | |
" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment