Setup WordPress With Memcached and Nginx
Installing Memcached
Memcached is a distributed in-memory caching system used to speed up web applications such as WordPress. It stores data in memory and improves the performance of web applications by reducing the amount of data that needs to be read from the database.
To install Memcached on Ubuntu and Debian, you need to use the apt-get command. Open up a terminal window and enter the following command:
$ sudo apt-get install memcached
Once the installation is finished, start the memcached service with the following command:
$ sudo systemctl start memcached
You can check if the Memcached service is running with the following command:
$ sudo systemctl status memcached
The output should look something like this:
Active: active (running) since Mon 2018-08-20 20:14:20 UTC
Main PID: 24461 (memcached)
CGroup: /system.slice/memcached.service
Aug 20 20:14:20 ubuntu-18 memcached[24461]: memcached.service: Succeeded.
Now that Memcached is installed and running, you can move on to the next step which is to install Nginx.
Installing Nginx
Nginx is a web server that can be used to serve static files and reverse proxy requests from applications such as WordPress. To install Nginx on Ubuntu and Debian, you will need to use the apt-get command. Open up a terminal window and enter the following command:
$ sudo apt-get install nginx
Once the installation is finished, you can start the Nginx service with the following command:
$ sudo systemctl start nginx
You can check if Nginx is running with the following command:
$ sudo systemctl status nginx
The output should look something like this:
Active: active (running) since Mon 2018-08-20 18:48:56 UTC
Main PID: 9151 (nginx)
CGroup: /system.slice/nginx.service
└─9151 nginx: master process /usr/sbin/nginx
Now that Nginx is installed and running, you can move on to the final step which is to install WordPress.
Installing WordPress
WordPress is a content management system that can be used to create and manage websites. To install WordPress on Ubuntu and Debian, you will need to use the apt-get command. Open up a terminal window and enter the following command:
$ sudo apt-get install wordpress
Once the installation is finished, you can start the WordPress service with the following command:
$ sudo systemctl start wordpress
You can check if WordPress is running with the following command:
$ sudo systemctl status wordpress
The output should look something like this:
Active: active (running) since Sun 2018-08-19 20:27:44 UTC
Main PID: 24461 (wordpress)
CGroup: /system.slice/wordpress.service
└─24461 /usr/sbin/wordpress --daemon
Configuring Nginx and Memcached for WordPress
Once the applications have been installed, it’s time to configure Nginx and Memcached for WordPress. To do this, you will need to edit the Nginx configuration file. The configuration file is located at /etc/nginx/nginx.conf. Open up the file in your text editor and add the following lines at the end of the file:
proxy_cache_path /tmp/nginx levels=1:2 keys_zone=my_cache:10m inactive=60m;
proxy_cache_key "$scheme$request_method$host$request_uri";
server {
listen 80;
server_name yourdomain.com;
root /var/www/wordpress;
location / {
proxy_pass http://127.0.0.1:80;
proxy_cache my_cache;
proxy_cache_valid 1m;
proxy_cache_methods GET;
proxy_cache_valid any 10m;
proxy_cache_use_stale error timeout invalid_header updating;
}
}
The above configuration will enable Nginx to cache static files such as images and CSS files. You can also enable Memcached for WordPress by adding the following lines to the Nginx config file:
upstream memcached {
server 127.0.0.1:11211;
}
server {
listen 80;
server_name yourdomain.com;
root /var/www/wordpress;
# enable memcached
location ~ .php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
fastcgi_cache WORDPRESS;
fastcgi_cache_valid 10m;
fastcgi_cache_methods GET POST;
fastcgi_cache_lock on;
fastcgi_cache_min_uses 3;
fastcgi_cache_use_stale updating error timeout invalid_header http_500;
fastcgi_cache_background_update on;
fastcgi_pass_header Set-Cookie;
fastcgi_pass_header Cookie;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
fastcgi_param WORDPRESS_EARLY_LOAD true;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
}
}
The above configuration will enable Memcached to store WordPress data in memory. Finally, you will need to restart Nginx and Memcached for the changes to take effect. You can do this with the following commands:
$ sudo systemctl restart nginx
$ sudo systemctl restart memcached
Testing WordPress Performance
To test WordPress performance, you can use a tool such as Apache Bench (ab) or WPsite Speed. Apache Bench will test the load speed of web pages and can be used to get an idea of how well WordPress is performing. To use Apache Bench, open up a terminal window and enter the following command:
$ ab -n 1000 -c 10 http://yourdomain.com/
The output should look something like this:
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
....
....
....
Server Software: nginx/1.14.0
Server Hostname: test-domain.com
Server Port: 80Document Path: /
Document Length: 233 bytes
Concurrency Level: 10
Time taken for tests: 0.322 seconds
Complete requests: 1000
Failed requests: 0
Total transferred: 191000 bytes
HTML transferred: 233000 bytes
Requests per second: 3117.76 [#/sec] (mean)
Time
Related Posts:
- Install Nginx And Php On Ubuntu Install Nginx And Php On Ubuntu A Comprehensive Tutorial to Install Nginx And Php On Ubuntu Nginx and PHP are two of the most popular web server and scripting language…
- Php-Fpm Conf Nginx Debian Php-Fpm Conf Nginx Debian Overview of PHP-FPM PHP-FPM (FastCGI Process Manager) is an extension designed to increase the speed and performance of websites that are frequently visited by users. It…
- Nginx Digitalocean To Docker Node Nginx Digitalocean To Docker Node What is Nginx? Nginx is a high performance web server used to serve static content. Developed by Igor Sysoev in 2004, Nginx is now widely…
- Install Nginx Latest Ubuntu 16.04 Install Nginx Latest Ubuntu 16.04 What is Nginx? Nginx is a web server. It is also an open source and free software. It was first developed by Igor Sysoev in…
- Default Webserver Nginx Ubuntu 18.04 Default Webserver Nginx Ubuntu 18.04 What is Nginx? Nginx is an open source web server that is used to host websites or act as a reverse proxy for other web…
- Install Nginx Ubuntu 16.04 For Odoo Install Nginx Ubuntu 16.04 For Odoo Install Ubuntu Server 16.04 Before we can install Nginx for Odoo we need to install Ubuntu 16.04 on our server. Ubunutu 16.04 is still…
- Nginx Php Fpm 7.2 Laravel Nginx Php Fpm 7.2 Laravel Introduction to Nginx Nginx (pronounced “engine-x”) is a free, open-source web server software. It’s quickly becoming one of the most popular web servers, used by…
- Centos 7 Install Nginx Php 7 Centos 7 Install Nginx Php 7 Nginx Server Overview and Prerequisites Nginx is a highly popular open source web server and reverse proxy software, known for its scalability and performance…
- Start Nginx Service Centos 7 Start Nginx Service Centos 7 Before You Start: Server and Requirements If you are running a website or a web application on Centos 7, chances are you will be using…
- Install Nginx Phpmyadmin Ubuntu 18.04 Install Nginx Phpmyadmin Ubuntu 18.04 Introduction to Nginx, PHP, and Ubuntu Nginx is an open-source, high-performance web server written in C and used to serve static and dynamic webpages. It…
- Ubuntu Install Nginx Php7.2 Mysql Ubuntu Install Nginx Php7.2 Mysql What is Nginx? Nginx is an open source web server that is very popular for powering web applications such as WordPress and Drupal. It is…
- Install Nginx Server On Centos 7 Install Nginx Server On Centos 7 What Is Nginx? Nginx is an open source web server and reverse proxy developed by Igor Sysoev in 2004. It is an efficient web…
- How To Install Nginx On Ubuntu 18.04 How To Install Nginx on Ubuntu 18.04 Introduction Nginx is a popular open-source web server and reverse proxy software that’s used by millions of websites. It’s the most widely used…
- Nginx 1.10 3 Ubuntu Nginx 1.10 3 Ubuntu Overview of Nginx Nginx (“engine x”) is an open source web server created by Russian software engineer Igor Sysoev and launched in 2004. It is used…
- Install Phpmyadmin On Nginx Centos 7 Install Phpmyadmin On Nginx Centos 7 Introduction PhpMyAdmin is one of the most popular tools used to manage and administer a MySQL database. It is a web-based application and can…
- Install Phpmyadmin Nginx Ubuntu 16.04 Install Phpmyadmin Nginx Ubuntu 16.04 What is PhpMyAdmin? PhpMyAdmin is an open-source software for managing MySQL databases. It can be used to add, modify, and delete databases, tables, and columns.…
- Install Postgis Ubuntu 18.04 Nginx Install Postgis Ubuntu 18.04 Nginx What is Postgis? Postgis is a Postgres-based open source geographic information system (GIS) that enables users to store, query, and analyze spatial data stored in…
- Google Cloud Ubuntu 16 Install Nginx Php Google Cloud Ubuntu 16 Install Nginx Php 1. What is Nginx? Nginx is a powerful open source web server. It is used to serve web pages to the internet and…
- Install Mariadb Nginx Debian 9.7 Install Mariadb and Nginx on Debian 9.7 Overview of Installing MariaDB and Nginx on Debian 9.7 Installing MariaDB and Nginx on Debian 9.7 can be an essential step when setting…
- How To Deactive Nginx Ubuntu How To Deactivate Nginx Ubuntu Introduction Nginx is a web server that’s popular in the Linux world because of its simple configuration, scalability, and performance. The Apache httpd web server…
- Remove Apache2 Ubuntu And Change To Nginx Remove Apache2 Ubuntu And Change To Nginx What Is Apache2? Apache2 is an open-source web server software created and maintained by the Apache Software Foundation. It is one of the…
- Install Mysql Pada Nginx Pada Ubuntu Install Mysql Pada Nginx Pada Ubuntu Overview of Nginx and Its Benefits Nginx is a web server, reverse proxy server, and mail proxy server application that is open-source and available…
- Upgrade Nginx Ubuntu 18.04 Upgrade Nginx Ubuntu 18.04 Getting Started with Nginx Ubuntu 18.04 Installation Nginx is a high performance web server and reverse proxy. It is written in C and has ways to…
- Replace Apache To Nginx Ubuntu 18 Replace Apache To Nginx Ubuntu 18 Installing Nginx Ubuntu 18 uses Nginx as its default web server, and it is pre-installed. However, if you want to use a fresh version…
- Setup Centos 7 Nginx With Php Setup Centos 7 Nginx With Php Overview of Centos7 Nginx and PHP Centos 7 is one of the most popular operating systems for web servers. Many businesses use Centos 7…
- Failed To Restart Nginx.Service Unit Nginx.Service Is Masked Failed To Restart Nginx.Service Unit Nginx.Service Is Masked What is Nginx? Nginx (pronounced "engine x") is an open source, high-performance web server and reverse proxy. It is used in production…
- Install Php Nginx Ubuntu 12.04 Install Php Nginx Ubuntu 12.04 Introduction Welcome to our guide on How to install PHP, Nginx & MySQL on Ubuntu 12.04 LTS. This guide should work on other Linux VPS…
- How To Install Cachet Nginx How To Install Cachet Nginx Overview Cachet is an open-source monitoring platform that is widely used by web developers, DevOps engineers, and system administrators for monitoring the performance of a…
- How To Install Nginx And Mariadb 10 How To Install Nginx And Mariadb 10 What is Nginx and MariaDB 10 Nginx is a free, open-source web server that is known for its scalability and performance. It is…
- How To Configure Nginx With Varnish How To Configure Nginx With Varnish Introduction Nginx and Varnish are powerful web server tools used to configure and optimize the delivery of web content. Nginx serves requests while Varnish…