• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here:Home » How to Install WordPress : Ubuntu 16.04, Nginx, PHP7-FPM

By Abhishek Ghosh June 7, 2016 11:46 pm Updated on June 12, 2016

How to Install WordPress : Ubuntu 16.04, Nginx, PHP7-FPM

Advertisement

All softwares installed are latest in this guide while publication of this guide. This guide is consistent with WordPress official documentation on Nginx, but tweaks are not included. This Step by Step Guide on How to Install WordPress on Ubuntu 16.06, Nginx, PHP7-FPM, memcached & MySQL on Cloud Server or VPS is Intended For the New Users. The Older How to Install WordPress on Ubuntu 14.04 LTS with Nginx Guide is a Complete Guide and Referenced in WordPress Documentation. But do not follow it right now, instead follow this guide. PHP5 and PHP7 has differences.

W3 Total Cache is enough to handle all the caches. If you cache those Static HTML pages with Nginx Microcache, then you’ll need their WordPress Plugin. Do not copy-paste from here and there without understanding. If you follow our plus WordPress DOT ORG’s codex.wordpress.org settings for Nginx; you will not face any trouble. Nginx Microcache is not shown to enable in this guide.

Contents of How to Install WordPress

  1. Introduction
  2. Server Components
    1. Nginx Extras Webserver Software
    2. Percona MySQL Server 5.7 Software
    3. Install PHP 7.0 Components
    4. Install WordPress
  3. WordPress Nginx Documentation
  4. Installing Memcached
  5. Next Steps (Configuring Email, CDN, DNS)
  6. Automation of this guide with DevOps and Bash Script

 

How to Install WordPress Ubuntu 16.04 : SSH for 100% New Users

 

Advertisement

---

Microsoft Windows will use PuTTY and GNU/Linux users and OS X users will use Terminal, Terminal or iTerm2 respectively.

If the command line interface feels bad, during configuration to install WordPress you can use FileZilla or Command Line File Browser to edit or see the files.

We are starting after you login to your server after typing the password, get authenticated upon running the command :

Vim
1
2
3
ssh username@IP_address
# Example
# ssh root@127.0.0.1

We used a Cloud Server instance for This How to Install WordPress on Ubuntu 16.04, Nginx, PHP7-FPM Installation Guide. Dedicated Server’s commands will be same some basic security steps is mandatory. We omitted that part. Basic Philosophy of How to Install WordPress on Ubuntu 16.04 Guide is to :

  1. Install webserver software Nginx.
  2. Install MySQL
  3. Install PHP

WordPress will run top of it.

 

How to Install WordPress Ubuntu 16.04 : Nginx Extras Webserver Software

 

We use nginx-extras from Ubuntu’s repository because Nginx Extras has important updated functions needed for WordPress like fastcgi cache purge module. We use the default paths. So, here we go, type these commands one by one :

Steps to Install WordPress Ubuntu 16.04 and Nginx Extras
Vim
1
2
3
4
apt update
apt upgrade
apt upgrade
apt install nginx-extras

Edit /etc/nginx/nginx.conf :

/etc/nginx/nginx.conf
Vim
1
nano /etc/nginx/nginx.conf

modify error_log to :

Vim
1
error_log  /var/log/nginx/error.log warn;

Open your server IP on a browser, you’ll see the default Nginx webpage. Easy step.

 

How to Install WordPress Ubuntu 16.04 : Percona MySQL

 

Heart of WordPress is Database. It is most difficult part. Instead of original MySQL, we use Percona MySQL with innodb Engine. Percona MySQL and normal SQL has no difference in commands, it is a special optimized version. You can easily optimize later. These will not be written by somehow written guides by Digital Ocean or Linode. Percona MySQL is preferred as Percona has free tuning service.

reference
Vim
1
https://www.percona.com/doc/percona-server/5.6/installation/apt_repo.html

Run these commands :

