73
r3df.com Rick Radko “Intro to Development Sites and Site Migration” WordCamp Toronto Developers November 3rd, 2012

Intro to development sites and site migration

Embed Size (px)

DESCRIPTION

Presentation slides from WordCamp Toronto Developers 2012 talk. As you begin doing any website design or development, or even just a site restructuring, you will quickly realize that a place to work, test and/or demonstrate a new site without impacting a production site is a necessity. A development site provides that place. This presentation will show you how to setup a simple local (on your pc/laptop) dev site or a hosted dev site. we’ll also see how to migrate WordPress sites, either to clone an existing site to a dev site for updates/testing or to move your finished dev site to the final production site.

Citation preview

Page 1: Intro to development sites and site migration

r3df.com Rick Radko

“Intro to Development Sites and Site Migration”

WordCamp Toronto Developers November 3rd, 2012

Page 2: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

A little bit about me

Rick Radko – R-Cubed Design Forge Software, web and app designer/developer. Creating custom web sites since 1996. Artistic and creative engineer. Co-organizer of: The Ottawa WordPress Group. If you have questions or need help, contact me

at: [email protected].

Slides are posted at: http://www.slideshare.net/r3df

1

Page 3: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Why a “Dev” site?

A development “Dev” site: Safe place to work that won’t disturb a live site. A site where it does not matter if you: WSOD the site. WSOD – White Screen Of Death – blank page from

WordPress when you have an error in your PHP code. http://wordpress.org/tags/wsod

Dump error messages.

2

Page 4: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Why a “Dev” site? Continued…

Safely test, add and remove plugins and themes Plugins and themes can have conflicts with other

plugins/themes or some versions of WordPress. Many plugins and themes don’t clean up after

themselves and leave junk in your database.

Public dev sites: Can be used for client review/demo before going

live. Allow clients to add content before the site is live.

3

Page 5: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Creating a Dev site for WordPress

WordPress needs a web server with PHP and MySQL to run. 2 common options for a dev site server: Hosted: On a sub-domain of the live site. On an alternate domain. Or a sub-domain on another site (like yours).

“Local” web server on your pc or laptop.

May use both local and hosted in the process of a site’s development.

4

Page 6: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Hosted dev sites

Hosted dev sites: Easy for users (clients) to make updates on. Public, but can be protected. Requires an internet connection. Constantly moving files across the net: slow.

Uses existing facilities. (Nothing to set-up) Domain can be: A spare domain. A subdomain on the client site. A subdomain on your site subdomain.

5

Page 7: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

A hosted example

Let’s create a dev site that: Is a copy or “clone” of an existing site. Is hosted. Will be on a subdomain of the existing site.

Creating a dev site like this: Normally takes about 10-15 minutes. Is one of the easiest dev setups to create: Copying the files and database is local to the server.

6

Page 8: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

cPanel

This demo will use cPanel, you may need to adjust to use your hosting’s control panel.

7

Page 9: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Add the sub-domain

Add a sub-domain to the hosted site.

8

Page 10: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Copy over the WordPress files

Copy all of the WordPress files over to the demo folder.

9

Page 11: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Copy the database to a new one – “demo”

Use phpMyAdmin to copy the database.

10

Page 12: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Fix up three things

1) You may need to add a user for the database: phpMyAdmin in most set-ups does not manage the

users. Use the Databases tool to do that. Just add the current

user to the new database.

11

Page 13: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Add all privileges

WordPress recommends “All Privileges”, for the database user. You can reduce this some if you want.

12

Page 14: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Update the config.php file

2) In config.php file you will need to change: The database name. The database user name and password if you

created a new user. Config.php is in the top folder of your WordPress

install, in this case: public_html/demo/.

13

Page 15: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Update the database – if needed

3) Update the database (if the domain changed). The database is full of links and settings with the

site domain. If the domain changes: Links, including the menus, will take you to the

original site. You won’t be able to login to admin, you will go to

the original site. Despite what a lot of tutorials say, DO NOT do a

search and replace in MySQL, or any text search and replace on an SQL dump. If you are lucky you may get away with it, but you will

more likely break serialized data representations. 14

Page 16: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Use a script

The codex page: http://codex.wordpress.org/ Moving_WordPress has some lengthy discussion on the topic of moving sites, but just use the script mentioned in the change URL section. searchreplacedb2.php http://interconnectit.com/124/search-and-

replace-for-wordpress-databases/ It’s easy to use, and does the job in one step. Is aware of serialization, even recursive (nested)

serialization.

15

Page 17: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Run searchreplacedb2.php

To use searchreplacedb2.php Upload searchreplacedb2.php to the top level

WordPress folder, public_html/demo in this case. Enter searchreplacedb2.php in the URL of your

browser, in this case: demo.wpottawa.org/searchreplacedb2.php

16

Page 18: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Opening screen

17

Page 19: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

The database settings

The script retrieved the settings…

18

Page 20: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Select the tables to update

19

Page 21: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Enter the URL changes

20

Page 22: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

It’s done

