Forked from pirafrank/install_latest_php_raspberrypi.sh
Created
November 1, 2016 13:26
-
-
Save celly/1daaf56346b680e869f4baa9a21e573a 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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.27" | |
### 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment