Skip to content

Instantly share code, notes, and snippets.

@jaywilliams
Last active May 18, 2023 16:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaywilliams/979039 to your computer and use it in GitHub Desktop.
Save jaywilliams/979039 to your computer and use it in GitHub Desktop.
Installing PHP 7.4.33 as CGI on *new* Pair Networks architecture
# Installing PHP 7.4.33 as CGI/FastCGI on a Pair Networks VPS
# By Jay Williams <http://myd3.com/>
# Based off of the Pair Users wiki page "Installing PHP5 as cgi" <http://www.pairusers.com/?How%20to%20install%20PHP5>
# Note: Replace "USERNAME" with your actual server username
# Make src directory in home
mkdir ~/src
# Download, configure, and compile OpenSSL
cd ~/src
wget https://github.com/openssl/openssl/releases/download/OpenSSL_1_1_1t/openssl-1.1.1t.tar.gz
tar zxf openssl-1.1.1t.tar.gz
cd openssl-1.1.1t
./Configure --prefix=$HOME/bin -fPIC -shared linux-x86_64
make -j 8
make install
export PKG_CONFIG_PATH=/usr/home/USERNAME/bin/lib/pkgconfig
# Download, configure, and compile PHP
cd ~/src
wget https://www.php.net/distributions/php-7.4.33.tar.gz
tar zxf php-7.4.33.tar.gz
cd php-7.4.33
# Make a directory to store our php ini file
mkdir -p ~/phpini/php74
'./configure' '--with-config-file-path=/usr/home/USERNAME/phpini/php74' '--enable-debug=no' '--enable-fpm' '--with-openssl' '--with-openssl-dir=/usr/home/USERNAME/bin/include/openssl' '--with-zlib' '--enable-bcmath' '--with-bz2' '--enable-calendar' '--with-curl' '--enable-dba' '--with-gdbm' '--with-db4' '--enable-exif' '--enable-gd' '--with-jpeg' '--with-freetype' '--with-gettext' '--with-gmp' '--enable-mbstring' '--with-mhash' '--with-mysqli=mysqlnd' '--with-iodbc' '--with-pdo-mysql=mysqlnd' '--with-pdo-sqlite=/usr' '--with-pdo-pgsql' '--with-pspell' '--with-xsl' '--with-zip' '--with-imap' '--with-imap-ssl' '--with-kerberos' '--with-ldap' '--enable-ftp' '--enable-soap' '--with-pgsql' '--enable-sockets' '--with-tidy' '--with-xmlrpc' '--with-sodium' '--enable-sysvmsg' '--enable-sysvsem' '--enable-sysvshm' '--enable-pcntl' '--with-webp' '--with-pear' '--enable-opcache'
# Build PHP
make
# Use the latest Pair Networks PHP 7.4 php.ini
cp /usr/local/etc/php74/php.ini ~/phpini/php74/php.ini
# Note: To enabled opcache you need to add the line:
# zend_extension=opcache.so
# Alternatively, you can use the php.ini that you downloaded
# cp php.ini-production ~/phpini/php74/php.ini
# Remove debug symbols from the binary
strip sapi/cgi/php-cgi
# Copy PHP to the domain specific mapped cgi-bin directory
cp sapi/cgi/php-cgi ~/public_html/cgi-bin/php74.cgi
strip sapi/cli/php
cp sapi/cli/php ~/bin/
# Copy PHP to the domain specific mapped cgi-bin directory
cat << EOF > ~/public_html/cgi-bin/php74_wrapper.sh
#!/bin/sh
exec /usr/home/USERNAME/public_html/cgi-bin/php74.cgi
EOF
chmod 705 ~/public_html/cgi-bin/php74_wrapper.sh
# Remove built files
make clean
# Add this to your .htaccess file:
# Action application/x-httpd-php /cgi-bin/php74_wrapper.sh
@jefkin
Copy link

jefkin commented Sep 13, 2012

Of potential note, if you do run into memory limitations and you're using bash/sh (which I think is default?), instead of some csh derivative, then setenv doesn't exist for you,

so you'll want to use, for example:

CFLAGS="--param ggc-min-expand=0 --param ggc-min-heapsize=4096 -fno-inline" bash

however even then I was unable to get even the xml built correctly without reaper reaping me. I've opened a ticket to pair and ... we'll see.

@kmoser
Copy link

kmoser commented Sep 14, 2012

I had no problem with memory limits or being reaped but then I'm on one of Pair's "High Volume" (HV-1) servers.

My application requires PHP 5.2.17, and to enable MySQL support I had to change this:

'--with-mysql=mysqlnd' '--with-mysqli=mysqlnd'

to this:

'--with-mysql' '--with-mysqli'

I merged your configuration options with those that were previously enabled on the PHP build on my server, resulting in the following:

'./configure' '--with-config-file-path=/usr/home/USERNAME/phpini/php52' '--enable-debug=no' '--enable-force-cgi-redirect=yes' '--with-mysql' '--with-mysqli' '--disable-fileinfo' '--with-libxml-dir=/usr/home/USERNAME/usr/local/' '--enable-soap' '--with-openssl' '--with-curl' '--enable-mbstring' '--enable-magic-quotes' '--with-zlib' '--enable-bcmath' '--with-bz2' '--enable-calendar' '--enable-dba' '--with-gdbm' '--with-ndbm' '--with-db4' '--enable-exif' '--with-gd' '--with-jpeg-dir' '--with-freetype-dir' '--with-gettext' '--with-gmp' '--with-mcrypt' '--with-mhash' '--with-iodbc' '--with-pdo-mysql' '--with-pdo-sqlite=/usr/local' '--with-pspell' '--with-xsl' 

@jaywilliams
Copy link
Author

I just updated the script to install PHP 5.3.27 and the latest version of libxml2, as a server configuration change on Pair's side caused my previous binary to no longer work.

@jaywilliams
Copy link
Author

The script has been updated for PHP 7.4.30, on Pair's VPS service. If you want to see the old PHP 5.3 version, view the previous commit:

https://gist.github.com/jaywilliams/979039/d764b58fc842e1b0593749b1005fcef5c8ed2c1d

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