Skip to content

Instantly share code, notes, and snippets.

@adrian-martinez-interactiv4
Created August 24, 2018 10:17
Show Gist options
  • Save adrian-martinez-interactiv4/f72814caa88cf1b6ed7b05e717a7b2f1 to your computer and use it in GitHub Desktop.
Save adrian-martinez-interactiv4/f72814caa88cf1b6ed7b05e717a7b2f1 to your computer and use it in GitHub Desktop.
Reinstall php
#!/bin/sh
php_versions_array=(
"5.6"
"7.0"
"7.1"
"7.2"
)
apache_conf_path="/usr/local/etc/httpd/httpd.conf"
echo "Updating Brew and cleaning up the house..."
brew update && brew upgrade && brew cleanup
echo "Uninstalling ALL existing php stuff..."
brew list | grep php | xargs -I {} brew uninstall --force {}
echo "Cleaning possible remaining existing folders..."
brew cleanup
rm -rf /usr/local/etc/php/*
for version in ${php_versions_array[@]}
do
echo "Installing php@$version..."
brew install php@$version
done
echo "Forcing first linking..."
brew link --force --overwrite php@${php_versions_array[0]}
echo "Reloading ~/.bash_profile..."
source ~/.bash_profile
echo "Updating $apache_conf_path for including proper configuration..."
sudo sed -i.bak "s/.*Brew PHP LoadModule .*//g" $apache_conf_path
sudo sed -i.bak "s/.*LoadModule php5_module .*//g" $apache_conf_path
sudo sed -i.bak "s/.*LoadModule php7_module .*//g" $apache_conf_path
echo "
# Brew PHP LoadModule for sphp switcher
#LoadModule php5_module /usr/local/opt/php@5.6/lib/httpd/modules/libphp5.so
#LoadModule php7_module /usr/local/opt/php@7.0/lib/httpd/modules/libphp7.so
#LoadModule php7_module /usr/local/opt/php@7.1/lib/httpd/modules/libphp7.so
#LoadModule php7_module /usr/local/opt/php@7.2/lib/httpd/modules/libphp7.so" >> $apache_conf_path
echo "Installing / updating sphp..."
curl -L https://gist.githubusercontent.com/rhukster/f4c04f1bf59e0b74e335ee5d186a98e2/raw > /usr/local/bin/sphp
chmod +x /usr/local/bin/sphp
echo "Installing / updating xdebug switcher..."
curl -L https://gist.githubusercontent.com/rhukster/073a2c1270ccb2c6868e7aced92001cf/raw > /usr/local/bin/xdebug
chmod +x /usr/local/bin/xdebug
echo "Reloading ~/.bash_profile..."
source ~/.bash_profile
for version in ${php_versions_array[@]}
do
/usr/local/bin/sphp $version
if [ $version = '5.6' ]; then
echo "Installing yaml..."
brew install libyaml
pecl uninstall -r yaml-1.3.1
printf "\n" | pecl install yaml-1.3.1
echo "Installing xdebug-2.5.5..."
pecl uninstall -r xdebug-2.5.5
printf "\n" | pecl install xdebug-2.5.5
else
echo "Installing yaml..."
pecl uninstall -r yaml
printf "\n" | pecl install yaml
echo "Installing xdebug..."
pecl uninstall -r xdebug
printf "\n" | pecl install xdebug
fi
echo "Fixing /usr/local/etc/php/$version/php.ini..."
sudo sed -i.bak "s/.*xdebug\.so.*//g" /usr/local/etc/php/$version/php.ini
sudo sed -i.bak "s/.*yaml\.so.*//g" /usr/local/etc/php/$version/php.ini
cat /usr/local/etc/php/$version/php.ini
echo "Writing /usr/local/etc/php/$version/conf.d/ext-xdebug.ini..."
touch /usr/local/etc/php/$version/conf.d/ext-xdebug.ini
echo '
[xdebug]
zend_extension="xdebug.so"
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_handler=dbgp
xdebug.remote_port=9000
xdebug.remote_autostart=1' > /usr/local/etc/php/$version/conf.d/ext-xdebug.ini
cat /usr/local/etc/php/$version/conf.d/ext-xdebug.ini
echo "Writing /usr/local/etc/php/$version/conf.d/ext-yaml.ini..."
touch /usr/local/etc/php/$version/conf.d/ext-yaml.ini
echo '
[yaml]
extension="yaml.so"' > /usr/local/etc/php/$version/conf.d/ext-yaml.ini
cat /usr/local/etc/php/$version/conf.d/ext-yaml.ini
done
echo "Restarting Apache..."
sudo apachectl restart
echo "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment