Opalstack's PHP setup is configured to meet the requirements for most PHP applications, but sometimes you might be working with a bleeding-edge application (or maybe a really old one) that needs a PHP version or configuration that's different than what Opalstack provides.
In those cases, you can build your own version of PHP from source and use that to serve your application.
As an example, there are some applications that need to use a newer version of the popular curl
libarary. These are the steps to install a private PHP-FPM stack with a custom-built version of PHP with an up-to-date version of curl.
Create a "Nginx Proxy Port" app in your Opalstack dashboard and make a note of the app's name and port assignment.
SSH to your Opalstack server as the new app's shell user.
Run the following commands to install curl and PHP:
source scl_source enable devtoolset-11
mkdir -p ~/src ~/tmp ~/opt
export TMPDIR=$HOME/tmp
export LD_LIBRARY_PATH=$HOME/opt/lib
# curl
cd ~/src
wget https://curl.se/download/curl-7.81.0.tar.xz
tar xf curl-7.81.0.tar.xz
cd curl-7.81.0
./configure --prefix=$HOME/opt --with-openssl
make && make install
# php
cd ~/src
wget https://www.php.net/distributions/php-8.1.2.tar.xz
tar xf php-8.1.2.tar.xz
cd php-8.1.2
./configure --prefix=$HOME/opt --with-pdo-mysql -with-pdo-pgsql=/usr/pgsql-11 --enable-bcmath --enable-calendar --enable-exif --enable-ftp --enable-mbstring --enable-soap --with-curl=$HOME/opt --with-gettext --with-gmp --with-iconv --with-kerberos --with-mhash --with-mysqli --with-openssl --with-pgsql=/usr/pgsql-11 --with-xsl --with-zlib-dir --without-pear --enable-sockets --enable-intl --with-mysql-sock=/var/lib/mysql/mysql.sock --enable-fpm --with-zlib
make && make install
Install a PHP-FPM stack into the app you created in step 1. Instructions for installing the PHP-FPM stack are available at: HOWTO run a private PHP-FPM stack on Nginx or Apache on Opalstack - Opalstack Community Forum
Configure the PHP-FPM stack to use your custom PHP by running the following commands as your stack's shell user:
cd ~/apps/name_of_app/bin
ln -f -s $HOME/opt/sbin/php-fpm ./
- Edit the stack's
bin/start
script to insert the following line near the top, just below #!/bin/bash
:
export LD_LIBRARY_PATH=$HOME/opt/lib
- Restart the stack to pick up the changes by running the following command:
~/apps/name_of_app/bin/restart
- Route the stack app to whatever site at https://my.opalstack.com/domains/.
You're done!