WordPress-Ubuntu16.04 with LEMP in VMware

Please refer to the following steps on how to setup a UAT Server in my VMware ESXi 6.5 to study and testing purpose

  1. Provision a new VM and install with ubuntu 16.04
  2. Basic configuration of ubuntu 16.04 server
  3. Install Nginx, MariaDB and PHP7 (LEMP Stack)
  4. Install WordPress
  5. Install WP-CLI (Optional)

Nginx 1.14.0
Add the repository for the stable version of Nginx

sudo add-apt-repository ppa:nginx/stable
sudo apt-get update 
sudo apt install nginx -y 
nginx -v
    nginx version: nginx/1.14.0</code></pre>
Enable Nginx to start when the system boot up 
<pre><code class="lang-bash">sudo systemctl enable nginx.service
sudo systemctl status nginx

PHP7.1
Add the repository for latest PHP and install PHP7.1

sudo add-apt-repository ppa:ondrej/php -y
sudo apt-get update
#Install PHP7.1 
sudo apt-get install php7.1-fpm php7.1-common php7.1-mysqlnd php7.1-xmlrpc php7.1-curl php7.1-gd php7.1-imagick php7.1-cli php-pear php7.1-dev php7.1-imap php7.1-mcrypt -y
#Verify PHP7.1 is installed 
sudo php-fpm7.1 -v
PHP 7.1.17-1+ubuntu16.04.1+deb.sury.org+1 (fpm-fcgi) (built: May  5 2018 04:55:21)
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.1.17-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies

Modify the MAX upload file size in php.ini file

sudo nano /etc/php/7.1/fpm/php.ini
    upload_max_filesize = 64M
    post_max_size = 8M
#Verify the configuration is valid 
sudo php-fpm7.1 -t
#Restart php71 
sudo systemctl restart php7.1-fpm

MariaDB 10.2
Add the repository for latest MariaDB

sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
sudo sh -c "echo 'deb https://mirrors.evowise.com/mariadb/repo/10.2/ubuntu '$(lsb_release -cs)' main' > /etc/apt/sources.list.d/MariaDB102.list"
sudo apt-get update</code></pre>
Install MariaDB
<pre><code class="lang-bash">sudo apt-get install mariadb-server mariadb-client
sudo systemctl enable mysql.service
#secure the MariaDB by answering YES to all questions
sudo mysql_secure_installation
sudo systemctl restart MySQL</code></pre>
Preparing DB for WordPress 
<pre><code class="lang-bash">sudo mysql -u root -p
CREATE DATABASE wordpress;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'P@ssw0rd';
GRANT ALL ON wordpress.* TO 'wpuser'@'localhost' IDENTIFIED BY 'P@ssw0rd' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;

WordPress
Download and install WordPress

cd /tmp && wget https://wordpress.org/latest.tar.gz
tar -zxvf latest.tar.gz
sudo mv wordpress /var/www/html/wordpress
#Grant ownership to www-data 
sudo chown -R www-data:www-data /var/www/html/wordpress/
#Assign full permission to owner (www-data), and remove write permission for other users
sudo chmod -R 755 /var/www/html/wordpress/

Prepare the Configuration File for Nginx for WordPress

sudo vi /etc/nginx/sites-available/wordpress
#Copy & Paste the configuration below 
server {
    listen 80;
    listen [::]:80;
    root /var/www/html/wordpress;
    index  index.php index.html index.htm;
    server_name  mylab.aventistech.info;

     client_max_body_size 100M;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
         include snippets/fastcgi-php.conf;
         fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
         include fastcgi_params;
    }
}

Modify the wp-config.php file to include the parameter for wordpress database prepared in MariaDB

#Link the wordpress to nginx
sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
#copy the wordpress conf 
sudo cp /var/www/html/wordpress/wp-config-sample.php /var/www/html/wordpress/wp-config.php
#To add the Database prepared in MariaDB 
sudo vi /var/www/html/wordpress/wp-config.php

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');

/** MySQL database username */
define('DB_USER', 'wpuser');

/** MySQL database password */
define('DB_PASSWORD', 'user_password_here');

Restart Nginx Service and complete the wordpress installation via GUI – http://mylab.aventistech.info/wp-admin

sudo systemctl restart nginx

Optional – Install WP-CLI

#Download WP-CLI 
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar                                                                      -pages/phar/wp-cli.phar
#verify the wp-cli.phar is working fine
sudo php wp-cli.phar --info
#Grant Execute permission and move it to /usr/local/bin/wp
sudo chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp

wp --info
OS:     Linux 4.4.0-116-generic #140-Ubuntu SMP Mon Feb 12 21:23:04 UTC 2018 x86_6                                                                        4
Shell:  /bin/bash
PHP binary:     /usr/bin/php7.1
PHP version:    7.1.17-1+ubuntu16.04.1+deb.sury.org+1
php.ini used:   /etc/php/7.1/cli/php.ini
WP-CLI root dir:        phar://wp-cli.phar
WP-CLI vendor dir:      phar://wp-cli.phar/vendor
WP_CLI phar path:       /tmp
WP-CLI packages dir:
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 1.5.1

#Check for latest update
sudo wp cli update
Success: WP-CLI is at the latest version.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top