Skip to content

Instantly share code, notes, and snippets.

@couetilc
Last active July 9, 2018 02:40
Show Gist options
  • Save couetilc/06d95803b5ebf39ba70a50cac42e287c to your computer and use it in GitHub Desktop.
Save couetilc/06d95803b5ebf39ba70a50cac42e287c to your computer and use it in GitHub Desktop.
Resources for development and maintenance of WordPress

Wordpress resources.

Table of Contents

Wordpress Structure

Template Hierarchy

Theme Template Data Flow

URI Routing

The Loop (Fundamental Concept)

WP Query (Fundamental Concept)

Plug-in Development

Theme Development

The Future of Wordpress (changes in 2018)

Installing Wordpress on Ubuntu 16.04

Compiled From:

Install Nginx

Step 1: Update server packages and install the latest version of nginx

sudo apt-get update
sudo apt-get install nginx

Step 2: Modify nginx configuration to pass requests to WordPress correctly.

Type in bash:

sudo vim /etc/nginx/sites-available/default

and modify the location block to look like:

server {
    ...
    location / {
        # try_files $uri $uri/ =404;
        try_files $uri $uri/ /index.php$is_args$args;
    }
    ...
}

Step 3: Test your nginx configuration and reload

sudo nginx -t
sudo systemctl reload nginx

Install MySQL

MySQL serves as the central repository for all the data your Wordpress application will show your user. Request for pages or posts will be realized as queries on a MySQL database.

Step 1: Install and configure the MySQL server

sudo apt-get install mysql-server

A prompt will appear asking you to input a password. This will be the password for the root mysql user who has full access to the database.

To see your new "mysql" user that manages the MySQL server:

cat /etc/passwd

Step 2: Create a database for Wordpress

To log-in to your MySQL server as the root user, invoke the MySQL CLI and input the password specified upon install. This will start the SQL server's shell interface.

mysql -u root -p

Now create a database that wordpress will control. Then specify a user for wordpress who has full access to the database (replace 'password' with a strong password). In the MySQL shell type

CREATE DATABASE wordpress DEFAULT CHARACTERS SET utf8 COLLATE utf8_unicode_ci;
GRANT ALL ON wordpress.* TO 'wpuser'@'localhost' IDENTIFIED BY 'password';
FLUSH PRIVILIGES;

Once you're in the mysql server shell, you can list all the users registered in the MySQL database. The user "root" has the password you specified upon install, and the user "wpuser" has the password you specified after "IDENTIFIED BY" in the previous command.

SELECT user, host FROM mysql.user

To exit the MySQL shell, type 'EXIT' or 'exit';

Install PHP

Step 1: Install PHP and its extensions used with WordPress.

sudo apt-get update
sudo apt-get install php-fpm php-mysql
sudo apt-get install php-curl php-gd php-mbstring php-mcrypt php-xml php-xmlrpc

Step 2: Secure your PHP installation.

Modify the configuration file /etc/php/7.0/fpm/php.ini to secure the setup by uncommenting the line:

;cgi.fix_pathinfo=1
cgi.fix_pathinfo=1

(In vim execute the command :%s/;cgi.fix_pathinfo/cgi.fix_pathinfo/)

Now restart the PHP processor

sudo systemctl restart php7.0-fpm

Step 3: Modify nginx to serve WordPress

Modify your nginx configuration to use fastcgi.

In /etc/nginx/sites-available/default pre-pend index.php to the list of index pages in the nginx configuration.

index index.html index.htm index.nginx-debian.html;

to

index index.php index.html index.htm index.nginx-debian.html;

Within the server block, add

server {
    ...
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }
    ...
}

Now test your configuration and reload in bash.

sudo nginx -t
sudo systemctl reload nginx

Download WordPress

Step 1: Download the latest WordPress release. Create a default configuration.

cd /tmp
curl -O https://wordpress.org/latest.tar.gz
tar xzvf latest.tar.gz
cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php
mkdir /tmp/wordpress/wp-content/upgrade
sudo cp -a /tmp/wordpress/. /var/www/html

Step 2: Adjust permissions and ownership so WordPress can manage pages without security issues.

sudo chown -R ubuntu:www-data /var/www/html
sudo find /var/www/html -type d -exec chmod g+s {} \;
sudo chmod g+w /var/www/html/wp-content
sudo chmod -R g+w /var/www/html/wp-content/themes
sudo chmod -R g+w /var/www/html/wp-content/plugins

Step 3: Secure your installation

Get a series of random strings ("salt keys") from the WordPress API and modify /var/www/html/wp-config.php to include them.

curl -s https://api.wordpress.org/secret-key/1.1/salt/
# Replace the values in wp-config.php with the values from the curl command.
# Also add the line "define('FS_METHOD', 'direct');" <-- indicates a trusted filesystem is being used.
vim /var/www/html/wp-config.php

Finalize Wordpress Installation

Now navigate to your website's public IP.

You will encounter the WordPress Initialization Wizard.

Fill in the form and Wordpress will be fully installed on your machine.

You will then be brought to WordPress's Admin Interface.

Installing Plug-ins and Themes

Using the plug-in interface, I installed WP ERP, an open-source HR WordPress plug-in. (They have extensions available for purchase)

and Brizy, a modern "What You See Is What You Get" visual editor for WordPress pages.

Using the Admin interface is equivalent to downloading the .zip files and unzipping them into your WordPress installation's /wp-contents/plugins/ directory.

Example using the WP ERP Plug-in.

sudo apt-get update
sudo apt-get install unzip curl
cd /tmp
curl -O https://downloads.wordpress.org/plugin/erp.zip
unzip erp.zip -d /var/www/html/wp-content/plugins/

If you navigate to the "Plugins" page in the Admin Console, you should see the plug-in available to activate.

The same process applies to themes, which are located in the /var/www/html/wp-content/themes/ folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment