WordPress is an open source, PHP based blog and content management system(CMS) made to streamline the process of getting your website up and looking pretty. The WordPress community makes a multitude of plugins (over 30,000) that extend the functionality to make it work just the way you like. There is also an enormous support community to help with any issues.
Nginx(pronounced "engine-x") is a popular light-weight server alternative to Apache. It is considered leaner and meaner than Apache because it uses an event-driven system that chomps through requests rather than spinning up separate processes and threads for each request.
wget https://wordpress.org/latest.tar.gz
tar -xvzf latest.tar.gz
/var/www
directory. The -p
flag will create the directory only if it doesn't exist already: sudo mkdir -p /var/www
/var/www
directory, you can use /usr/share/nginx/www
instead. Make sure to adjust all of the commands and configs if you do.www-data
) to the directory we just created: sudo chown -R www-data:www-data /var/www
www-data
group: sudo usermod -a -G www-data yourusername
(replace "yourusername" with your username)/var/www/
directory: sudo cp -r ~/wordpress/* /var/www
- Don't worry, the files are not public yet. We will change this in the Nginx server block.rm latest.tar.gz
rm -r wordpress/
mysql -u root -p
mysql>
on the left now. Query OK [...]
will appear after you enter each of the following commands.CREATE DATABASE wordpress;
CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'password';
SET PASSWORD FOR 'wordpressuser'@'localhost' = PASSWORD('password');
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
exit;
sudo nano /etc/nginx/sites-available/wordpress
server_name example.com;
and change it to your domain name example.com
. If you don't have a domain, you can use your server IP address.listen
is the port we check for web requests onroot
is the base folder where we have contentindex
is the auto-complete file when nothing is in the url(ex. http://example.com/
)server_name
your domain or IPlocation / { ... }
is the block that allows the Wordpress permalinks to worklocation ~ \.php$ { ... }
is the block that passes any .php
request to the PHPserver {
listen 80;
root /var/www;
index index.php index.html index.htm;
server_name example.com;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to index.html
try_files $uri $uri/ /index.php;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
try_files $uri =404;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Ctrl+x
to exit. Press y
to confirm and then enter
to finally save.sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/wordpress
sudo rm /etc/nginx/sites-enabled/default
sudo service nginx restart
Now when you visit your site either by IP or domain it should show a "There doesn't seem to be a wp-config.php file." dialog like the one below:
Press the Create a Configuration File
button and the Let's go!
button on the following page. Now you should see a form that asks for the database info. Fill it out appropriately with the credentials you set up, then press submit.
Press the Run the install
button on the following page.
Now enter in your site title and admin account info and press the Install WordPress
button. The page should look like this.
It should present you with a "Success!" screen and you should be able to login to the admin panel and visit the main site now.
Login to the WordPress admin interface.
In the left-hand menu go to Settings -> Permalinks. Change the radio button setting to your needs(I usually use "Month and name"). Then click Save Changes
.
W3 Total Cache(W3TC) is a quick and easy way to speed up your site by utilizing the power of caching and minification.
I suggest running Google's PageSpeed Insight test before and after you install to see the improvement.
NOTE: This plugin will cache your files making it a little bit difficult to make theme changes. All you have to do is Purge the cache every time you make a modification.
Login to the WordPress admin interface.
In the left-hand menu go to Plugins -> Add New. Type W3 Total Cache
in the search.
Click the Install Now
link.
If WordPress is asking for your FTP credentials, this means it can't access the files directly. To fix this, just change the wordpress file owner to the www-data
user and group
sudo chown -R www-data:www-data /var/www
Click the Activate Plugin
link(screenshot) after it installs.
Click the W3TC Settings
link or in the left-hand menu go to Performance -> General Settings.
Page cache
. Cache pages for faster loading and more efficient delivery.Minify
. Shrink and combine JS and CSS files for faster loading and more efficient delivery.Object Cache
. Speed up generation of content by WordPress.Browser Cache
. Properly tags content so that browser clients minimize downloads of pages (file header stuff).If you are getting an error(something about the file length 150, etc) with the Minify function: Visit http://example.com/wp-admin/admin.php?page=w3tc_minify#advanced
and check the Disable minify automatic file name length test
option. The Filename length
should be 150. Disable Minify
, save, then re-enable it.
You need to include the W3TC nginx.conf
file generated in the root of your wordpress install to the wordpress nginx server block. Add this to bottom of the server block below the php location block.
/etc/nginx/sites-available/wordpress
server {
[...]
# For W3 Total Cache(W3TC)
include /var/www/nginx.conf;
}
Save(Ctrl+x
) and restart nginx: sudo service nginx restart
There is a lot more you can do with W3 Total Cache but those are just the easy click and done settings. To further utilize this plugin, you could get a CDN to host all of your static files, or even add in the CloudFlare integration.
You could even install Varnish. Varnish is a web app accelerator that stores a copy of a page and serves it immediately when a request comes in rather than having Nginx and WordPress rebuild the page on every request. This will act as another layer of caching on top of W3 Total Cache
.
In the W3 Total Cache
settings under the Reverse Proxy
category make sure to add 127.0.0.1
to the Varnish Servers
textarea. This will allow W3 Total Cache to purge the Varnish cache.
Command | Description |
---|---|
sudo service nginx restart | Restart the Nginx process |
sudo nano /etc/nginx/sites-available/wordpress | Edit the Nginx server block we made for WordPress |