Over 7500 changes!!! Remember to remove the script!

21

Page 23: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Dev site on a subdomain – complete duplicate

22

Page 24: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

The site is public

In WordPress admin, under Settings -> Privacy Set to “Ask search engines not to index this site”

Don’t want the dev site listed in Google etc.

May also consider password protection. .htaccess or maintenance mode plugins

23

Page 25: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Copying the site back

Same process to copy a revised dev site back. Beware: the original site may change after the

copy to dev. Post/page etc. updates – easy to restrict Comments – no control

May need to do a database merge to accommodate changes.

24

Page 26: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

“Local” web servers

“Local” web server on your pc/laptop. Fast, no internet lag, no FTP’ing of files. All work is local on the computer. Easier to integrate IDE.

No internet connection needed to use it. Can work anywhere you that you can take your

computer. (airplane, remote locations) Usually private. Need to install a web server

25

Page 27: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Local servers – web server stack

WAMP stack Windows, Apache, MySQL, PHP

LAMP stack Linux, Apache, MySQL, PHP

MAMP stack Mac, Apache, MySQL, PHP

*Apache is a web server

26

Page 28: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Some available server stacks

All platforms: BitNami: http://bitnami.org XAMPP: http://www.apachefriends.org

Windows only options: EasyPHP: http://www.easyphp.org WampServer: http://www.wampserver.com

Mac only options: MAMP: http://www.mamp.info Native installs

Linux only options: Native installs

27

Page 29: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

BitNami

BitNami Available for all platforms Easiest to install: If you use the WordPress version. http://bitnami.org/stack/wordpress

Production ready versions Virtual machine versions Cloud deployment (amazon)

28

Page 30: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Information

BitNami install tutorial on wordpress.org: Bit out of date, but still good http://codex.wordpress.org/BitNami

BitNami FAQ: More detailed: http://wiki.bitnami.org/Applications/BitNami_Word

press

29

Page 31: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

A quick BitNami install

Lets see how easy it is to install BitNami:

30

Page 32: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

A quick BitNami install: screen 2

31

Page 33: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

A quick BitNami install: screen 3

32

Page 34: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

A quick BitNami install: screen 4

33

Page 35: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

A quick BitNami install: screen 5 - some details

34

Page 36: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

A quick BitNami install: port 80 conflict!

35

Page 37: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Port conflicts

Possible conflicts: Skype Other web

servers Chat software

36

Page 38: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

A quick BitNami install: port 3306 conflict!

37

Page 39: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

A quick BitNami install: screen 6

38

Page 40: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

A quick BitNami install: screen 7

39

Page 41: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

A quick BitNami install: mail settings

Mail settings screens if you want to set them up.

40

Page 42: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

A quick BitNami install: screen 8

41

Page 43: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

A quick BitNami install: screen 9

42

Page 44: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

A quick BitNami install: screen 10

43

Page 45: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

A quick BitNami install: screen 11

44

Page 46: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Install complete!

45

Page 47: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

The installed WordPress Site

46

Page 48: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

XAMPP

XAMPP Available for all platforms http://www.apachefriends.org/en/xampp.html

Easy to install (not as easy as BitNami) More tends to go wrong during installs.

Mimics common server setups NOT production ready (security)

47

Page 49: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Installing XAMPP

Detailed install instructions are available for Windows, Mac and Linux at: http://www.apachefriends.org/en/xampp-windows.html http://www.apachefriends.org/en/xampp-macosx.html http://www.apachefriends.org/en/xampp-linux.html

There is also a version for memory sticks: http://www.apachefriends.org/en/xampp-windows.html#646

48

Page 50: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Manual WordPress install

If you don’t know how to install WordPress using the .zip copied from wordpress.org, you should learn. Most of the web server stacks do not include

WordPress. If you want more than one WordPress site on

BitNami you will also need to do WordPress installs.

See codex for help with a WordPress install: http://codex.wordpress.org/Installing_WordPress

49

Page 51: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

An additional note on scripted installs

A native install allows you to tweak settings like the table prefix, which you can’t with a scripted install (Fantastico, Simplescripts etc.). Installer applications: may add files to your site for “internal” tracking. may not install the latest version of WordPress. usually use default database settings for names and

table prefixes – security weakness.

50

Page 52: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Installing WordPress

The most complicated thing to installing WordPress is setting up the database. It’s not that hard. Lots of tutorials online. On hosted servers you can use GUI tools like

cPanel. On a local server you can use phpMyAdmin Hosted installs usually have the DB management in

phpMyAdmin disabled.

51

Page 53: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Managing databases

This is the cPanel Databases tool which will allow you to add/delete databases and database users.

52

Page 54: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

More installing WordPress

The other question is where to put the files? On local servers the htdocs folder is the default. But where is it? Depends on the install: apache/htdocs is a common default

BitNami default windows: C:\Program Files\BitNami WordPress

Stack\apache2\htdocs Note: the WordPress “module” we installed in the demo is

in a special location: C:\Program Files\BitNami WordPress Stack\apps.

Hosted servers: public_html

53

