Skip to content

Instantly share code, notes, and snippets.

@gerarldlee
Created February 17, 2018 08:22
Show Gist options
  • Save gerarldlee/43dee3df71db9bc38ae837c1d1faa505 to your computer and use it in GitHub Desktop.
Save gerarldlee/43dee3df71db9bc38ae837c1d1faa505 to your computer and use it in GitHub Desktop.
https://fpira.com/blog/2016/04/install-php-raspberry-pi/
#!/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
@Ripax
Copy link

Ripax commented Jan 8, 2019

tnks for this

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