Urgent Installing WordPress on Lemp

Hi I want to install WordPress on lemp with FastCgi cache and redis cache and Opcache , can Anybody Link me to A good article Which is updated recently

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Below is the general setup and configs I use with NGINX + PHP7 + WordPress. The first file is my main NGINX config file.


user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/;

events {
    worker_connections  1024;

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;
    client_max_body_size 8M;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    gzip  on;
    gzip_disable "msie6";
    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_buffers 16 8k;
    gzip_http_version 1.1;
    gzip_min_length 256;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/ application/x-font-ttf font/opentype image/svg+xml image/x-icon;    

    include /etc/nginx/conf.d/*.conf;

    server {
        listen 80 default_server;

        server_name _;
        return 444;

I create a new user adduser username with a home directory. I include a /home/username/public_html directory where WordPress will be installed.

Below are my NGINX configuration file(s) for WordPress.


upstream php7 {
    server unix:/var/run/php/php7.0-fpm-username.sock;

server {
    listen 80;
    root /home/username/public_html;
    index index.php index.html;
    location / {
        try_files $uri $uri/ /index.html /index.php$args;
    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
        fastcgi_read_timeout 300;
        fastcgi_pass php7;
    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires max;
        log_not_found off;
    location = /favicon.ico {
        log_not_found off;
        access_log off;
    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    location ~ /\. {
        deny all;
    location ~* /(?:uploads|files)/.*\.php$ {
        deny all;

For PHP I create a pool that will run the PHP process under the previously created user.


user = username
group = username
listen = /var/run/php/php7.0-fpm-username.sock
listen.owner = nginx = nginx
request_terminate_timeout = 300
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
chdir = /

You will need to restart NGINX…

service nginx restart

If the restart fails you can use nginx -t to help debug the issue.

… and then PHP service php7.0-fpm restart

Create an index.php file in /home/username/public_html/ with the following contents

<?php phpinfo(); ?>

Then navigate to - if all is well you should see a PHP information page. From here you can then continue installing WordPress.

Please note in the above configs you will need to replace

  • username with a username of your choice.
  • with your registered domain.
  • 7.0 with the PHP version that was installed (ie. 7.1, 7.2, etc…)

502 means that you have received an invalid response from your backend server. In this case it is most likely PHP. You will need to go through your configs and ensure they are correct.

This is a great walk through to get you started.

The following guides are not so much a one off walk through but each have a great deal to offer. I suggest reading through them and take what you need/like and adjust your setup/configuration as needed.

Installing the LEMP Stack on Ubuntu:16.04

Securing NGINX with LetsEncrypt

This is my preferred method for NGINX and LetsEncrypt.

Optimizing NGINX with PHP pools - This guide is for Ubuntu:13.04 and PHP5 however it is still relevant. You will need to adjust for your PHP version.

Installing WordPress on Ubuntu:16.04 with NGINX

Understanding Caching with NGINX/NGINX Plus

Enable PHP7 Opcache + a discussion on configuring.

Installing Redis on Ubuntu:16.04

Using Redis with WordPress (I use Method 2 Personally)

Hope that helps!