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:
- How To Set Up Nginx Loadbalancer Ubuntu How To Set Up Nginx Loadbalancer Ubuntu Introduction to Nginx Loadbalancer Nginx Loadbalancer is a web application that lets you easily set up load balancing for your website. It is…
- Nginx 502 Bad Gateway Php Wordpress Digitalocean Nginx 502 Bad Gateway Php Wordpress Digitalocean Introduction to 502 Bad Gateway A 502 Bad Gateway is an HTTP status code that is displayed when the server acting as a…
- Nginx Install Custom Directory Phpmyadmin Nginx Install Custom Directory PhpMyAdmin Introduction to Nginx and PhpMyAdmin Nginx is a web server and content caching solution used to host a variety of web applications. It is highly…
- Nginx Multi Domain Centos 7 Nginx Multi Domain Centos 7 Introduction to Nginx Nginx is an open source, high performance web server software written in C language, designed to be deployed on Linux and Unix-like…
- Ubuntu Server18 How To Enable Nginx Pdo Mysql Ubuntu Server18: How to Enable Nginx Pdo Mysql As a developer, you may have heard of Nginx, PDO, and MySQL – all are essential components of web applications. Nginx is…
- Node Express Mongodb Nginx Digitalocean Node Express Mongodb Nginx Digitalocean Creating a Machine Through DigitalOcean Droplet Creating a DigitalOcean Droplet is the simplest and most fool-proof way of setting up a more secure and private…
- Ubuntu Server Postgresql Nginx Php Ubuntu Server Postgresql Nginx Php Introduction Optimizing your server is one of the most important steps you can take when it comes to running a successful website or application. It…
- Tutorial Install Nginx Di Ubuntu Vps Tutorial Install Nginx Di Ubuntu Vps Step 1: Install Nginx The first step to install nginx in your Ubuntu VPS is to install the nginx package. To do this, use…
- How To Ubuntu 16.04 Multiple Php Nginx How to Ubuntu 16.04 Multiple PHP Nginx Ubuntu 16.04 is a robust operating system that is commonly used for web application development. This operating system uses Nginx as the web…
- 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…
- Error Install Nginx On Ubuntu Error Install Nginx On Ubuntu What is Nginx? Nginx is a web server software used to host web applications. It is open source software developed by the open source community.…
- Check Nginx Version Centos 7 Check Nginx Version Centos 7 1. What is Nginx? Nginx is an open source web server software created by Igor Sysoev in 2002 and is widely used for powering the…
- Failed To Restart Nginx.Service: Unit Nginx.Service Not… Failed To Restart Nginx.Service: Unit Nginx.Service Not Found What is Nginx? Nginx (Engine X) is a web server originally created by Igor Sysoev in 1996. It is now one of…
- 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…
- Error Nginx When Installing Certbot Ubuntu Error Nginx When Installing Certbot Ubuntu What is Nginx? Nginx is a web server software often used to serve web pages. It is known as a high-performance web server and…
- How To Install Flask Nginx On Ubuntu 1604 How To Install Flask Nginx On Ubuntu 1604 Introduction Flask is a web application framework based on Python. It is highly useful for web developers due to its flexibility and…
- Virtualhost Nginx Ubuntu 16.04 Virtualhost Nginx Ubuntu 16.04 Introduction to Virtualhost Virtualhost is a software configuration option in web servers including Apache, Nginx, and more that allows a web server to host multiple web…
- 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 Phpmyadmin On Nginx Ubuntu 18.04 Install Phpmyadmin On Nginx Ubuntu 18.04 Introduction PhpMyAdmin is one of the most popular and widely used web-based database management tools available. It is used for administering, managing and maintaining…
- 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…
- Selinux Enable Php Fpm Nginx Centos 7 Selinux Enable Php Fpm Nginx Centos 7 What is Selinux Enable Php Fpm Nginx Centos 7? Selinux Enable Php Fpm Nginx CENTOS 7 is an easy-to-use web server and operating…
- 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 Config Nginx Di Ubuntu How to Config Nginx di Ubuntu Nginx atau Pronounced “Engine X” adalah salah satu server web, proxy dan cache yang paling populer di dunia. Ini digunakan oleh banyak perusahaan sukses…
- Config Mysql Nginx In Centos Config Mysql Nginx In Centos Introduction: CentOS is a versatile Linux server operating system. It is the most widely used operating system for web servers, providing enterprises and small business…
- Configure Nginx Add Module Mac Configure Nginx Add Module Mac What is Nginx? Nginx is an open source web server software that helps websites become more efficient. In particular, it helps websites by providing a…
- Wordpress Behind Load Balancer Nginx WordPress Behind Load Balancer Nginx Understanding Load Balancing and Nginx Load balancing is an essential component of running websites and services successfully. Load balancing technology enables servers, applications, and networks…
- Install Paid Ssl Nginx Ubuntu 18.04 Install Paid SSL Nginx Ubuntu 18.04 What Is Nginx? Nginx is an open-source web server and reverse proxy used in many applications worldwide. It is a lightweight, high-performance server that…
- 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…
- Setting Https Wordpress On Nginx Setting Https Wordpress On Nginx Setting Up An SSL Certificate In order to enable HTTPS on your WordPress site, you first need to add an SSL certificate. An SSL certificate…
- 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…