Urgent Installing WordPress on Lemp

April 18, 2018 902 views
WordPress Ubuntu CentOS Ubuntu 16.04

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

4 Answers

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

/etc/nginx/nginx.conf

user  nginx;
worker_processes  1;

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


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/vnd.ms-fontobject 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.

/etc/nginx/conf.d/yourdomain.com.conf

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

server {
    listen 80;

    server_name youdomain.com www.youdomain.com;

    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.

/etc/php/7.0/fpm/pool.d/username.conf

[username]
user = username
group = username
listen = /var/run/php/php7.0-fpm-username.sock
listen.owner = nginx
listen.group = 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 http://yourdomain.com - 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.
  • yourdomain.com with your registered domain.
  • 7.0 with the PHP version that was installed (ie. 7.1, 7.2, etc...)

Can you clarify what you're looking to accomplish? Running multiple caching layers will not necessarily improve the performance of your site and could even impact it negatively since each of these caching systems requires resources of their own.

  • Well i need to setup server for two website
    One is static and second is a store based on woo Commerce
    So most article i read show to use redis and fastcgi cache
    For static i can use fastcgi cache but for woo i need redis cache and fast cgi
    Please let me know what you think

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!

by Alex Kavon
Here are some tips on how to optimize Nginx with PHP pools on an Ubuntu 13.04 VPS.

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.

Have another answer? Share your knowledge.