Install WordPress with LEMP on Ubuntu 18.04

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 18.04
  2. Configure Static IP with NetPlan
  3. Basic configuration of ubuntu 16.04 server
  4. Install Nginx, MariaDB and PHP7 (LEMP Stack)
  5. Install WordPress
  6. Install WP-CLI (Optional)

Nginx 1.14.0
Nginx 1.14.0 is the default in ubuntu 18.04 Server

su -
apt install nginx -y 
nginx -v
    nginx version: nginx/1.14.0
Enable Nginx to start when the system boot up 
systemctl enable nginx.service
systemctl status nginx

Check your public IP with and try to access http://publicIP to verify that NGINX is up and running successfully

curl -4 icanhazip.com

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

add-apt-repository ppa:ondrej/php -y
apt-get update
#Install PHP7.1 
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 
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

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

MariaDB 10.2
Add the repository for latest MariaDB

apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
sh -c "echo 'deb https://mirrors.evowise.com/mariadb/repo/10.2/ubuntu '$(lsb_release -cs)' main' > /etc/apt/sources.list.d/MariaDB102.list"
apt-get update

Install MariaDB

apt-get install mariadb-server mariadb-client
systemctl enable mariadb.service
#secure the MariaDB by answering YES to all questions
mysql_secure_installation

systemctl restart mariadb

Preparing DB for WordPress

sudo mysql -u root -p
CREATE DATABASE wordpress;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'XXXXXXXX';
GRANT ALL ON wordpress.* TO 'wpuser'@'localhost' IDENTIFIED BY 'XXXXXXXX' 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
mv wordpress /var/www/html/wordpress
#Grant ownership to www-data 
chown -R www-data:www-data /var/www/html/wordpress/
#Assign full permission to owner (www-data), and remove write permission for other users
chmod -R 755 /var/www/html/wordpress/

Prepare the

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  aventistech.com;

     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
ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
#copy the wordpress conf 
cp /var/www/html/wordpress/wp-config-sample.php /var/www/html/wordpress/wp-config.php
#To add the Database prepared in MariaDB 
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', 'XXXXXXXX');

Restart NGINX service again and complete the WordPress installation via GUI – https://aventistech.com

systemctl restart nginx

Secure the wordpress with LetEncrypted Free SSL Certificate following Free Let’s Encrypt SSL Certificate

Optional – Install WP-CLI

#Download WP-CLI 
cd /tmp
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar                                                                    
#verify the wp-cli.phar is working fine
php wp-cli.phar --info
#Grant Execute permission and move it to /usr/local/bin/wp
chmod +x wp-cli.phar
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
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