Steps to Install WordPress Ubuntu 16.04 and Percona MySQL
Vim
1
2
3
4
5
6
gpg --keyserver  hkp://keys.gnupg.net --recv-keys 1C4CBDCDCD2EFD2A
gpg -a --export CD2EFD2A | apt-key add -
sudo sh -c 'echo "deb http://repo.percona.com/apt xenial main" >> /etc/apt/sources.list.d/percona.list'
apt update
sudo apt install percona-server-5.7
sudo mysql_secure_installation

You can optimize it later using Percona’s service and Major Hayden’s MySQL Tuner. We prefer InnoDB engine. Running sudo mysql_install_db consumes a time, it creates all the needed directories and settings files. sudo mysql_secure_installation needed to ensure security. Now login to MySQL server and run the commands specific for Percona (you’ll see they are instructed to run) :

Vim
1
2
3
4
5
6
7
8
9
mysql -u root -h localhost -p
# run after login
CREATE FUNCTION fnv1a_64 RETURNS INTEGER SONAME 'libfnv1a_udf.so';
CREATE FUNCTION fnv_64 RETURNS INTEGER SONAME 'libfnv_udf.so';
CREATE FUNCTION murmur_hash RETURNS INTEGER SONAME 'libmurmur_udf.so';
# you should exit
exit
# then restart mysql
service mysql restart

Now, again login and create database, add password etc. yourserver2016, wordpress2016, BAD_PASSWORD__change are my own custom phrases, you should change to yours difficult to guess combinations :

Vim
1
2
3
mysql -u root -h localhost -p
CREATE USER 'yourserver2016'@'localhost' IDENTIFIED BY 'BAD_PASSWORD__change';
CREATE DATABASE wordpress2016;

MySQl server’s root with password while installing MySQL ALWAYS can access the database. We add user with a password to separate the chance of attack, we sometimes never create a user if one MySQL has one database on different server. This step is for higher security, MySQl server’s root with password would work to install WordPress. The extra steps :

Vim
1
2
3
GRANT SELECT,DELETE,INSERT,UPDATE ON wordpress2016.* TO 'yourserver2016'@'localhost';
GRANT ALL PRIVILEGES ON wordpress2016.* TO 'yourserver2016'@'localhost';
FLUSH PRIVILEGES;

MySQL need no PHPMyAdmin to manage. PHPMyAdmin is good for 100% new users. PHPMyAdmin will eat RAM and increase security risks.

Vim
1
2
mysql -u root -h localhost -p
show databases;

After completion of this step, you can run a cat command on /etc/mysql/my.cnf. You can optimize it later like using some basic tweaked and ready to my.cnf from our GitHub repo. Percona has no my.cnf by default. Percona MySQL is for the advanced users. Most important to read how to “enable” Auto Restart of MySQL. Otherwise MySQL will not Auto-Restart on failure and throw infamous Error Establishing a Database Connection message.

Vim
1
2
3
echo " " > /etc/mysql/my.cnf
cd ~ && wget https://raw.githubusercontent.com/AbhishekGhosh/Nginx-PHP5-FPM/master/percona-mysql-server/fail-safe-my.cnf
cat fail-safe-my.cnf > /etc/mysql/my.cnf

If fails to restart, then check :

Vim
1
cat /var/log/mysql/error.log

We have finished installing MySQL database part.

 

How to Install WordPress Ubuntu 16.04 : PHP 7.0.7

 

We install some PHP version specific packages for full support of all plugins – common, mysqlnd, xmlrpc, curl, gd, cli, fpm, pear, dev, imap, mcrypt, snmp, intl, imagick, ming, ps, pspell, recode, snmp, mysql, sqlite, tidy, xsl, libssh2, memcached.

This is minimum you should run :

