Skip to content

Instantly share code, notes, and snippets.

@StoyPenny
Last active August 7, 2020 22:16
Show Gist options
  • Save StoyPenny/d64a680005e3717e7ac488cd3b12ea5e to your computer and use it in GitHub Desktop.
Save StoyPenny/d64a680005e3717e7ac488cd3b12ea5e to your computer and use it in GitHub Desktop.
Basic instruction template for setting up a local copy of a WordPress website's repository. Use and extend for your projects.

Welcome

The instructions below are a basic skeleton for creating a get started style guide for your wordpress repository. Feel free to use this as a base for your project, adding custom content as you need for your project.




Getting Started

Use the following as a guide on how to get started setting up your new development environment.

Clone Repo

Navigate to your your local apache server files, often located at /var/www/html/ on standard linux servers.

cd /your/local/server/directory/ 
git clone https://github.com/companyX/projectX.git

Clone Database

Use the following MySQL command to create a backup of the database. This command will dump the SQL file into your current directory, so make sure to navigate to where you want the backup file to be located before using the folling command.

 
mysqldump -u user_name --password='my_password' database_name | mysql -u user_name -p database_name;

After that, use the terminal on your Mac to download the file from the server.

scp user@serverIP:/path/to/remotefile.zip /Local/Target/Destination

Import Database

After you have a local copy of the database ready to go, it's time to actually import the database. Use the comman below, replacing the bold items with your details.

mysql -u username -p database_name < file.sql

Update Database

After cloning the database, you will need to update the URL values that are stored in the WP Options table to match your new site's URL.

UPDATE wp_options SET option_value = 'http://yoursite.com' WHERE option_name = 'siteurl';
UPDATE wp_options SET option_value = 'http://yoursite.com' WHERE option_name = 'home';

Create WP Config

Copy the WP Config file from the root directory of your WordPress installation.

cp wp-config-sample.php wp-config.php 

After creating a copy of this file, you will need to open it so that you can update the following lines in the file:

sudo nano wp-config.php
/** The name of the database for WordPress */
define( 'DB_NAME', 'database_name_here' );

/** MySQL database username */
define( 'DB_USER', 'username_here' );

/** MySQL database password */
define( 'DB_PASSWORD', 'password_here' );

Generate Salts

To complete the setup of the WP Config by adding hashes for the salts. Visit the link below to generate unique salts, then copy and paste these values back into the WP Config file, replacing the default ones that are there.

Generate WP Config Salts

Create .htaccess File

Navigate to the root directory of your WordPress installation and run the following command to create an .htaccess file.

touch .htaccess

Sync Uploads Folder

The Uploads folder is not stored in the Git Repo due to the size and types of content, so you will need to synchronize your installation with the files from the server. Synchronize the files in your uploads folder using Rsync for the most efficient method.

Pattern:

rsync -azP --delete username@remote_host_ip:/source/ /destination

Example:

rsync -azP --delete username@55.555.5.5:/var/www/html/public/wp-content/uploads/ ~/Documents/GitHub/my-project/wp-content/uploads/

Update File Permissions

Files

Set all files to 644

sudo find . -type f -exec chmod 644 {} +

Folders

Set all folders to 755

sudo find . -type d -exec chmod 755 {} +

WP Config

Set WP Config to 600

sudo chmod 600 wp-config.php

Update File Ownership

Ensure that the Apache user, typically www-data, is part of the owner group for the files. Run the following command from the root directory of your WordPress installation, replacing myuser with your username.

sudo find . -exec chown myuser:www-data {} +

Update Permalinks

At this point, you should be able to log into your WordPress installation. Once you are at the WordPress dashboard (yourwebsite.com/admin/) you should be able to navigate to Settings > Permalinks. Once here, scroll to the bottom of the page and click the blue save button. This will flush your permalinks and ensure that your .htaccess file is up to date to handle any redirects.

Enjoy Developing

At this point you should be all good to start developing!

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