Skip to content

Instantly share code, notes, and snippets.

@willwade
Created April 1, 2012 15:56
Show Gist options
  • Select an option

  • Save willwade/2276565 to your computer and use it in GitHub Desktop.

Select an option

Save willwade/2276565 to your computer and use it in GitHub Desktop.
Switch PHP
################################################################################
# Setphp helps out in running Apache with either php4 or php5 and makes
# switching between these versions easy.
#
# Author: Bjorn Wijers <http://www.burobjorn.nl>
#
# I was inspired by this post
# http://www.entropy.ch/phpbb2/viewtopic.php?p=5842#5842
#
#
# DESCRIPTION:
# Before using this script, please follow these instructions.
#
# [ 0 ] make sure you have downloaded the php4 and php5
# packages found at: http://www.entropy.ch/software/macosx/php/
#
# [ 1 ] install PHP 4 and configure the httpd.conf file to your liking.
# Once that is done, save a copy of the file as php4.httpd.conf in /etc/httpd/
#
# [ 2 ] install PHP 5 and configure the new httpd.conf file to suit your PHP 5 work.
# Once that is done, save a copy of the file as php5.httpd.conf in /etc/httpd/.
#
# [ 3 ] create a file called phpinfo.php and copy these contents into it:
# <?php phpinfo(); ?>
#
# [ 4 ] copy the above created file into your webdirectory
# Usually: /Users/username/Sites/ (where username is your username)
#
# [ 5 ] copy this script anywhere in your PATH. A good place would be:
# /usr/local/bin/
#
# [ 6 ] make sure the script is executable, i.e. chmod ug+x setphp
#
# [ 7 ] each time you would like to switch from php version just open an terminal
# and type: setphp phpX (where phpX is php4 or php5)
#
# [ 8 ] check if the script worked as expected by going to 127.0.0.1/phpinfo.php
# this would give you the specific php4 or php5 version
#
# This script was made in the hope it would make my life easier, feel free to
# use and abuse it as you see fit. However WITHOUT ANY WARRANTY. So if this
# script causes your computer to tell bad jokes, its not my problem.
#
################################################################################
#!/bin/bash
# if php4 or php5 are are passed as parameters then set this as the input and
# don't ask questions. If no parameters are included ask which version of php should
# be activated.
if [[ "$1 " == php5 || "$1" == php4 ]]; then
INPUT=$1;
else
echo -n "Please enter which version of php you would like to start (php4/php5): ";
read -e INPUT;
fi
if [ "$INPUT" == php4 ]; then
echo "copying php4 config file...";
sudo cp /etc/httpd/php4.httpd.conf /etc/httpd/httpd.conf;
echo "restarting Apache graceful..";
sudo apachectl graceful;
echo "Apache with php4 should be running now";
elif [ "$INPUT" == php5 ]; then
echo "copying php5 config file...";
sudo cp /etc/httpd/php5.httpd.conf /etc/httpd/httpd.conf;
echo "restarting Apache graceful..";
sudo apachectl graceful;
echo "Apache with php5 should be running now";
else
echo "Oops, wrong input. You can only choose between php4 or php5";
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment