Skip to content

Instantly share code, notes, and snippets.

@davidosomething
Last active December 13, 2015 17:29
Show Gist options
  • Save davidosomething/4948436 to your computer and use it in GitHub Desktop.
Save davidosomething/4948436 to your computer and use it in GitHub Desktop.
Script to update the PHP module version used by Apache in httpd.conf. Written for josegonzalez/homebrew-php but you can edit the path to the module file (change /usr/local/Cellar to whatever)
#!/bin/bash
# you should already have $APACHE_CONF, change these if your files aren't in those paths
export APACHE_HTTPD_CONF="$APACHE_CONF/httpd.conf"
export APACHE_HTTPD_VHOSTS="$APACHE_CONF/extra/httpd-vhosts.conf"
# these require awk and sed to get the PHP version and variants of it
export PHPVER="`php -v | sed 1q | awk '{print \$2}'`"
export PHPMINORVER="`echo $PHPVER | awk -F=\".\" '{split(\$0,a,\".\"); print a[1]\"\.\"a[2]}'`"
export PHPMINORVERNUM="`echo $PHPVER | awk -F=\".\" '{split(\$0,a,\".\"); print a[1]a[2]}'`"
# use sed to do the actual replacement. Written for josegonzalez/homebrew-php but you can edit the path to the module file.
sed "s/\/usr\/local\/Cellar\/php\([0-9]*\)\/\([\.0-9]*\)\//\/usr\/local\/Cellar\/php$PHPMINORVERNUM\/$PHPVER\//g" $APACHE_HTTPD_CONF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment