I scripted this, because it was annoying me.
By default phpbrew switch
will change the CLI version. To update Apache, you will have to tell it to use the newly generated .so
file. On Ubuntu this file will be created like /usr/lib/apache2/modules/libphp$VERSION.so
.
For this .so
file to be generated, you have to install PHP like:
phpbrew install php-5.6.16 +default +apxs2
Anyway, here's the shell script I use to switch PHP versions. The switch will fail if the .so
file cannot be found, and it will request sudo
privileges to restart Apache.
/home/luker/bin/phpbrewswitch
#!/usr/bin/env bash
VERSION=$1
SOFILE=/usr/lib/apache2/modules/libphp$VERSION.so
CONFFILE5=/etc/apache2/mods-available/php5.load
CONFFILE7=/etc/apache2/mods-available/php7.load
source ~/.phpbrew/bashrc
if [ -f $SOFILE ]; then
phpbrew switch $VERSION
phpbrew list
if [[ $VERSION == 7* ]]; then
FILECONTENTS="LoadModule php7_module $SOFILE"
CONFFILE=$CONFFILE7
sudo a2enmod php7
sudo a2dismod php5
else
FILECONTENTS="LoadModule php5_module $SOFILE"
CONFFILE=$CONFFILE5
sudo a2enmod php5
sudo a2dismod php7
fi;
echo $FILECONTENTS > $CONFFILE
echo "AddType application/x-httpd-php .php" >> $CONFFILE
echo "Updated $CONFFILE"
sudo service apache2 restart
else
echo $VERSION "is not configured for apache"
phpbrew list
fi
Usage
Attempting to switch to a PHP version that wasn't built for Apache:
[21:02:55] luker [~]$ phpbrewswitch 5.4.45
5.4.45 is not configured for apache
php-5.6.16
php-5.6.10
* php-5.5.30
php-5.4.45
Successfully changing to a PHP version that has an existing .so
file:
[21:03:55] luker [~]$ phpbrewswitch 5.6.16
* php-5.6.16
php-5.6.10
php-5.5.30
php-5.4.45
Updated /etc/apache2/mods-available/php5.load
phpbrew install
. it doesn't work onphpbrew use
orphpbrew switch
– Saransarangi