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:
- 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…
- How To Install Nginx On Centos 7 Rhel 7 How To Install Nginx On Centos 7 Rhel 7 Nginx is one of the most popular web servers around the globe – being an open-source application, it drives a large…
- 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…
- 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.…
- 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…
- Install Nginx Ubuntu 18.08 Local Install Nginx on Ubuntu 18.04 Local Installing Nginx on Ubuntu 18.04 can be accomplished quickly and in several different ways. Depending on your needs, some methods may be better suited…
- Kubectl Install Nginx Wordpress Bare Metal Kubectl Install Nginx Wordpress On Bare Metal Introduction To The Process Of Installing Nginx On Bare Metal With the new trend of cloud and automated solutions, it has become easier…
- 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…
- 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…
- 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…
- Reverse Proxy Nginx Centos 7 Reverse Proxy Nginx Centos 7 What is a Reverse Proxy? A reverse proxy is a type of proxy server that retrieves resources on behalf of a client from one or…
- Step By Step Install Nginx And Phpmyadmin On Ubuntu Step By Step Install Nginx And Phpmyadmin On Ubuntu Introduction Setting up a web server on Ubuntu is easy and straightforward. Nginx is a popular web server for Ubuntu, and…
- 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 Nginx Php Fpm Centos 7 Install Nginx Php Fpm Centos 7 Prerequisites Before you start installing Nginx and Php-Fpm on CentOS 7, make sure the following prerequisites are in place. CentOS 7 must be installed…
- Nginx Wordpress Ubuntu 18.04 Nginx Wordpress Ubuntu 18.04 Introduction to Nginx Nginx is a web server software for hosting websites and applications. It is open-source and highly configurable, making it a popular choice for…
- How Use Nginx Mysql Ubuntu How to Use Nginx, MySQL and Ubuntu What is Nginx? Nginx is an open source web server and reverse proxy software written by Igor Sysoev. It is a popular choice…
- 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 Nginx Di Kali Linux Install Nginx Di Kali Linux Introduction Kali Linux is a well-known operating system specially designed for Penetration Testing and Security Auditing tasks. The operating system is loaded with all the…
- Install Nginx 1.17 Centos 8 Install Nginx 1.17 Centos 8 Introduction to Nginx Nginx is one of the most popular web servers in the world. It is reliable, free, and open source software. It is…
- Wordpress Permalink Http 404 On Nginx Here We Go. WordPress Permalink Http 404 On Nginx What is WordPress Permalink? WordPress Permalinks, also known as permanent links, are URLs (Uniform Resource Locators) that are used to access…
- 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…
- 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…
- 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…
- 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 Nginx And Php On Ubuntu 18.04 Install Nginx And Php On Ubuntu 18.04 Introduction In this article, we will guide you on how to install Nginx and php on Ubuntu 18.04. Nginx is a popular web…
- Nginx Php Fpm 7.2 Nginx Php Fpm 7.2 Introduction to Nginx and PHP-FPM Nginx is an open-source web server, reverse proxy server, and load balancer. It is known for being lightweight and fast, and…
- 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…
- 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…
- Add Root Password Mysql Nginx Ubuntu 16.04 Add Root Password Mysql Nginx Ubuntu 16.04 What is a root password? In the context of computer security, a root password is a user account that is given access to…
- Nginx Ssl Ubuntu 16.04 Nginx SSL Ubuntu 16.04 What is SSL and Nginx? SSL stands for Secure Sockets Layer. It is a protocol used to encrypt communications over the internet. It is a secure…