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. ✨
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:
git clone -b opalstack https://github.com/rsanden/userspace-fpm-installer.git
When that's done you will have (among other things) a file named
config. Edit that file as directed in this example:
STACKNAME="phpfpm" # replace `phpfpm` with your proxy port app name
PORT="77777" # your proxy port assignment
DOMAIN1="mydomain.com" # domain that the site will run on
APPDIR1="$HOME/apps/app1" # the PHP app that you want to serve
SERVER_TYPE="nginx" # nginx or apache
PHP_VERSION="8.0" # PHP version: 5.6, 7.4, 7.4, or 8.0
Next, run the install script:
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:
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 🙂