How to fine-tune PHP-FPM, Nginx, and Apache
NOTE: We’re working on a configuration panel so that you can edit your configs right from Moss. In the meantime, you must follow the guidelines in this article.
One of the main benefits of using Moss is that you rarely have to deal with the low-level details of server and site configuration. However, sometimes you need to get your hands dirty and provide extra configuration for your applications.
Moss will honor your own config and won’t overwrite it. In this article we tell you how you can set it up.
PHP-FPM extra config
Moss serves your PHP applications using PHP-FPM, an implementation of the FastCGI protocol for PHP.
The configuration for PHP-FPM can be found on your servers within directories /etc/php/<version>/fpm/
, where <version>
are each of the PHP versions installed on your server. For the sake of simplicity, in the remainder of this article we provide examples for PHP 7.0. However everything stated here applies to all supported PHP versions. Just substitute 7.0
for the PHP version you’re actually tweaking.
moss@<server>:~$ ls -F /etc/php/7.0/fpm/conf.d/ php-fpm.conf php.ini pool.d/
Moss sets up some of these configuration files on your behalf. But luckily, you may overwrite the values of the directives you want by including additional .ini
files within /etc/php/7.0/fpm/conf.d/
: e.g. /etc/php/7.0/fpm/conf.d/99-extra.ini
Moss won’t overwrite the configuration that you put into those files. In order to create them, you must log into your server as user moss
and become root
via sudo
. Once you’re done with the config, log into Moss and restart PHP-FPM from the Software tab.
Nginx extra config
Moss installs and sets up the OpenResty (Nginx) web server on your behalf. You can find the Nginx configuration files within the /usr/local/openresty/nginx/conf/
and /usr/local/openresty/nginx/sites/
directories of your server.
You can tweak the configuration of each site by editing the following files:
/usr/local/openresty/nginx/conf/server_params.your_site
: Nginx directives within blockserver
of your site./usr/local/openresty/nginx/conf/root_params.your_site
: Nginx directives within blocklocation /
of your site./usr/local/openresty/nginx/conf/fastcgi_params.your_site
: Nginx directives within blocks with FastCGI configs (blocklocation ~ .php$
at the moment) of your site.
Moss won’t overwrite the configuration that you put into those files. In order to create them, you must log into your server as user moss
and become root
via sudo
. Once you’re done with the config, log into Moss and restart Nginx from the Software tab.
Apache extra config
Your site may use Nginx in standalone mode or as a reverse proxy in front of Apache. In the latter case, you may fine-tune Apache configs in different ways:
- Create config files within
/etc/apache2/conf-available/
and runa2enconf
afterwards (e.g. create filemyconfig.conf
and runa2enconf myconfig
). Since you’re changing the global configuration, you must SSH into your server as usermoss
and becomeroot
usingsudo
. Once you’re done, you must log into Moss and restart Apache from the Software tab. - Create
.htaccess
files within your sites’ directory. Since you’re dealing with a given site, you must create these files as the server user that runs said site. - WordPress users will likely employ a plugin to make some configs like setting up the browser cache, among others. Such plugins could add the required configs to a
.htaccess
file, so you don’t need to do it by hand.
What’s next?
Need some examples? Below you can find articles that describe some common use cases:
- How to increase the maximum upload size
- How to set up basic auth for a website
- How to tweak fastcgi params for a website
- How to add rewrite rules in Nginx for a website
- How to set up the cache policy for the resources of a website
Don’t hesitate to contact us if you have any other use case in mind 😉