Skip to content

Instantly share code, notes, and snippets.

@MagePsycho
Last active June 3, 2022 09:44
Show Gist options
  • Save MagePsycho/c06280ee8cbcbc29f71cea3dddfcfe41 to your computer and use it in GitHub Desktop.
Save MagePsycho/c06280ee8cbcbc29f71cea3dddfcfe41 to your computer and use it in GitHub Desktop.
Wordpress: Cheatsheet

Manually (Option 1)

warden shell
cd /tmp
curl -O https://wordpress.org/latest.tar.gz
tar -zxvf latest.tar.gz
touch /tmp/wordpress/.htaccess
mkdir /tmp/wordpress/wp-content/upgrade
cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php
cp -a /tmp/wordpress/. /var/www/html
cd /var/www/html

# Configure the wp-config.php
sed -i 's/database_name_here/wordpress/' /var/www/html/wp-config.php
sed -i 's/username_here/wordpress/' /var/www/html/wp-config.php
sed -i 's/password_here/wordpress/' /var/www/html/wp-config.php
sed -i 's/localhost/wp591_db_1/' /var/www/html/wp-config.php

# Replace the Salts values from below
curl -s https://api.wordpress.org/secret-key/1.1/salt/

Browser the website for installation:
https://app.wp591.test

Using WP CLI (Option 2 - Better)

warden shell

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
./wp-cli.phar --info
./wp-cli.phar core download
./wp-cli.phar core config --dbhost=wp593_db_1 --dbname=wordpress --dbuser=wordpress --dbpass=wordpress
./wp-cli.phar core install --url='https://app.wp593.test' --title='Blog Demo' --admin_user=admin --admin_password=p@ss429 [email protected]

# Browser the website for installation:
# https://app.wp591.test

Using Warden (option 3 - Preferred)

cd /path/to/project

# Init the warden environment
warden env-init <project> wordpress
warden sign-certificate <project>.test
vi .env (if required)
warden env up

# Import the DB
pv /path/to/dump.sql.gz | gunzip -c | warden db import

# Configure the DB
warden db connect

# And edit
# - base url
# Disable not required plugins like reCaptcha
# replace <old-domain> to <new-domain> from blog posts

# Edit the DB settings in wp-config.php

Download the latest DB

scp [email protected]:$(ssh [email protected] find /var/www/backups/blog.magepsycho.com/ -type f -mtime -1 -name "*.sql.gz") ./

Disable not required plugin in localhost (ex: recaptcha)

# Get all the active plugins in serialized form, edit it and update it
SELECT * FROM mpb_options WHERE option_name = 'active_plugins';
UPDATE mpb_options SET option_value = '...' WHERE option_name = 'active_plugins';

Download all the media files

rsync -ravz [email protected]:/var/www/vhosts/blog.magepsycho.com/htdocs/wp-content/uploads/ ./wp-content/uploads/

CHANGE BASE URL

BASIC

SELECT * FROM mpb_options where option_name IN ('siteurl', 'home');
UPDATE mpb_options SET option_value = 'http://blog.mage-expo.com' WHERE option_name IN ('siteurl', 'home');

ADVANCED
Note: Didn't work last time. Maybe you can check one more time

SET @OLD_URL = 'oldurl.com';
SET @NEW_URL = 'newurl.com';
UPDATE mpb_options SET option_value = REPLACE(option_value, @OLD_UR, @NEW_URL) WHERE option_name IN ('siteurl', 'home');
UPDATE mpb_posts SET guid = REPLACE(guid, @OLD_UR, @NEW_URL);
UPDATE mpb_posts SET post_content = REPLACE(post_content, @OLD_UR, @NEW_URL);
UPDATE mpb_postmeta SET meta_value = REPLACE(meta_value, @OLD_UR, @NEW_URL);

RESET PERMISSIONS

cd /path/to/wordpress
chown -R www-data:www-data ./

# Set all directories permissions to 755
find . -type d -exec chmod 755 {} \;

# Set all files permissions to 644
find . -type f -exec chmod 644 {} \;

chmod -v 666 .htaccess
chmod 640 wp-config.php

CHANGE ADMIN PASSWORD

SELECT * FROM mpb_users WHERE user_login = 'magepsycho';                 
UPDATE mpb_users SET user_pass = MD5( 'p@ss429' ) WHERE user_login = 'magepsycho';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment