iEFdev

Code, Computers & Random Junk

Script to Download PHP

This is a script I use download the PHP source code. Since I compile my 3 PHP version from source, it’s nice to have a script to download the source files. I updated the script recently, and noticed I haven’t posted it here either. So here it is…

php-dl

When you’ve made your changes (see below), then just run it like:

$ php-dl 7.0.8

The script will download the archive: php-N.N.N.tar.xz, and the signature: php-N.N.N.tar.xz.asc, and then verify it in the end if you have gpg2 installed.

You’ll need wget to download it. Otherwise - change it to curl if you want or prefer that.

php-dl(raw file at Github)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env bash
#
# Download php src + key
#
# Adjust: mirror, and your php src folder
#
# Example - structure:
#
# $ php-dl 7.0.8
#
# Will download/create folders like:
# - /path/to/php/7.0/7.0.8/php-7.0.8_build/
# - /path/to/php/7.0/7.0.8/php-7.0.8.tar.xz
# - /path/to/php/7.0/7.0.8/php-7.0.8.tar.xz.asc
# ------------------------------------------------------------
#

# Set your PHP mirror
phpmirror='se2';

# Set path to where your php download folder is
phpfolder="$HOME/Downloads/Server/php";

# Vars
# ------------------------------------------------------------
phpseries="${1%.*}";
phpversion="$1";
php_dl_folder="${phpfolder}/${phpseries}/${phpversion}";

# check input of $1
_base=$(basename $0);
if [ $# != 1 ] || [[ -z $1 ]]; then
    cat <<INFO
 :: Usage:  $_base <version>
            $_base 7.0.8
INFO
    exit 1
fi

# Set format (5.4 doesn't have "tar.xz")
[[ ${phpseries} == '5.4' ]] && _ext='tar.gz' || _ext='tar.xz';

# Create and goto folder
mkdir -p ${php_dl_folder}/php-${phpversion}_build && cd ${php_dl_folder};

# Download: src + key
for file in "${_ext}.asc" "${_ext}"; do
    wget -c http://${phpmirror}.php.net/get/php-${phpversion}.${file}/from/this/mirror \
    -O php-${phpversion}.${file};
done

# Verify the signature (asc file)
if [[ `type gpg2 2>/dev/null` ]]; then
    gpg2 --verify "php-${phpversion}.${_ext}.asc" "php-${phpversion}.${_ext}";
else
    echo "Couldn't find 'gpg2'. Please verify the signature.";
fi

# Reveal in Finder
if [[ `uname` == 'Darwin' ]]; then
    open .;
elif [[ `type xdg-open 2> /dev/null` ]]; then
    xgd-open .;
fi

exit;

You can also get the script on Github. octocat

Edits

There are two edits to look after - the two first variables.

phpmirror

Go to the PHP download page and find a mirror and the link.

Example: Sweden

http://se2.php.net/get/php-7.0.8.tar.xz/from/this/mirror

Change $phpmirror to match your mirror.

# Set your PHP mirror
phpmirror='se2';

phpfolder

Where on the computer to store… Change to match your setup.

phpfolder="$HOME/Downloads/Server/php";

Install it somewhere within PATH. I keep mine in a custom folder I use for my own script: /usr/local/xbin.

sudo install -v -m 0755 -o root -g wheel php-dl /usr/local/xbin

# verify
which php-dl

When downloading from time to time, you’ll eventually end up with a file/folder structure like this:

$HOME/Downloads/Server/php/
    5.4/
        5.4.45/
            php-5.4.45_build/
            php-5.4.45.tar.xz
            php-5.4.45.tar.xz.asc
    5.6/
        5.6.22/
            php-5.6.22_build/
            php-5.6.22.tar.xz
            php-5.6.22.tar.xz.asc
        5.6.23/
            php-5.6.23_build/
            php-5.6.23.tar.xz
            php-5.6.23.tar.xz.asc
    7.0/
        7.0.7/
            php-7.0.7_build/
            php-7.0.7.tar.xz
            php-7.0.7.tar.xz.asc
        7.0.8/
            php-7.0.8_build/
            php-7.0.8.tar.xz
            php-7.0.8.tar.xz.asc

# etc...

If you don’t want the build folder, you can edit the script. That’s just how I use it, and where I compile it from later.

cd php-N.N.N_build/
../php-N.N.N/configure --with-foo …

Happy hacking…

/Eric

Comments