The
For example, some people seriously doubt that nginx+php-fpm is actually slightly slower than apache+mod\u PHP (because nginx does not need to connect to the php-fpm backend, but directly provides it). If the memory is sufficient, the solution using varnish+apache+mod_php may surpass the nginx+php-fpm solution. Nginx+php-fpm is WordPress. Just because the setting type that may be most suitable for com does not mean that it is most suitable for you. The
However, if your environment is very compact and has few resources, or you prefer to spread the load over multiple smaller cloud instances rather than large servers with more memory and CPU, this tutorial will provide the best performance on smaller virtual private servers. With the installation of MySQL, the virtual server provider has just sent the access password to your slice! It is now time to log in through SSH and start the installation. Start with MySQL. Some pre installed Ubuntu versions may already have MySQL 5.5 as part of the package list. Otherwise, you must do the following: The
Sudo apt get install MySQL server now is the time to adjust Mysql to as little memory as possible, but it still works normally. The first option is to use MyISAM or InnoDB, the two most popular table engines. MyISAM is the oldest, and InnoDB is the foundation of mysql5.5. There is a heated discussion on the Internet about which solution is most suitable for the text printing machine. In other words, it may be a matter of personal preference and specific environment. The most important thing is to use only one of them. It is meaningless to let MySQL run both at the same time, which saves memory. The
It is worth mentioning that after reading Mark Maunder’s article (people who benchmark MySQL with both methods), MyISAM seems to be the first choice for single CPU environments. This tutorial uses a small virtual server with only one CPU core, so you will continue to use MyISAM\/ Etc\/mysql\/my Open CNF (requires a text editor. Nano is a widely used tool and should be installed on most systems. Otherwise, you can use sudo apt get install nano) to change \/ add the following: The
#
#* MySQL configuration for tiny memory footprint
#
[client]
Port = 3306
Socket = \/var\/run\/mysqld\/mysqld Sock
[mysqld_safe]
Socket = \/var\/run\/mysqld\/mysqld Sock
Nice = 0
[mysqld]
#
#* basic settings
#
User = MySQL
PID file = \/var\/run\/mysqld\/mysqld PID
Socket = \/var\/run\/mysqld\/mysqld Sock
Port = 3306
Basedir = \/usr
DataDir = \/var\/lib\/mysql
TMPDIR = \/tmp
LC messages dir = \/usr\/share\/mysql
Skip external locking
Skip networking
Key_buffer = 24m
Sort_buffer_size = 4m
Read_buffer_size = 4m
#Binlog_cache_size = 2m
Max_allowed_packet = 12m
Thread_stack = 128K
Thread_cache_size = 8
#This replaces the startup script and checks MyISAM tables if n
Since service mysql start is empty by default, the root password of MySQL (also known as \
Sudo mysqladmin-u root-h myhostname password \
Nginx=stable \use nginx=development for latest development version
Add apt repository ppa:nginx\/$nginx
Apt get update
If apt get install nginx add apt repository not exist has an error, you must install Python software properties. Sudo apt get install Python software properties, and then re run the above command. The Apache Web server can run nginx and Apache in parallel on the same server (for example, let nginx handle static content and Apache handle PHP). However, this guide assumes that only nginx is running. We will use the same data directory structure that Apache uses (the directory where the actual files are located on the web site). What’s the matter. If you decide to remove nginx, you can easily change it to Apache. Or, if you follow some tutorials on the web, assuming you have the \
You may remember the PHP 5 extension and php-fpm installation, but nginx only handles static files. The rest must be transferred to external services. In our case, php-fpm is used instead of nginx to process PHP5. Php-fpm is the same as a mini web server with its own options, but only handles PHP. I’ll explain later. Knowing what PHP 5 extensions you really need is not always easy! This tutorial wants to use as few PHP 5 extensions as possible (to minimize memory consumption!) WordPress (or some plug-ins) depends on this, so at least a few are required. I mainly follow Rahul Bansal’s advice. The first step is to get PHP 5.4 (instead of the default PHP 5.3 that comes with Ubuntu 12.04 LTS). This means adding additional repositories to get the latest version. The latest version of Ubuntu may already include PHP 5.4 as the default, so you can skip this step. Sudo add apt repository ppa:ondrej\/php5
Sudo apt get update now requires PHP 5 and all required modules to be installed. Sudo apt get install PHP5 common PHP5 MySQL PHP5 XMLRPC PHP5 CGI PHP5 curl PHP5 cli PHP5 FPM PHP APC PHP5 dev PHP5 mcrypt some WordPress plug-ins may need to add PHP5 pear to the corresponding list (if you use a press release sent to users by mail, PHP5 IMAP, etc.). International users may add PHP5 Intl. I usually add PHP5 tidy used by W3 total cache, but it is not required. To provide a general overview of the operations performed by the nginx configuration under the nginx configuration, please understand that nginx is composed of rules. (images, CSS, etc.), forward PHP scripts to php-fpm or block access (for security reasons). Nginx can perform more processing, such as adding unexpired headers, deleting cookie requests for static files (for better caching), or immediately compressing all content into gzip (for bandwidth savings). Here is \/etc\/nginx\/nginx, which handles most common functions. Conf file. User www data;
Worker_processes 1;
PID \/var\/run\/nginx PID;
Events{
Worker_connections 256;
#Multi_accept on;
}The
Http{
##The
#Basic settings
##The
Sendfile on;
Tcp_nopush on;
Tcp_nodelay on;
Keepalive_timeout 65;
Types_hash_max_size 2048;
Server_tokens off;
Client_max_body_size 8m;
Reset_timedout_connection on;
#Server\names\u hash\u bucket\u size 64;
#Server_name_in_redirect off;
Index PHP index HTML index Htm;
Include \/etc\/nginx\/mime Types;
Default_type application\/octet stream;
##The
#Logging settings
##The
Access_log \/var\/log\/nginx\/access Log;
Error_log \/var\/log\/nginx\/error Log;
##The
#Gzip settings
##The
Gzip on;
Gzip_disable \
Upstream PHP5 FPM{
Keepalive 8;
Server
Unix:\/var\/run\/php5-fpm Sock;
}The
#Include \/etc\/nginx\/conf.d\/* Conf;
Include \/etc\/nginx\/sites-enabled\/*;
}Please note the following: First, worker_processes must be set to 1 per CPU (there is only one CPU in my VPS). Client_max_body_size is the size of the file uploaded through post. The default value is 1 meter (1 MB), but the default value for PHP to upload files is 8, so it is recommended to keep these two settings the same. Upstream commands are settings for communicating with php-fpm. As you can see, we are using UNIX sockets to communicate with php-fpm, just as MySQL does. If one VPS has nginx, the other VPS has php-fpm settings (for example, using nginx as a front-end reverse proxy \/ cache server), not my. Ip Address: use the PortNumber server. This guide shows the single site and multi site configurations for word press. The two selected configuration files are stored in \/etc\/nginx\/conf.d\/, so activate the corresponding files as needed. This is why the line is annotated. WordPress works differently in multi site mode, so I don’t want to load two configurations at the same time! The configuration of single site WordPress (stored in \/etc\/nginx\/conf.d\/wordpress.conf) is WordPress. Inspired by the WordPress project of the nginx wiki, which describes org’s recommendations and best practices, including: There are also several ways to avoid common pitfalls# WordPress single blog rules
#Designed to be included in any server {} block
#This order might see weight – this is attempted to match last if rules below fail
# http:\/\/wiki.nginx.org\/HttpCoreModule
Location \/{
Try\u files $uri $uri\/ \/index PHP$ Args;
}The
#Add trailing slash to *\/wp-admin requests
Rewrite \/wp admin$$scheme:\/\/$host$uri\/ permanent;
#Directions to send expires headers and turn off 404 error logging
Location ~* ^.+\ (xml|ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc XLS exe ppt tar MIDI wav BMP RTF) ${
Access_log off; Log\u not\u found off; Expires max;
}The
#Uncomment one of the lines below for the appropriate caching plugin (if used)
#Include global\/wordpress-wp-super-cache Conf;
#Include global\/wordpress-w3-total-cache Conf;
#Pass all PHP files onto a PHP FPM \/ PHP fcgi server
Location ~ \ Php${
#Zero day exploit defense
# http:\/\/forum.nginx.org\/read.php?2 , 88845, page=3
#Won’t work properly (404 error) if the file is not stored on this server, which is
#Truly possible with PHP FPM \/ PHP FC
Gi
#Comment the’try_files’line out if you set up PHP FPM \/ PHP fcgi on other machine# And then cross your fingers that you won’t get hacked
Try\u files $uri =404;
#Fastcgi_split\u path\u info ^ (.+\.php) (\/.+) $;
#Note: you should have \
Include fastcgi_params;
Fastcgi_index PHP;
#Fastcgi_param script_filename $document_root$fastcgi_script_name;
#Fastcgi_intercept_errors on;
Fastcgi_keep_conn on;
Fastcgi_pass PHP5 FPM;
}Now, the rules of WordPress running in multi site mode (stored in \/etc\/nginx\/conf.d\/wordpress-mu.conf): \wordpress multi site subdirectory rules.
#Designed to be included in any server {} block
Index PHP;
#This order might see weight – this is attempted to match last if rules below fail
# http:\/\/wiki.nginx.org\/HttpCoreModule
Location \/{
Try\u files $uri $uri\/ \/index PHP$ Args;
}The
#Add trailing slash to *\/wp-admin requests
Rewrite \/wp admin$$scheme:\/\/$host$uri\/ permanent;
#Pass all PHP files onto a PHP FPM \/ PHP fcgi server
Location ~ \ Php${
#Zero day exploit defense
# http:\/\/forum.nginx.org\/read.php?2 , 88845, page=3
#Won’t work properly (404 error) if the file is not stored on this server, which is truly possible with PHP FPM \/ PHP fcgi
#Comment the’try_files’line out if you set up PHP FPM \/ PHP fcgi on other machine And then cross your fingers that you won’t get hacked
Try\u files $uri =404;
#Fastcgi_split\u path\u info ^ (.+\.php) (\/.+) $;
#Note: you should have \
Include fastcgi_params;
Fastcgi_index PHP;
#Fastcgi_param script_filename $document_root$fastcgi_script_name;
#Fastcgi_intercept_errors on;
Fastcgi_pass PHP5 FPM;
}The
Location ~ ^\/files\/ (.*) ${
Try_files \/wp content\/blogs Dir\/$blogid\/$uri \/wp includes\/ms-files PHP? File=$1;
#Access_log on; Log\u not\u found on; Expires max;
}The
#Avoid PHP readfile()
Location ^ ~ \/blogs Dir{
Internal;
Alias \/var\/www\/wordpress\/wp-content\/blogs Dir;
Access_log off; Log\u not\u found off; Expires max;
}The
#Directions to send e
You may notice that you need to use aix_pathinfo=0. In addition, for your own time zone, date. Remember to set the timezone (PHP 5.4 is required). The rest must almost always be standard\/ Check the modules that PHP 5 needs to load in etc\/php5\/fpm\/conf.d. In my case, 20 SNMP is not required. Ini must be removed. Each file can call the appropriate extension and set additional parameters. The following list is required: 10-pdo Ini
20 apc Ini
20 curl Ini
20 gd Ini
20 mcrypt Ini
20 mysql Ini
20 mysqli Ini
20 pdo_mysql Ini
20 xmlrpc Ini now needs to be configured to provide PHP services for nginx. PHP FPM includes \/etc\/php5\/fpm\/php FPM. There are other saved configuration files under conf. There is no need to change this file. This is the global configuration of php-fpm. Then start multiple pools. For example, php-fpm works the same way as the web server where the virtual host resides. PHP fpm Conf has complete configuration, \/etc\/php5\/fpm\/pool. D\/ the following is a separate configuration of the pool. By default, there is only one pool named www.conf, which is all we need to edit. Long file. Only changes and partial confirmations that need to be performed are displayed. Male listen = \/var\/run\/php5-fpm Sock
PM = Dynamic
Pm Max_children = 20
Pm Start_servers = 3
Pm Min\u spare\u servers = 1
Pm Max\u spare\u servers = 5
Pm Does max_request=500 look familiar? First, make sure that php-fpm uses the same UNIX socket as nginx. Then use the dynamic allocation of the pool. In this case, instruct php-fpm to start with 3 servers (that is, 3 processes ready to receive nginx PHP requests), and limit it to 20 at most. Keep too many standby servers around, and the child process will terminate every time it processes 500 requests. This naturally reflects my own settings. 512MB ram, some of which naturally require MySQL and nginx (nginx does not occupy a lot of memory). After carefully adjusting several parameters, you can provide 10 concurrent requests and store all processes in memory. No exchange! Of course, this depends on the number of extensions loaded by PHP5, the actual synchronization required (not many 10 concurrent connections), and the speed of web page loading (depending on plug-ins and components). External calls, etc.)… The whole technique is to operate on these numbers before obtaining acceptable performance, so as to avoid disk exchange and prevent users from waiting for pages endlessly! If you want to have a separate log to report processes that have terminated prematurely due to insufficient resources or nginx connection problems and similar errors, please add the following content to the www.conf pool configuration file: Php_admin_value[error_log] = \/var\/log\/fpm-php If it is not www.log, php-fpm will display most (but not all) errors in the web server’s log through the nginx pipeline. Start php-fpm with the following command: Sudo service PHP5 FPM start when Ubuntu starts, please check again whether mysql, nginx and PHP FPM are started (the default behavior of the new installation package that provides network services). Otherwise, update RC. Please use d to register all rooms. Word printing machine is installed. Most of them install word press directly from the source and provide a good reference
The last command of conf is the requirement for W3 total cache (the file exists and must be readable by the web server user). Finally, to make all of this readable on the web server: Chown-r www data: www data \/ var \/ www \/ WordPress WordPress auto installer runs. Please continue WordPress creation. Go and click: the database host is localhost:\/var\/run\/mysqld\/mysqld. It’s a sock. In this way, WP will communicate with the database through the UNIX socket set to MySQL by default. As mentioned above, TCP based network connection is completely avoided. If all goes well, you can go to the familiar steps below. Male or female otherwise there may be two errors. The first reason is that the \
Define (‘wp\u allow\u multisite’, true); When you refresh the browser, the new option appears under Tools > network settings. This tutorial sets it as a separate sub domain. There is a reason. The nginx rule will be easier in the future. At this point, click Install, WP will perform some validation checks and return the missing \
Define (‘subdomain_install’, true);
Define (‘domain_current_site’,’mydomain.com’);
Define (‘path_current_site’,’ \/ ‘);
Define (‘site_id\u current\u site’, 1);
Define (‘blog\u id\u current\u site’, 1); (in fact, under the last line of the definition \
All plug-ins will be added. Personally, I am a jetpack fan Akismet anti spam measures, statistics, WP. Photo caches images on the cloud on COM for free (very useful for maintaining traffic on the website!) Because it contains many useful functions, such as This is a logical system for managing all social network integrations. Moreover, due to many security incidents in WP, you tend to set at least login attempt restrictions. WP remote and backupwordpress, a pair of plug-ins of human made limited, are also very popular. Using the first feature, all WP blogs (even if hosted on other servers!) Centralized free management ensures that the status (core, plug-ins and themes) is always up-to-date and all upgrades are ensured. Backupwordpress is probably one of the simplest free backup plug-ins that can back up content and databases at the same time. In my experience, this is one of the easiest plug-ins to use if you want to migrate from one server to another. Text printer. If both are installed as bonuses, all sites can easily search for backups in the background of WP remote. Therefore, if you manage a large number of WP blogs on other servers, both are required. Both of them are free, easy to use and operate normally, so there is almost no reason not to install them even if there are better (charging) alternatives around. But of course it all depends on you! You really want a domain name mapping. What we really want to add is the WordPress Mu domain mapping. We have in-depth theological discussions, which are not part of the WordPress core. By default, there are two options for configuring the site network. They are all in the same domain, but in different directories (such as mydomain.com\/site1, mydomain.com\/site2, etc.) or in other subdomains. (site1.mydomain.com, site2.mydomain.com) However, in most practical cases, each site has a completely different domain, and you want to be able to manage these domains at the same time. This is the operation of word press Mu field mapping. Indicates that a specific domain, such as myotherdomain.com and otherdomain.com, points to a specific site for installation. Obviously, we need some help from nginx. The next step is to add these two sites, ensure that the sites are correctly designated as the correct locations, and ensure that nginx can correctly forward requests to the correct locations. It is possible to ensure that W3 total cache is working! First, let’s check whether W3 total cache likes the configuration so far. In the network management panel, click the link on performance > panel to confirm the configuration. If all goes well, there should be the following: The important thing here is to detect nginx. In addition, you can see that the APC (alternative PHP cache) module has been activated. Now go to performance > general settings and activate at least page cache, minify, database cache, object cache (and browser cache must be turned on by default). To use this method, use opcache:alternative PHP cache (APC). Click save all settings to save the configuration. W3tc will notify you to empty the page cache. Please continue. If everything is fine, w3tc has done some hidden magic tricks for you. Now \/var\/www\/wordpress\/nginx. Opening the conf file will surprise you. W
3TC may have filled the file for the user! (if there is an empty file or an error occurs, it means that you have forgotten to touch the file before, or you do not have the correct user \/ group ownership or permission. If it is set to WWW, please review it again. -data:www-data and writable) Fine tuning the w3tc is more art than science, but it has become much easier in the recent version. By default, page caching must be normal. Shrinking depends on a lot of things and may be the trickiest part. If you are using cloudflare and are as lazy as I am, make sure that cloudflare handles scaling down. If w3tc adds the login data of cloudflare, it will correctly identify the latest version to communicate with the account and set it to auto collapse. W3tc will disable this option. Cloudflare is always better at allowing CPU cycles to be minimized than using valuable resources for reduction. However, although the folding of cloudflare does not work properly, the w3tc has a specific instance of the work site. This will largely depend on the theme and the plug-in being used, and you have the option to know. If you do not use cloudflare, try to set it automatically and enable at least HTML and XML (including folding inline CSS and folding inline JS), JS and CSS in performance > folding. In addition, you must automatically combine all JS and CSS to get extra points on Google PageRank. I usually don’t disturb the database cache and object cache, but I will go crazy in the browser cache. After changing the settings, I will prevent object caching and use WordPress to handle 404 errors on static objects. In addition, I will open everything. Personalize the error page!). W3tc is a very active plug-in in the development cycle. This means that many options will continue to be added and \/ or removed if they are vague or difficult to understand what is being done. If you are reading this tutorial several years after it was created, it is recommended that you review the recent w3tc tutorials to determine which options have changed and what features they have. Now, let’s install the word press Mu domain mapping plug-in. Remember that for it to work, the network must be active. Then navigate to domain > domain mapping and set the check box in the domain options, as shown below: With the addition of two new websites, mydomain will be created after this tutorial. COM, myotherdomain COM and otherdomain. Com must have three site networks. What we are doing is the following mapping: mydomain. Com refers to the entire installation, the primary site (for example, mydomain.com). Myotherdomain COM is site1. Mydomain Com. Otherdomain COM is site2. Mydomain Com. You must first go to your DNS provider and then add all records. Mydomain You have seen that com is configured to point to your IP address. Now it’s site1. Mydomain COM, site2 Mydomain COM, myotherdomain COM and otherdomain. Com must all be specified as the same IP address (the rest will be handled by nginx). After DNS refresh (then, you can ping the domain and ensure that all domains point to the correct IP address, always the same address!) You can add two sites. Of course, this can be done on network admin>sites>add site. The site address is site 1; Use myotherdomain in the website title; Administrator email is primary
Collection. Final note: how to test all the above before putting into production? It’s time to do some tests. According to the above tutorial, you must have at least 3 domain names, and you must adjust all lines of code to reflect the actual domain name, not for any purpose. However, before entering the production environment, you can perform some tests to verify that the configuration is correct. Here are some simple tips you can use: Use the hosts file to create a false field. Most computers first read fixed IP address assignments from the hosts file, and then are preconfigured to reach DNS name servers. You only need to know the IP address of the server. You must perform this operation on the server and desktop computer running the WordPress installation. On linux\/mac OS X, the file is located under \/etc\/hosts, so you must be able to edit the file using sudo nano\/etc\/hosts and add the following line at the bottom: 192.168.0.1 mydomain COM site1 Mydomain COM site2 Mydomain COM myotherdomain COM otherdomain Of course, 192.168.0.1 must be replaced with the actual IP address of the server. The version on windows is slightly different. It is usually located under c:\windows\system32\drivers\etc\hosts. Please use Notepad for editing (do not use write or word, because it will add many useless formats and may damage all contents!) After making the changes, you will most likely need to exit and restart your browser (because most browsers cache DNS). But there are several considerations. WordPress installation cannot use plug-ins that require the server to call XML-RPC because \