Link Search Menu Expand Document

Wordpress on Nginx

Table of contents

Wordpress Installation

  1. Install LEMP stack
  2. Download Wordpress

    cd /tmp
    wget http://wordpress.org/latest.tar.gz (or, curl -LO https://wordpress.org/latest.tar.gz)
       # check again how to unzip the file in terminal
       # put WP files under /var/www/example.com directory  
    tar xzvf latest.tar.gz
       # un-zip the file 
    cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php
       # copy wp-config-sample.php file
    
  3. Change permission

    chown -R www-data:www-data /var/www/wp.example.com/
       # change owner 
    chmod -R 750 /var/www/linkforideas.com
    chmod -R 755 /var/www/linkforideas.com/wp-content
    curl -s https://api.wordpress.org/secret-key/1.1/salt/
       # get salt
    
  4. Amend wp-config.php file
    • Swap salt and update below info
    define('DB_NAME', '<wordpress>');
    define('DB_USER', '<wordpressuser>');
    define('DB_PASSWORD', '<password>');
    define('FS_METHOD', 'direct'); # add this line as it doesn't exist by default
    

Set up MySQL

Duplicate Wordpress in the same server

  1. Copy the file: cp /var/www/a.example.com /var/www/b.example.com

  2. Create new database name

    Exporting

    mysqldump -uroot -p old_database_name > dumpfilename.sql
    

    Importing

    mysql -uroot -p new_database_name < dumpfilename.sql
       # make sure the [new-database] is created before importing
    
  3. Change url in MySQL

    mysql > show databases;
    mysql > use [wordpress];
    mysql > show tables;
    mysql > update [wp_options] set option_value = ['http://www.correctDomain.name'] where option_id = 1;
       # to update [site-url], without brackets 
    mysql > update [wp_options] set option_value = ['http://www.correctDomain.name'] where option_id = 2;
       # to update [home]
    mysql > select * from [wp_options] where option_value = ['http://www.correctDomain.name'];
       # check if this has been updated 
    mysql > grant all on <database-name>.* to '<user-name>'@'localhost';
    mysql > flush Privileges;
    mysql > \q
    
  4. Check wp-config.php and ensure line define('WP_HOME','http://domain.name'); is comment out or removed.

Remove Wordpress

sudo rm -r Wordpress_folder_name

NGINX configuration for Wordpress

Wordpress-CLI

1. Install

cd /opt 
wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
mv wp-cli.phar /usr/local/bin/wp 

2. Usage

cd /var/www/example.com 
   # be in the folder where WP is hosted 
wp theme install singl --allow-root
wp plugin install wordpress-seo --allow-root 
wp theme update —all —-allow-root 
wp user list --allow-root
wp user update 1 --user_pass=123456789 --allow-root
   # update password, 1 is the user ID