← ServerPilot Docs

How to Create a LEMP Stack (Only Nginx, No Apache)

Careful, don't break your server! This customization is not supported by ServerPilot.

You should first read the article on customizing Nginx.
Any app such as WordPress and WordPress plugins using .htaccess files will break if you perform the customizations in this article.

If your app doesn't utilize .htaccess files, it is possible to have Nginx interact directly with PHP-FPM and bypass Apache entirely. For more information on how Nginx and Apache work together, see How ServerPilot Configures Your LAMP/LEMP Stack.

First, rename main.conf so you have a backup, where APPNAME is the name of your app.

cd /etc/nginx-sp/vhosts.d/APPNAME.d
mv main.conf main.conf.bak

Next, create a new file, /etc/nginx-sp/vhosts.d/APPNAME.d/main.custom.conf, with the following contents:

index index.php index.html index.htm;

# Don't serve hidden files.
location ~ /\. {
    deny all;
}

location = /favicon.ico {
    log_not_found off;
}

location / {
    try_files     $uri $uri/ /index.php?$args;
}

location ~ \.php$ {
  include       fastcgi_params;
  fastcgi_index index.php;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  # You must replace "SYSUSER" with the app's system user's name
  # and "APPNAME" with your app's name.
  ############################################################
  fastcgi_pass  unix:/srv/users/SYSUSER/run/APPNAME.php-fpm.sock;

  # Prevent arbitrary code execution by third parties with
  # try_files directive.
  # http://wiki.nginx.org/Pitfalls#Passing_Uncontrolled_Requests_to_PHP
  try_files     $uri =404;
} 

Then, restart Nginx by running this command as root:

sudo service nginx-sp restart

Launch your first site in 5 minutes