Vim
1
2
sudo add-apt-repository ppa:ondrej/php
apt install libcurl3 libmcrypt4 libmemcached11 libxmlrpc-epi0 php7.0-cli php7.0-common php7.0-curl php7.0-fpm php7.0-gd php7.0-intl php7.0-json php7.0-mbstring php7.0-mcrypt php7.0-mysql php7.0-opcache php7.0-readline php7.0-xml php7.0-xmlrpc psmisc libmcrypt-dev mcrypt php-pear php-mysql php-mbstring php-mcrypt php-xml php-intl libmhash2 php-common

The above command is cross tested. It will not give any warning and start installing.

Vim
1
nano /etc/php/7.0/fpm/php.ini

Find cgi.fix_pathinfo. This will be commented out with a semi-colon (;) and set to “1” by default. We will change both of these conditions by uncommenting the line and setting it to “0” like this:

/etc/php/7.0/fpm/php.ini
Vim
1
cgi.fix_pathinfo=0

Now, edit default nginx file with sudo nano /etc/nginx/sites-available/default command and make it like this :

/etc/nginx/sites-available/default
Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
server {
    listen 80 default_server;
    root /usr/share/nginx/html;
    index index.html index.htm index.php;
    server_name localhost;
    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        # fastcgi_split_path_info ^(.+\.php)(/.+)$;
        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
 
        # With php7.0-fpm:
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        include fastcgi_params;
    }
}

Then restart PHP and Nginx :

Vim
1
2
3
sudo systemctl restart php7.0-fpm
# sudo service php7.0-fpm restart
service nginx restart

Now, delete the default file in /usr/share/nginx/html and add PHP file :

/usr/share/nginx/html
Vim
1
2
3
cd /usr/share/nginx/html
rm -r *
nano index.php

Fill with this content :

Final Steps to Install WordPress

 

We are doing the next steps logically :

/usr/share/nginx/html
Vim
1
2
3
4
5
6
7
cd /usr/share/nginx/html && rm -r *
curl -O https://wordpress.org/latest.tar.gz && tar -xzxf latest.tar.gz
rm latest.tar.gz && cd w*
mv * .. && cd ..
rm -r wordpress
cp /usr/share/nginx/html/wp-config-sample.php /usr/share/nginx/html/wp-config.php
rm /usr/share/nginx/html/wp-config-sample.php

Open /usr/share/nginx/html/wp-config.php and add define('FS_METHOD', 'direct'); after database details paragraph to avoid file uploading issue in WordPress :

/usr/share/nginx/html/wp-config.php
Vim
1
2
3
4
5
/** MySQL database password */
define('DB_PASSWORD', 'password');
...
...
define('FS_METHOD', 'direct');

Now, we need to set the permissions and ownership properly :

Vim
1
2
3
4
5
sudo chown -R root:www-data /usr/share/nginx/html
sudo find /usr/share/nginx/html -type d -exec chmod g+s {} \;
sudo chmod g+w /usr/share/nginx/html/wp-content
sudo chmod -R g+w /usr/share/nginx/html/wp-content/themes
sudo chmod -R g+w /usr/share/nginx/html/wp-content/plugins

Open your server IP on a browser, you’ll see the default WordPress Web GUI for Installation. Easy steps, written in WordPress official website too.

 

Example Nginx Configuration is on Official WordPress Docs

 

Now you need some software for monitoring OpCache and Memcached. These are optional steps.

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
cd /usr/share/nginx/html
rm index.html index.php
mkdir mystat && cd mystat
mkdir opcache memcache
cd opcache
wget https://raw.githubusercontent.com/rlerdorf/opcache-status/master/opcache.php
cd .. && cd memcache
wget https://github.com/AbhishekGhosh/phpmemcacheadmin/archive/1.3.tar.gz
tar -xzvf 1.3.tar.gz && rm 1.3.tar.gz
cd php* && mv * ..
cd .. && rm -r phpmem*
chmod +r *
chmod 0777 Config/Memcache.php

You will get the opcache, memcache status in this kind of URLs :

