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: 80
Document 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 Php Nginx Mysql Ubuntu 18.04 Install Php Nginx Mysql Ubuntu 18.04 What is PHP, Nginx, and MySQL PHP is a popular and powerful scripting language that can be used to create dynamic web pages, web…
- Nginx And Apache Together Centos Nginx and Apache Together in Centos Overview A popular choice for websites is using the powerful combination of Nginx and Apache together. The two web servers are both reliable and…
- Install Pdo_Mysql Ubuntu Nginx Install Pdo_Mysql Ubuntu Nginx What is Pdo_Mysql? PDO_Mysql is a driver for the PHP Data Objects (PDO) extension that provides a database abstraction layer for working with MySQL databases.PDO_Mysql provides…
- Wordpress Nginx Ubuntu 18.04 Wordpress Nginx Ubuntu 18.04 Overview WordPress is a popular web software used by millions of people around the world. It allows users to easily create and manage websites without the…
- Debian Install Nginx Php Mysql Phpmyadmin On Debian 9 Debian Install Nginx Php Mysql PhpMyAdmin On Debian 9 What Is Debian 9? Debian 9 (codenamed “stretch”) is the most recent stable version released by the Debian project, the developers…
- Nginx On Ubuntu 18.04 Nginx On Ubuntu 18.04 What is Nginx? Nginx is a free, open-source, high-performance web server software. It is known for its stability, rich feature set, simple configuration, and low resource…
- Install Wordpress On Different Location Nginx Install Wordpress On Different Location Nginx What Is Wordpress? WordPress is an open-source content management system (CMS) used to create websites. The software is built on PHP and MySQL, and…
- Nginx Handle Large Upload Data Post Wordpress Nginx Handle Large Upload Data Post Wordpress Why Do We Need to Handle Large Upload Data in Wordpress? WordPress is used on a wide variety of platforms and web servers.…
- 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…
- Enable Memcached Nginx Debian 9 Enable Memcached Nginx Debian 9 Memcached Basics Memcached is a distributed memory caching system that greatly enhances the performance of network-based applications. It is a great tool that allows data…
- How To Install Nginx Debian 9.7 How To Install Nginx Debian 9.7 Step 1: Setting Up the Server The first step in the installation of Nginx on Debian 9.7 is to set up the server. This…
- How To Install Phpmyadmin On Nginx How To Install Phpmyadmin On Nginx Introduction PhpMyAdmin is an open source software program which is used to manage MySQL and MariaDB databases. It provides a graphical interface to execute…
- Ubuntu 18.04 Nginx Php Mariadb Ubuntu 18.04 Nginx, Php, and Mariadb Understanding Ubuntu 18.04 Ubuntu 18.04 is the latest version of the popular open-source Linux distribution. It is based on Debian and is known for…
- How To Setup Nginx On Ubuntu How To Setup Nginx On Ubuntu Introduction Nginx is a powerful web server that is very popular among Linux users. It is open-source and comes with great features such as…
- 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…
- Ubuntu 16.04 Nginx Ipv6 Ubuntu 16.04 Nginx Ipv6 What is Ubuntu 16.04? Ubuntu 16.04 is a version of the Ubuntu Linux operating system for computers and servers. Ubuntu has been around since 2004, and…
- Sudo Systemctl Status Nginx.Service Sudo Systemctl Status Nginx.Service What is Nginx? Nginx is a free, open-source, high-performance web server that claims to offer better performance and scalability than Apache. Nginx also provides a reverse…
- 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 Php Mysql Ssl & Wordpress On Ubuntu 18.04 Install Nginx Php Mysql Ssl & Wordpress On Ubuntu 18.04 What is Nginx, Php, Mysql, SSL and Wordpress? Nginx is a high-performance web server that is widely used to serve…
- Install Rapidssl Nginx Ubuntu 18.04 Install RapidSSL with Nginx on Ubuntu 18.04 Step 1: Installing Nginx The first step in setting up RapidSSL with Nginx on Ubuntu 18.04 is to install Nginx itself. This can…
- How Instal Nginx Debian 9 How to Install Nginx Debian 9 What is Nginx? Nginx (pronounced "engine-x") is an open source web server and reverse proxy software. It is known for its light weight and…
- 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…
- Stop Nginx Ubuntu 16.04 Stop Nginx Ubuntu 16.04 What is Nginx? Nginx is a web server and reverse proxy software. It is open source and widely used on the web. It is used to…
- Install Nginx Ubuntu Server 16.04 Install Nginx Ubuntu Server 16.04 Introduction to Nginx Nginx is a high performance web server and reverse proxy. It is normally used for serving static content such as images, static…
- Install Wordpress On Ubuntu 18.04 Nginx Install WordPress On Ubuntu 18.04 Nginx Introduction To Ubuntu And Nginx Ubuntu is a popular open-source operating system which has gained immense popularity over the years. It is easy to…
- 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…
- 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 Proxy Cache Redis Wordpress Centos Nginx Proxy Cache Redis Wordpress Centos Understanding Nginx Proxy Cache Nginx Proxy Cache is a web-acceleration software from Nginx, Inc. It is designed to speed up dynamic web content delivery.…
- Centos 7 Install Nginx Php Mariadb Centos 7 Install Nginx Php Mariadb Installing Centos 7 for Nginx CentOS 7 is one of the most widely used linux distributions for web servers, and it is an ideal…
- 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…