WordPress, XAMPP, and Windows - a how-to

28
Local WordPress ON BUILDING AND TESTING WORDPRESS WEBSITES ON YOUR OWN COMPUTER By Grant Palin

Transcript of WordPress, XAMPP, and Windows - a how-to

Page 1: WordPress, XAMPP, and Windows - a how-to

Local WordPressON BUILDING AND TESTING WORDPRESS WEBSITES ON YOUR OWN COMPUTER

By Grant Palin

Page 2: WordPress, XAMPP, and Windows - a how-to

Overview

Benefits of developing & testing locally

The options

Installing XAMPP

Installing WordPress

Synchronizing sites

Find this presentation and related materials at

http://grantpalin.com/?p=3788

Page 3: WordPress, XAMPP, and Windows - a how-to

Benefits of developing & testing

locally

Less friction in the workflow

Not dependent on being connected

Isolate radical changes to one environment

Edit Upload Test

Page 4: WordPress, XAMPP, and Windows - a how-to

The options

Separate machine

Dual boot

Virtualize

Varying Vagrant Vagrants (VVV)

WAMP

XAMPP

Page 5: WordPress, XAMPP, and Windows - a how-to

Installing XAMPP

Get the download at

https://www.apachefriends.org/

Run the installer

Really only need Apache, PHP,

MySQL, and phpMyAdmin

Page 6: WordPress, XAMPP, and Windows - a how-to

Installing XAMPP cont.

On Windows, installs by default to C:\xampp

A lot of files and folders, but the one of interest is htdocs

This is where XAMPP hosts websites

Run the XAMPP control panel

It might already be running, look for the system tray icon

Page 7: WordPress, XAMPP, and Windows - a how-to

Installing XAMPP cont.

Page 8: WordPress, XAMPP, and Windows - a how-to

Installing XAMPP cont.

On the Apache line, click Config, then Apache (httpd.conf)

The Apache configuration file opens in the default or configured

text editor

If changing the default port, search for Listen 80, and change the

port number

Also update the ServerName directive to match

Ensure the Rewrite module is enabled:

Disabled#LoadModule rewrite_module modules/mod_rewrite.so

EnabledLoadModule rewrite_module modules/mod_rewrite.so

Page 9: WordPress, XAMPP, and Windows - a how-to

Installing XAMPP cont.

The DocumentRoot directive specifies the default website location

Default configuration for the default website location

<Directory “C:\xampp\htdocs”>…</Directory>

Virtual hosts are used to run multiple named websites, rather than all off of localhost

# Virtual hostsInclude conf/extra/httpd-vhosts.conf

Open the file at C:\xampp\apache\conf\extra\httpd-vhosts.confin a text editor

Page 10: WordPress, XAMPP, and Windows - a how-to

Installing XAMPP cont.

This file can contain directives for multiple virtual hosts

A virtual host directive looks like:

<VirtualHost grantpalin.com.dev:81>DocumentRoot "C:/xampp/htdocs/grantpalin_com"ServerName grantpalin.com.dev<Directory "C:/xampp/htdocs/grantpalin_com">

Require all granted</Directory>

</VirtualHost>

The local domain including custom port

The local domain,

no port

The filesystem location

Required for XAMPP security

Page 11: WordPress, XAMPP, and Windows - a how-to

Installing XAMPP cont.

With a virtual host ready, must edit the hosts file

Located at C:\Windows\System32\drivers\etc\hosts

It has no extension, but is a text file

Normally a system file, so must change permissions so it can be

edited

Right-click the file, choose Properties

Page 12: WordPress, XAMPP, and Windows - a how-to

Installing XAMPP cont.

Need to add

these permissions

Click here

Select the

current user

Check

these boxes

Page 13: WordPress, XAMPP, and Windows - a how-to

Installing XAMPP cont.

With the updated permissions, can now edit the hosts file in a text

editor

For each local site, add a line like:

127.0.0.1 grantpalin.com.dev

Save and close the file

Always refers to the same computer The local domain, no port

Page 14: WordPress, XAMPP, and Windows - a how-to

Installing WordPress

Download the latest version from https://wordpress.org/download/

Extract the zip file to a directory within htdocs

Name the directory to reflect the site

To set up the database, point your web browser at

http://localhost/phpmyadmin

Include the custom port if you chose one, e.g.

http://localhost:81/phpmyadmin

Page 15: WordPress, XAMPP, and Windows - a how-to

Installing WordPress cont.

Switch to the Databases view

Type a name and submit

Page 16: WordPress, XAMPP, and Windows - a how-to

Installing WordPress cont.

Go to Add user view Fill the form and submit

Page 17: WordPress, XAMPP, and Windows - a how-to

Installing WordPress cont.

Choose the just-created database

Check the first two groups

Page 18: WordPress, XAMPP, and Windows - a how-to

Installing WordPress cont.

One last preparation step before WordPress is up and running

In the directory where WordPress is located, copy the wp-config-sample.php file to wp-config.php, and open the new file

On the following lines, fill in your database & user details:

define('DB_NAME', 'database_name_here');define('DB_USER', 'username_here');define('DB_PASSWORD', 'password_here');define('DB_HOST', 'localhost');

Save the file, and point your browser to your local domain

Page 19: WordPress, XAMPP, and Windows - a how-to

Installing WordPress cont.

If all is well, the installation process will

begin

If there is a message about a databaseerror, double-check the entries made inthe wp-config.php file

Enjoy the famed five-minute install

Page 20: WordPress, XAMPP, and Windows - a how-to

Synchronizing sites

Supposing that there is a live site already with content, and one

wants to synchronize this site to a local copy

There are multiple ways to do this, buta recommended route is using the

WP Migrate DB plugin

Free, found athttps://wordpress.org/plugins/wp-migrate-db/

Can install through the WordPress

plugin manager

Page 21: WordPress, XAMPP, and Windows - a how-to

Synchronizing sites

cont.

In the case of a live site with content to sync down, go to Tools -> Migrate DB on the live site

The left side has values based on the live site setup

Enter on the right side the equivalents for the local setup

The exported file has the replacements made

Can save the settings for future use

Page 22: WordPress, XAMPP, and Windows - a how-to

Synchronizing sites cont.

The output is a zipped SQL file

Can be imported through phpMyAdmin

Go here

Page 23: WordPress, XAMPP, and Windows - a how-to

Synchronizing sites cont.

Unzip the downloaded zip file

In phpMyAdmin, select the SQL file

On submitting, phpMyAdmin will run the SQL

and the database will be updated

Files are not included, only data

Select the SQL file

Run the SQL query

Page 24: WordPress, XAMPP, and Windows - a how-to

Synchronizing sites cont.

WP Migrate DB has a bigger brother, WP Migrate DB Prohttps://deliciousbrains.com/wp-migrate-db-pro/

Paid, but adds features:

Synchronizes media (requires developer license)

Synchronization can be automated – no handling SQL files

Works over HTTPS

Backs up the target database before replacing

Can synchronize in both directions

Choose which tables to migrate

Choose which content types to migrate

Saves a LOT of time, and time is money

Page 25: WordPress, XAMPP, and Windows - a how-to

Additional configuration tips

Settings in the wp-config.php are typically intended for a particular

environment e.g. local or live

Upload a local copy by mistake and the live site may malfunction

Put a conditional in the file to load the appropriate settings

if (file_exists(dirname(__FILE__) . '/wp-config-local.php')) {include(dirname(__FILE__) . '/wp-config-local.php');// additional local configuration

}

// live site configuration

The appropriate settings are used based on the presence or absence of

a local-only file

Page 26: WordPress, XAMPP, and Windows - a how-to

Additional configuration tips cont.

A useful configuration option is to define the site url and home:

define('WP_SITEURL', 'http://grantpalin.com');define('WP_HOME', 'http://grantpalin.com');

Avoids the site getting confused when it is updated or migrated

Avoids the setting being mistakenly changed in the admin

Page 27: WordPress, XAMPP, and Windows - a how-to

Additional configuration tips cont.

Local

define('WP_LOCAL_DEV', true);

define('WP_DEBUG', true);

define('SAVEQUERIES', true);

// logs to wp-content/debug.log

define('WP_DEBUG_LOG', true);

define('WP_DEBUG_DISPLAY', true);

Live

define('WP_LOCAL_DEV', false);

define('WP_DEBUG', false);

define('SAVEQUERIES', false);

// logs to wp-content/debug.log

define('WP_DEBUG_LOG', true);

define('WP_DEBUG_DISPLAY', false);

define( 'DISALLOW_FILE_EDIT', true );

define('FORCE_SSL_ADMIN', true);

Page 28: WordPress, XAMPP, and Windows - a how-to

Recap

Developing locally speeds workflow, reduces connectivity issues

Numerous choices available for running sites locally

XAMPP is easy to install, but takes some configuration

Ditto for WordPress

Synchronizing live and local sites can be easy