A private PHP-FPM stack running on Nginx or Apache gives you total control over your web server configuration.
A colleague of mine at WebFaction was kind enough to create a script that will install a private backend PHP stack using either Nginx or Apache with the version of PHP of your choice. We've adapted that script to work with Opalstack's services.
To use it, first create the following items in your Opalstack dashboard:
Once that's done, SSH to the shell user and run the following commands:
cd ~
git clone https://github.com/opalstack/private-phpfpm-installer
cd private-phpfpm-installer
When that's done you will have (among other things) a file named config
. Edit that file as directed in this example:
#!bash
# change these to your stack app's name and port
STACKNAME="phpfpm"
PORT="77777"
# change these to the domain and directory you want the stack to serve
DOMAIN1="mydomain.com"
APPDIR1="$HOME/apps/app1"
# change these as needed, nginx or apache, php versions 5.6, 7.3, 7.4, 8.0, 8.1, 8.2, 8.3
SERVER_TYPE="nginx"
PHP_VERSION="8.3"
# no need to change these
PREFIX="$HOME/apps/$STACKNAME"
LOGDIR="$HOME/logs/apps/$STACKNAME"
Next, run the install script:
./install.bash
The script will generate the necessary configuration and scripts needed to run your application.
The generated Nginx & Apache config will be in the conf
subdirectory of the app directory. You can edit that config post-install to set up additional sites on the stack, or to modify the existing site (changing domains etc).
The generated FPM config will be in the etc
subdirectory of the app dir. You can edit that post-install to adjust performance parameters, etc.
start/stop/restart scripts are in the bin
subdir. start and stop are symlinked to nginx or apache depending on your config. You can change the app to either web server by changing the symlinks, for example to switch from Nginx to Apache:
cd ~/apps/appname/bin
ln -f -s start-httpd start
ln -f -s stop-httpd stop
The script also creates a cron job to restart the app if it goes down:
*/10 * * * * /home/shelluser/apps/phpfpm/bin/start &>/dev/null
That's pretty much it! If you've been wanting (or needing) to try out this sort of setup, please give it a try and let me know what you think 🙂