Link Search Menu Expand Document

Wordpress on Nginx

Table of contents

Wordpress Installation

  1. Install LEMP stack
  2. Download Wordpress

    cd /tmp
    wget (or, curl -LO
       # check again how to unzip the file in terminal
       # put WP files under /var/www/ 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/
       # change owner 
    chmod -R 750 /var/www/
    chmod -R 755 /var/www/
    curl -s
       # 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/ /var/www/

  2. Create new database name


    mysqldump -uroot -p old_database_name > dumpfilename.sql


    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 = [''] where option_id = 1;
       # to update [site-url], without brackets 
    mysql > update [wp_options] set option_value = [''] where option_id = 2;
       # to update [home]
    mysql > select * from [wp_options] where option_value = [''];
       # 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',''); is comment out or removed.

Remove Wordpress

sudo rm -r Wordpress_folder_name

NGINX configuration for Wordpress


1. Install

cd /opt 
chmod +x wp-cli.phar
mv wp-cli.phar /usr/local/bin/wp 

2. Usage

cd /var/www/ 
   # 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