Skip to content

Instantly share code, notes, and snippets.

@pirafrank
Last active November 1, 2016 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pirafrank/2bce62d541af195aaea865d5102f1c09 to your computer and use it in GitHub Desktop.
Save pirafrank/2bce62d541af195aaea865d5102f1c09 to your computer and use it in GitHub Desktop.
install the PHP version you want on Raspbian. Tested with 5.5 and 5.6. It may work for PHP 7.x, too.
#!/bin/bash
# credits: http://stackoverflow.com/questions/31280912/how-to-install-php-5-6-on-raspbian-wheezy
### VARIABLES ###
# type here the specific php 5.x version you want to install
PHP_VERSION="5.6.20"
### SCRIPT ###
# check if script is running as root
if [[ $EUID -ne 0 ]]; then
echo "Sorry, you have to be root."
echo "Try again using sudo"
exit 1
else
echo "Running as root..."
fi
# getting real number of cores
# CORES=$(cat /proc/cpuinfo | grep Hardware | wc -l)
# Check PHP version before start
# latest version in repo should be 5.4, which is no longer supported.
echo "Currently installed PHP version is..."
php -v
# working in temporary dir
mkdir -p /tmp/php_install
cd /tmp/php_install
# Get the PHP source
# You can find the latest version number on the PHP download page: http://php.net/downloads.php
# Change `nl1` to your nearest mirror. Find the mirror list here: http://php.net/mirrors.php.
wget http://nl1.php.net/distributions/php-$PHP_VERSION.tar.bz2
# Unpack
tar -xvjf php-$PHP_VERSION.tar.bz2
cd php-$PHP_VERSION
apt-get update
apt-get install libxml2-dev
./configure
# getting cpu architecture
RPI_HW=$(cat /proc/cpuinfo | grep Hardware | awk '{print $3}' | head -1)
if [ "$RPI_HW" = "BCM2709" ]; then
# if on RPi 2 or RPi 3 use 4 cores.
make -j4
else
# if on RPi 1 or unrecognized cpu (future Pis?) use 1 core
make
fi
make install
# Check PHP version
echo "now printing the newly installed PHP version..."
php -v
@celly
Copy link

celly commented Nov 1, 2016

Awesome. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment