|
| 1 | +#!/bin/bash |
| 2 | +set -x |
| 3 | + |
| 4 | +function setup() { |
| 5 | + read -p 'Which PHP version would you like to install?[latest-7.1/latest-7.2/latest-7.3/default: latest-7.4/latest-8.0/latest-master/q (quit)] ' PHPINSTALLVERSION |
| 6 | + PHPINSTALLVERSION=${PHPINSTALLVERSION:-latest-7.4} |
| 7 | + |
| 8 | + # Setup Correct files depending on PHP installation version choice |
| 9 | + if [ "$PHPINSTALLVERSION" = latest-7.1 ]; then |
| 10 | + read -p 'latest-7.1 is outdated and has been superseded by latest-7.2. Would you like to continue installation?[y/Y/default: n/N] ' OUTDATEDCHOICE |
| 11 | + OUTDATEDCHOICE=${OUTDATEDCHOICE:-n} |
| 12 | + if [ "$OUTDATEDCHOICE" = y ] || [ "$OUTDATEDCHOICE" = Y ]; then |
| 13 | + cd ../../releases/ || exit |
| 14 | + ls latest-7.1 |
| 15 | + ISFOLDERPRESENT=$? |
| 16 | + if [ "$ISFOLDERPRESENT" = 2 ]; then |
| 17 | + unzip php-src-php-7.1.32.zip -d latest-7.1 |
| 18 | + cd latest-7.1 || exit |
| 19 | + elif [ "$ISFOLDERPRESENT" = 0 ]; then |
| 20 | + read -p 'There already is a folder with this version of PHP. Would you like to remove it?[default: n/N/y/Y] ' FOLDERCHOICE |
| 21 | + FOLDERCHOICE=${FOLDERCHOICE:-n} |
| 22 | + if [ "$FOLDERCHOICE" = y ] || [ "$FOLDERCHOICE" = Y ]; then |
| 23 | + sudo rm -r latest-7.1 |
| 24 | + unzip php-src-php-7.1.32.zip -d latest-7.1 |
| 25 | + cd latest-7.1 || exit |
| 26 | + elif [ "$FOLDERCHOICE" = n ] || [ "$FOLDERCHOICE" = N ]; then |
| 27 | + echo cancelling installation |
| 28 | + setup |
| 29 | + else |
| 30 | + echo invalid argument, exiting... |
| 31 | + setup |
| 32 | + fi |
| 33 | + fi |
| 34 | + elif [ "$OUTDATEDCHOICE" = n ] || [ "$OUTDATEDCHOICE" = N ]; then |
| 35 | + echo cancelling installation |
| 36 | + setup |
| 37 | + else |
| 38 | + echo invalid argument, exiting... |
| 39 | + setup |
| 40 | + fi |
| 41 | + |
| 42 | + elif [ "$PHPINSTALLVERSION" = latest-7.2 ]; then |
| 43 | + read -p 'latest-7.2 is outdated and has been superseded by latest-7.3. Would you like to continue installation?[y/Y/default: n/N] ' OUTDATEDCHOICE |
| 44 | + OUTDATEDCHOICE=${OUTDATEDCHOICE:-n} |
| 45 | + if [ "$OUTDATEDCHOICE" = y ] || [ "$OUTDATEDCHOICE" = Y ]; then |
| 46 | + cd ../../releases/ || exit |
| 47 | + ls latest-7.2 |
| 48 | + ISFOLDERPRESENT=$? |
| 49 | + if [ "$ISFOLDERPRESENT" = 2 ]; then |
| 50 | + unzip php-src-php-7.2.33.zip -d latest-7.2 |
| 51 | + cd latest-7.2 || exit |
| 52 | + elif [ "$ISFOLDERPRESENT" = 0 ]; then |
| 53 | + read -p 'There already is a folder with this version of PHP. Would you like to remove it?[default: n/N/y/Y] ' FOLDERCHOICE |
| 54 | + FOLDERCHOICE=${FOLDERCHOICE:-n} |
| 55 | + if [ "$FOLDERCHOICE" = y ] || [ "$FOLDERCHOICE" = Y ]; then |
| 56 | + sudo rm -r latest-7.2 |
| 57 | + unzip php-src-php-7.2.33.zip -d latest-7.2 |
| 58 | + cd latest-7.2 || exit |
| 59 | + elif [ "$FOLDERCHOICE" = n ] || [ "$FOLDERCHOICE" = N ]; then |
| 60 | + echo cancelling installation |
| 61 | + setup |
| 62 | + else |
| 63 | + echo invalid argument, exiting... |
| 64 | + setup |
| 65 | + fi |
| 66 | + fi |
| 67 | + elif [ "$OUTDATEDCHOICE" = n ] || [ "$OUTDATEDCHOICE" = N ]; then |
| 68 | + echo cancelling installation |
| 69 | + setup |
| 70 | + else |
| 71 | + echo invalid argument, exiting... |
| 72 | + setup |
| 73 | + fi |
| 74 | + elif [ "$PHPINSTALLVERSION" = latest-7.3 ]; then |
| 75 | + read -p 'latest-7.3 is outdated and has been superseded by latest-7.4. Would you like to continue installation?[y/Y/default: n/N] ' OUTDATEDCHOICE |
| 76 | + OUTDATEDCHOICE=${OUTDATEDCHOICE:-n} |
| 77 | + if [ "$OUTDATEDCHOICE" = y ] || [ "$OUTDATEDCHOICE" = Y ]; then |
| 78 | + cd ../../releases/ || exit |
| 79 | + ls latest-7.3 |
| 80 | + ISFOLDERPRESENT=$? |
| 81 | + if [ "$ISFOLDERPRESENT" = 2 ]; then |
| 82 | + unzip php-src-php-7.3.22RC1.zip -d latest-7.3 |
| 83 | + cd latest-7.3 || exit |
| 84 | + elif [ "$ISFOLDERPRESENT" = 0 ]; then |
| 85 | + read -p 'There already is a folder with this version of PHP. Would you like to remove it?[default: n/N/y/Y] ' FOLDERCHOICE |
| 86 | + FOLDERCHOICE=${FOLDERCHOICE:-n} |
| 87 | + if [ "$FOLDERCHOICE" = y ] || [ "$FOLDERCHOICE" = Y ]; then |
| 88 | + sudo rm -r latest-7.3 |
| 89 | + unzip php-src-php-7.3.22RC1.zip -d latest-7.3 |
| 90 | + cd latest-7.3 || exit |
| 91 | + elif [ "$FOLDERCHOICE" = n ] || [ "$FOLDERCHOICE" = N ]; then |
| 92 | + echo cancelling installation |
| 93 | + setup |
| 94 | + else |
| 95 | + echo invalid argument, exiting... |
| 96 | + setup |
| 97 | + fi |
| 98 | + fi |
| 99 | + elif [ "$OUTDATEDCHOICE" = n ] || [ "$OUTDATEDCHOICE" = N ]; then |
| 100 | + echo cancelling installation |
| 101 | + setup |
| 102 | + else |
| 103 | + echo invalid argument, exiting... |
| 104 | + setup |
| 105 | + fi |
| 106 | + elif [ "$PHPINSTALLVERSION" = latest-7.4 ]; then |
| 107 | + cd ../../releases/ || exit |
| 108 | + ls latest-7.4 |
| 109 | + ISFOLDERPRESENT=$? |
| 110 | + if [ "$ISFOLDERPRESENT" = 2 ]; then |
| 111 | + unzip php-src-php-7.4.10RC1.zip -d latest-7.4 |
| 112 | + cd latest-7.4 || exit |
| 113 | + elif [ "$ISFOLDERPRESENT" = 0 ]; then |
| 114 | + read -p 'There already is a folder with this version of PHP. Would you like to remove it?[default: n/N/y/Y] ' FOLDERCHOICE |
| 115 | + FOLDERCHOICE=${FOLDERCHOICE:-n} |
| 116 | + if [ "$FOLDERCHOICE" = y ] || [ "$FOLDERCHOICE" = Y ]; then |
| 117 | + sudo rm -r latest-7.4 |
| 118 | + unzip php-src-php-7.4.10RC1.zip -d latest-7.4 |
| 119 | + cd latest-7.4 || exit |
| 120 | + elif [ "$FOLDERCHOICE" = n ] || [ "$FOLDERCHOICE" = N ]; then |
| 121 | + echo cancelling installation |
| 122 | + setup |
| 123 | + else |
| 124 | + echo invalid argument, exiting... |
| 125 | + setup |
| 126 | + fi |
| 127 | + fi |
| 128 | + elif [ "$PHPINSTALLVERSION" = latest-8.0 ]; then |
| 129 | + read -p 'This a BETA PHP version and. This software has been tested, but bugs and errors are bound to appear in this early stage. This should not be used in a production environment. Are you sure you want to install?[y/Y/default: n/N] ' INSTALLCHOICE |
| 130 | + INSTALLCHOICE=${INSTALLCHOICE:-n} |
| 131 | + |
| 132 | + if [ "$INSTALLCHOICE" = y ] || [ "$INSTALLCHOICE" = Y ]; then |
| 133 | + cd ../../releases/ || exit |
| 134 | + ls latest-8.0 |
| 135 | + ISFOLDERPRESENT=$? |
| 136 | + if [ "$ISFOLDERPRESENT" = 2 ]; then |
| 137 | + unzip php-src-php-8.0.0beta2.zip -d latest-8.0 |
| 138 | + cd latest-8.0 || exit |
| 139 | + elif [ "$ISFOLDERPRESENT" = 0 ]; then |
| 140 | + read -p 'There already is a folder with this version of PHP. Would you like to remove it?[default: n/N/y/Y] ' FOLDERCHOICE |
| 141 | + FOLDERCHOICE=${FOLDERCHOICE:-n} |
| 142 | + if [ "$FOLDERCHOICE" = y ] || [ "$FOLDERCHOICE" = Y ]; then |
| 143 | + sudo rm -r latest-8.0 |
| 144 | + unzip php-src-php-8.0.0beta2.zip -d latest-8.0 |
| 145 | + cd latest-8.0 || exit |
| 146 | + elif [ "$FOLDERCHOICE" = n ] || [ "$FOLDERCHOICE" = N ]; then |
| 147 | + echo cancelling installation |
| 148 | + setup |
| 149 | + else |
| 150 | + echo invalid argument, exiting... |
| 151 | + setup |
| 152 | + fi |
| 153 | + fi |
| 154 | + elif [ "$INSTALLCHOICE" = n ] || [ "$INSTALLCHOICE" = N ]; then |
| 155 | + echo cancelling installation |
| 156 | + setup |
| 157 | + else |
| 158 | + echo invalid argument, exiting... |
| 159 | + setup |
| 160 | + fi |
| 161 | + elif [ "$PHPINSTALLVERSION" = latest-master ]; then |
| 162 | + read -p 'CAREFUL: This is a pre-release version and is in heavy development. Install this only if you want the latest bleeding-edge features. These may not have been tested thoroughly and should not be used in a production environment. Are you sure you want to install?[y/Y/default: n/N] ' INSTALLCHOICE |
| 163 | + INSTALLCHOICE=${INSTALLCHOICE:-n} |
| 164 | + if [ "$INSTALLCHOICE" = y ] || [ "$INSTALLCHOICE" = Y ]; then |
| 165 | + cd ../../releases/ || exit |
| 166 | + sudo rm -r php-src |
| 167 | + git clone https://github.com/php/php-src.git |
| 168 | + cd php-src || exit |
| 169 | + elif [ "$INSTALLCHOICE" = n ] || [ "$INSTALLCHOICE" = N ]; then |
| 170 | + echo cancelling installation |
| 171 | + git chekout master |
| 172 | + setup |
| 173 | + else |
| 174 | + echo invalid argument, exiting... |
| 175 | + git checkout master |
| 176 | + setup |
| 177 | + fi |
| 178 | + elif [ "$PHPINSTALLVERSION" = q ] || [ "$PHPINSTALLVERSION" = quit ]; then |
| 179 | + echo cancelling installation |
| 180 | + exit 130 |
| 181 | + fi |
| 182 | + |
| 183 | + # Install dependencies using APT |
| 184 | + # Code goes below for installing dependencies |
| 185 | + PREVDIR=$(pwd) |
| 186 | + echo installing dependencies |
| 187 | + mkdir iconvSRC |
| 188 | + cd iconvSRC || exit |
| 189 | + ICONVSRCDIR=$(pwd) |
| 190 | + wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.16.tar.gz |
| 191 | + tar -xvzf libiconv-1.16.tar.gz |
| 192 | + cd libiconv-1.16 || exit |
| 193 | + ./configure --prefix=/usr/local/libiconv |
| 194 | + make |
| 195 | + sudo make install |
| 196 | + cd "$ICONVSRCDIR" || exit |
| 197 | + cd .. |
| 198 | + sudo rm -r iconvSRC |
| 199 | + cd "$PREVDIR" || exit |
| 200 | + sudo apt-get install -y pkg-config build-essential autoconf bison re2c \ |
| 201 | + libxml2-dev libsqlite3-dev openssl libssl-dev libcurl4-openssl-dev libenchant-dev libpng-dev libwebp-dev libjpeg-dev libfreetype6-dev libonig-dev libsodium-dev libtidy-dev libzip-dev |
| 202 | + # Go into the right directory depending on PHP installation version |
| 203 | + if [ "$PHPINSTALLVERSION" = latest-7.1 ]; then |
| 204 | + cd php-src-php-7.1.32/ || exit |
| 205 | + elif [ "$PHPINSTALLVERSION" = latest-7.2 ]; then |
| 206 | + cd php-src-php-7.2.33/ || exit |
| 207 | + elif [ "$PHPINSTALLVERSION" = latest-7.3 ]; then |
| 208 | + cd php-src-php-7.3.22RC1/ || exit |
| 209 | + elif [ "$PHPINSTALLVERSION" = latest-7.4 ]; then |
| 210 | + cd php-src-php-7.4.10RC1/ || exit |
| 211 | + elif [ "$PHPINSTALLVERSION" = latest-8.0 ]; then |
| 212 | + cd php-src-php-8.0.0beta2/ || exit |
| 213 | + elif [ "$PHPINSTALLVERSION" = latest-master ]; then |
| 214 | + cd . |
| 215 | + fi |
| 216 | +} |
| 217 | + |
| 218 | +# Configure PHP (./buildconf and ./configure) |
| 219 | +function configure() { |
| 220 | + echo Building configuration script |
| 221 | + # Build the configure script |
| 222 | + sudo ./buildconf --force || exit |
| 223 | + echo Built Configuration Script |
| 224 | + # Configure PHP Installation |
| 225 | + echo Configuring PHP |
| 226 | + # Configure PHP per install version choice |
| 227 | + if [ "$PHPINSTALLVERSION" = latest-8.0 ] || [ "$PHPINSTALLVERSION" = latest-master ]; then |
| 228 | + sudo ./configure --with-openssl=/usr/lib/ssl --enable-bcmath --enable-calendar --with-curl --with-enchant --enable-ftp --enable-gd --with-webp --with-jpeg --with-freetype --with-mhash --with-iconv=/usr/local/libiconv --with-imap-ssl --enable-mbstring --enable-pdo --with-pdo-mysql=mysqlnd --enable-shmop --enable-soap --enable-sockets --with-sodium --with-password-argon2 --enable-sysvmsg --enable-sysvsem --enable-sysvshm --with-tidy --with-zip || exit |
| 229 | + elif [ "$PHPINSTALLVERSION" = latest-7.4 ]; then |
| 230 | + sudo ./configure --with-openssl --enable-bcmath --enable-calendar --with-curl --enable-ftp --enable-gd --with-webp --with-jpeg --with-freetype --with-mhash --with-iconv=/usr/local/libiconv --with-imap-ssl --enable-mbstring --enable-pdo --with-pdo-mysql=mysqlnd --enable-shmop --enable-soap --enable-sockets --with-sodium --with-password-argon2 --enable-sysvmsg --enable-sysvsem --enable-sysvshm --with-tidy --with-zip || exit |
| 231 | + elif [ "$PHPINSTALLVERSION" = latest-7.3 ]; then |
| 232 | + sudo ./configure --with-openssl --enable-bcmath --enable-calendar --with-curl --enable-ftp --enable-gd --with-webp --with-jpeg --with-freetype --with-mhash --without-iconv --with-imap-ssl --enable-mbstring --enable-pdo --with-pdo-mysql=mysqlnd --enable-shmop --enable-soap --enable-sockets --with-sodium --with-password-argon2 --enable-sysvmsg --enable-sysvsem --enable-sysvshm --with-zip || exit |
| 233 | + elif [ "$PHPINSTALLVERSION" = latest-7.2 ]; then |
| 234 | + sudo ./configure --with-openssl --enable-bcmath --enable-calendar --with-curl --enable-ftp --with-mhash --without-iconv --with-imap-ssl --enable-mbstring --enable-pdo --with-pdo-mysql=mysqlnd --enable-shmop --enable-soap --enable-sockets --with-sodium --with-password-argon2 --enable-sysvmsg --enable-sysvsem --enable-sysvshm || exit |
| 235 | + elif [ "$PHPINSTALLVERSION" = latest-7.1 ]; then |
| 236 | + sudo ./configure --with-openssl --enable-bcmath --enable-calendar --with-curl --enable-ftp --with-mhash --without-iconv --with-imap-ssl --enable-mbstring --enable-pdo --with-pdo-mysql=mysqlnd --enable-shmop --enable-soap --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm || exit |
| 237 | + fi |
| 238 | + echo Configured PHP |
| 239 | +} |
| 240 | + |
| 241 | +# Build PHP (make) |
| 242 | +function build() { |
| 243 | + # Set the Job Count for make |
| 244 | + echo Setting job count for make |
| 245 | + # Set the make job count for the lowest buid time |
| 246 | + THREADCOUNT=$(grep -c ^processor /proc/cpuinfo) |
| 247 | + JOBCOUNT=$((THREADCOUNT + 1)) |
| 248 | + echo Set job count for make |
| 249 | + # Build PHP |
| 250 | + echo Building PHP |
| 251 | + # Build PHP using make |
| 252 | + sudo make -j"$JOBCOUNT" || exit |
| 253 | + echo Built PHP |
| 254 | +} |
| 255 | + |
| 256 | +# Test PHP (make test) |
| 257 | +function test() { |
| 258 | + echo Testing PHP |
| 259 | + # Test PHP per PHP version choice |
| 260 | + if [ "$PHPINSTALLVERSION" = latest-8.0 ] || [ "$PHPINSTALLVERSION" = latest-master ] || [ "$PHPINSTALLVERSION" = latest-7.4 ]; then |
| 261 | + sudo make TEST_PHP_ARGS=-j"$JOBCOUNT" test |
| 262 | + elif [ "$PHPINSTALLVERSION" = latest-7.3 ]; then |
| 263 | + sudo make test -j"$JOBCOUNT" |
| 264 | + elif [ "$PHPINSTALLVERSION" = latest-7.2 ]; then |
| 265 | + sudo make test -j"$JOBCOUNT" |
| 266 | + elif [ "$PHPINSTALLVERSION" = latest-7.1 ]; then |
| 267 | + sudo make test -j"$JOBCOUNT" |
| 268 | + fi |
| 269 | + |
| 270 | + echo Tested PHP |
| 271 | +} |
| 272 | + |
| 273 | +# Install PHP CLI (make install) |
| 274 | +function installCLI() { |
| 275 | + # Ask the user if the PHP CLI should be installed or not |
| 276 | + read -p 'The tests have been completed and you may or may not have had failures on some of them. This can sometimes be ignored with the latest builds, or may need extra attention. Would you like to continue with installation?[default: y/Y/n/N] ' ERRORRESPONSE |
| 277 | + ERRORRESPONSE=${ERRORRESPONSE:-y} |
| 278 | + if [ "$ERRORRESPONSE" = y ] || [ "$ERRORRESPONSE" = Y ]; then |
| 279 | + # Install PHP CLI |
| 280 | + echo Installing PHP-CLI |
| 281 | + sudo make install || exit |
| 282 | + echo Installed PHP-CLI |
| 283 | + exit 0 |
| 284 | + elif [ "$ERRORRESPONSE" = n ] || [ "$ERRORRESPONSE" = N ]; then |
| 285 | + # Cancel install, go back to setup |
| 286 | + echo cancelled installation |
| 287 | + git checkout master |
| 288 | + setup |
| 289 | + fi |
| 290 | +} |
| 291 | + |
| 292 | +setup |
| 293 | +configure |
| 294 | +build |
| 295 | +test |
| 296 | +installCLI |
| 297 | +exit 0 |
0 commit comments