Page 55: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Localhost or 127.0.0.1

Default web servers setups will have your sites at: http://localhost/<some_name>/ http://127.0.0.1/<some_name>/

54

Page 56: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Localhost or 127.0.0.1

While this works most of the time: Some things can have issues with the localhost or

127.0.0.1 address as they expect a domain name. It’s not very nice for using as a set-up when you

have lots of sites. Wouldn’t http://dev.site.demo be nicer than

http://127.0.0.1/wordpress/? Or how about http://client_domain.local instead of

http://localhost/clent_domain/wordpress/?

55

Page 57: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Virtual hosts

Virtual host – vhosts are a web server feature that lets you set up nice names “virtual host names” for your websites. http://httpd.apache.org/docs/2.2/vhosts/

To get vhosts working you need to tell apache you want to use them. Find the apache/conf/ folder in your server install. Open the httpd.conf file. (use a plain-text or

programming editor)

56

Page 58: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Httpd.conf file

Find the line “# Virtual hosts” remove the “#” from the start of the line below.

Save the file. (You may need to alter permissions to be able to save it.)

57

to

Page 59: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Vhosts file

In the apache/conf/ folder you should also find the folder “extra” -> apache/conf/extra/ That is where you will find the file: httpd-vhosts.conf

Open that file.

Look for a line near the top like: NameVirtualHost *:80 Make sure there are no “#”s in-front of it.

58

Page 60: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Add a virtual host

For a default BitNami install (on Windows) paste this code after any other lines for bitnami.demo:

You may need to adjust the 2 occurrences of:

C:/Program Files/BitNami WordPress Stack/apache2/htdocs on other installs

59

<VirtualHost *:80> ServerName bitnami.demo DocumentRoot "C:/Program Files/BitNami WordPress Stack/apache2/htdocs" <Directory "C:/Program Files/BitNami WordPress Stack/apache2/htdocs"> Options Indexes FollowSymLinks Includes ExecCGI AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost>

Page 61: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Add another virtual host

And paste this code after that for dev.site.demo:

You may need to adjust the 2 occurrences of:

C:/Program Files/BitNami WordPress Stack/apps/wordpress/htdoc

60

<VirtualHost *:80> ServerName dev.site.demo DocumentRoot "C:/Program Files/BitNami WordPress Stack/apps/wordpress/htdocs" <Directory "C:/Program Files/BitNami WordPress Stack/apps/wordpress/htdocs"> Options Indexes FollowSymLinks Includes ExecCGI AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost>

Page 62: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Save and restart Apache

Save the vhosts file. (You may need to alter permissions to be able to save it.) You will need to restart Apache to get the settings to take effect.

61

Page 63: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Hosts files

To final step to make this work is to add the virtual host to the “hosts” files on your computer There is a chart on Wikipedia that provides

common host files locations (dependent on your operating system) http://en.wikipedia.org/wiki/Hosts_(file)

62

Page 64: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Hosts files

Open up the hosts file and add these 2 lines: Tells your computer that the 2 virtual hosts are on

your computer.

Save the hosts file. (You may need to alter permissions to be able to save it) 63

Page 65: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Sites on vhosts

64

Page 66: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Trick to avoid domain migration issues

Add the final name of the site to your hosts file:

Set up a vhost for “somesite.com” and now you can work locally with the final name! Easy migration BUT - blocks access to any real external site of that

name. I don’t use this technique as I want to access both

sites.

65

Page 67: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Migration review

We did a migration in our first example and there we saw that it is just a few steps:

1. Copy files. Local copy or FTP to another server, does not matter.

2. Copy the database. To move servers you will need to do an SQL dump/export

and then an import on the new server.

3. Clean-up a few things. Database user. Database settings in wp-config. URL’s - be aware of serialization.

That’s all there is to migration! 66

Page 68: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

MySQL export

To export the database to move to another server you can use the export function in phpMyAdmin.

67

Page 69: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

MySQL import

To import the database on another server you can use the import function in phpMyAdmin.

68

Page 70: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Backup scripts

Many of the backup and maintenance scripts: Backup Buddy, InfiniteWP, ManageWP, + many others

will do site migrations. Make sure any one you use mentions serialization.

69

Page 71: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Multisite migration quirks

Need to manually change the wp-config file. Look for the line: and update it to your new domain.

Unlike regular sites which will display, (just with bad links) with multisite, you will get a database error until you fix URL’s. (Use the script, note – you need to be aware of all the different site domains, particularly with sub-domain multisite installs, and you may not want to change all tables at once.)

70

define( 'DOMAIN_CURRENT_SITE', ‘somesite.com' );

Page 72: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Checking for ports in use

netstat (network statistics) A command-line tool that displays network

connections. http://en.wikipedia.org/wiki/Netstat

netstat –an Shows all active ports

netstat –anb Shows process names.

71

Page 73: Intro to development sites and site migration

© 2012 Rick Radko, r3df.com

Contact

Rick Radko email: [email protected] twitter: @r3designforge

Slides at: www.slideshare.net/r3df

72