Set up a production Wordpress project

If you are doing a Wordpress project, you are probably building a custom theme in your local environment. When the time comes, you need to transfer that to a production environment. Here is a list of steps you should do and check while doing that process.

Install Wordpress

First step is obvious: install Wordpress instance on your production. Some providers even give you a one-click installation of Wordpress. If that is not the case, you will have to do several small steps to install it.

You can do this by directly downloading it from wordpress.org. You will need a database and credentials for database user which will use that database.

You start with downloaded Wordpress archive which you should place somewhere on your server (if you are having a domain, place it in that directory, otherwise, public_html is good). Directory in which you place it is going to be your root folder and with it, your root url.

Let’s say we are launching our site on www.awesome-project.com and that that is an add-on domain for our server with it’s root in public_html/awesome-project.

You will need to extract contents from downloaded archive into that directory. Make sure that folders wp-content, wp-admin and wp-include are all in that directory (you might get everything extracted inside of a directory named wordpress — just move it one level up). After that, just go to the root url of your site (http://www.awesome-project.com).

Wordpress will detect that you don’t have it yet installed and it will start installation. You will need to enter some basic informations about your project (remember those database credentials? :) ).

After the installation, you are having one nice Hello world Wordpress set up.

Installing your theme

You have developed a theme and set up a Wordpress instance. You will need to upload and install your theme now.

Just compress your current theme folder (the one that is inside of wp-content/themes) into a ZIP archive and go to Appearance section in your wp-admin panel.

There, go to Add new and click Upload theme. Select your theme and that’s it.

After the installation, just activate your theme and start filling in the content.

Problems

If you have no dependant content or no dependencies on any plugins, you are done after two previous steps.

However, in a real world situation, this is rarely the case (except if you are building a generic theme).

Here are some most common problems and their solutions.

Data migration

You might have some data that you already entered while you were developing (like some page templates that have some custom fields).

There are 2 ways how you can migrate that into your production:

  1. Wordpress export/import
  2. Database override with uploads upload

You will sometime use one, sometime another. What is the main difference?

Wordpress export/import is core tool that handles data migrations. One thing it does is the creation of XML files with data that needs to be imported. Main problem it has is with media. It will ask you should it download files and you will say yes, but the problem lies within the fact that your production can’t see your local development, so it will get errors while trying to import those files.

You can find this under Tools section in wp-admin.

This approach is great if you have no or small amount of images with your posts. You can just go into wp-admin and attach freshly uploaded files to posts.

Database override with uploads upload is more advanced type of migration since it is touching database directly.

Here’s a list of things you need to do (and yes, in that order):

  1. Export your local database
  2. Clear your production database
  3. Import exported local database
  4. Go to wp_options table
  5. Update site_url to match your domain name
  6. Go to wp-admin -> Settings
  7. Change Home url to your domain name
  8. Save settings
  9. Go to wp-admin -> Settings -> Permalinks
  10. Update permalinks (this will flush them)
  11. Go to wp-admin -> Users
  12. Change your local password to something more secure
  13. Upload wp-content -> uploads from your local environment to the production (use some FTP tool like Filezilla).

This is basic stuff. If you are having any type of content linking inside your posts (images in content, references to other posts, etc.) you need to change that also.

Here’s a simple query to replace your local environment domain with your production:

UPDATE wp_posts
SET post_content = REPLACE(post_content, 'www.domain.loc', 'www.awesome-project.com')

You can run this also over other columns in other tables where you might have some some linked content (wp_postmeta/meta_value, etc.).

BEFORE DOING ANY OF THIS, PLEASE, MAKE A BACKUP OF YOUR PRODUCTION DATABASE!

This is so important that I will write it again.

BEFORE DOING ANY OF THIS, PLEASE, MAKE A BACKUP OF YOUR PRODUCTION DATABASE!

Good, next problem.

Plugin dependencies

This is a really nasty one. You are using some plugin and it’s methods, like Advanced Custom Fields. But, you don’t have that plugin. And you are referencing it directly from your functions.php which is always loaded when your theme is active.

This will leave you with a white screen of death. You will get no errors out (since WP_DEBUG is turned off). You will not be able to access your wp-admin to install the plugin. As a normal user/admin, you are just locked out of everything.

Luckily, we are developers and we know how to do something about this.

There are several ways you can fix this, and all of them require some type of file access (meaning, if you are launching a project on someone else’s environment and they didn’t give you any access, you are screwed).

First solution is to upload needed plugins directly to wp-content/plugins folder. If it isn’t there, just create it. When you cover all your missing plugins, site should* continue to work properly.
 *I don’t know if there are some more bugs, but we are currently talking about plugin dependencies 🙃.

Other approach is to change wp_options value current_theme to some other installed theme (how about twenty-seventeen?). This will turn off your current theme and you can access wp-admin to install everything you need.

You can always prevent this in advance. Install plugins before uploading a theme, or, even better, check for dependencies. Don’t break everything if you are missing one component. Better write out a reason why are you missing it.

And that’s it. There are not so many cases that need to be covered while launching a site to new environment. If you had any problems or you know some more cases that weren’t listed above, let me know, we will expand this. 😀

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.