While porting a PHP/Wordpress application to CloudFoundry, we are facing the issue that the application relies on the linux mail
command, which is not installed on CloudFoundry containers by default.
Is there a way of getting this installed within the container the apps runs on upon startup?
The best solution is to transition your app to talking directly to an SMTP server. There are Wordpress plugins that will let you do this. You might want to consider utilizing one of them. I don't know your situation, but using them is often straightforward.
If that's not an option, you basically need to package a mail
binary or script with your app. You can then either point Wordpress to that executable directly or you can adjust the PATH environment variable so the binary is on your path and Wordpress can find it.
A couple notes on this:
You can't install RPM or DEB packages because you can't get root access on CF. The best you can do is to bring your own binaries and scripts with the application (or write a custom build pack, but that's a lot more work).
You might be able to take the mail
binary from a Linux system and bundle it with your app. For example, install mail
in a VM (running Ubuntu Trusty or use the cloudfoundry/cflinuxfs2
docker image), copy the mail
binary and dependent shared libraries to a directory in your application. Push your app including those binaries. You can then adjust the PATH and LD_LIBRARY_PATH env variables so that Wordpress can find the command and the command can find it's associated shared libraries.
If you can't / don't want to mess with #2, you could write a script in your favorite scripting language (Python, Perl, Ruby, PHP, etc..) that implements a similar cli as the mail
command (just enough to satisfy the needs of Wordpress) and talks directly to an SMTP server. Name the script mail
and point Wordpress to it or put in on the PATH.
To adjust the PATH environment variable, you don't want to use cf set-env
. That's because you can only override variables with cf set-env
, you can't do the traditional PATH=$PATH:/my/new/path
. To make this work, you want to include a .profile
file in the root of your application. This will be picked up and sourced prior to your application starting and in it you can add PATH=$PATH:$HOME/path/to/mail/script
, where /path/to/mail/script
is the location of what you are bundling with your application and what you want available on the path. We prefix that with $HOME
so that it points to our application.
https://docs.cloudfoundry.org/devguide/deploy-apps/deploy-app.html#profile