Vim
1
2
http://your_IP_or_domain/mystat/opcache/opcache.php
http://your_IP_or_domain/mystat/memcache/index.php

Password protect the directory with nginx. It is security risk to keep them openly available. Obviously it is your next step, not mandatory. Official Nginx configuration including the needed for W3 Total Cache is written here :

Vim
1
https://codex.wordpress.org/Nginx#Better_Performance_for_Static_Files_in_Multisite

You will again referred to our website from the official listed guides there. Ask on StackExchange or WordPress Forum for help for any issue. You will probably install W3 Total Cache. This guide is compatible with W3 Total Cache, WP Super Cache.

How to Install WordPress-Nginx, PHP7-FPM-Ubuntu-16-04,-Nginx,-PHP7-FPM

 

Memcached?

 

PHP Memcached may fail. Obviously, should not fail. For that reason not added in this guide. Who will install, should be used with memcached, install via apt-get -y install memcached. You will see this works. Test with :

Vim
1
echo stats | nc 127.0.0.1 11211

This is “original” memcached, and wiki is at – https://github.com/memcached/memcached/wiki.

Vim
1
echo stats | nc 127.0.0.1 11211

This is “original” memcached, and wiki is at – https://github.com/memcached/memcached/wiki.

 

What is Next?

 

We have not installed mail server. You can use free tier of Zoho for domain named email. But you need some easy free cloud transactional email service like SendGrid with WordPress Plugin. Otherwise you can not receive email via contact us form. Installing Postfix like self hosted software as mail server not recommended for security. DNSSEC should be configured.

You can install Let’s Encrypt free SSL certificate. You can use KeyCDN or CacheFly CDN, use Dyn DNS for faster DNS resolution.

 

How to Install WordPress Ubuntu 16.04 With Automation

 

We can automate this whole guide with primitive bash script to DevOps tools including Anscible. You may read our Ansible tutorial to create WordPress Nginx Playbook for Ubuntu 16.04 or use bash script to install WordPress-nginx on Ubuntu 16.04.

Tagged With wordpress ubuntu 16 04 , wordpress ubuntu 16 , [keywprd] , wordpress installation 16 04 language:en , ubuntu 16 04 nginx php7 , ubuntu 16 04 php5 6-memcached , ubuntu 16 04 install nginx php7 0 , ubuntu 16 04 php7 0-fpm howto , ubuntu wordpress , how to install wordpress to ubuntu for windows
Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to How to Install WordPress : Ubuntu 16.04, Nginx, PHP7-FPM

  • Nginx WordPress Installation Guide (All Steps)

    This is a Full Nginx WordPress Installation Guide With All the Steps, Including Some Optimization and Setup Which is Compatible With WordPress DOT ORG Example Settings For Nginx.

  • Steps To Install Nginx Plus on Ubuntu Server (HP Cloud)

    Here Are the Steps To Install Nginx Plus on Ubuntu Server Running on HP Cloud. Nginx Plus is the Paid Version of Nginx with Extra Features.

  • WordPress Multisite on Nginx on Ubuntu 14.04 on HP Cloud

    Here is a Step by Step Guide on Setting Up WordPress Multisite on Nginx on Ubuntu 14.04 on HP Cloud with All Commands and the Configuration.

  • Ansible Ubuntu 16.04 1 Click Install WordPress, Nginx Playbook Tutorial

    Following This Tutorial, You Will Be Able to Create Own Ansible 1 Click Install WordPress Nginx Percona MySQL Playbook For Ubuntu 16.04.

performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Hybrid Multi-Cloud Environments Are Becoming UbiquitousJuly 12, 2023
  • Data Protection on the InternetJuly 12, 2023
  • Basics of BJT TransistorJuly 11, 2023
  • What is Confidential Computing?July 11, 2023
  • How a MOSFET WorksJuly 10, 2023
PC users can consult Corrine Chorney for Security.

Want to know more about us?

Read Notability and Mentions & Our Setup.

Copyright © 2023 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy