Oftentimes it makes sense to set up and develop your WordPress page locally and then move it to a remote server once everything works. This prevents downtime of the live page in case something goes wrong, makes development easier and is just good practice in general.

Here is a short description how to move WordPress from a local computer to the production server.

Exporting and Importing WordPress Database and changing the website url

# 1. Export Mysql Database on local computer:
mysqldump your_wordpress_database -u root -p > wordress_export.sql

# 2. Replace local url in database with production url:
sed -i 's/your-wordpress.local/your-domain.com/g' wordress_export.sql

# 3. Upload Wordpress_export.sql to webserver
# 3.1 Connect to server

# 4. import database on server
mysql your_wordpress_database -u root -p < wordress_export.sql

The interesting part is step two in which we changed all occurrences of the domain in the database. This has to be done when moving your WordPress site, but the same command can also be used in case you change your WordPress domain.

Creating the WordPress Database and User

If it is the first time moving the WordPress blog from development to production you have to create the database and user after step 4. first:

mysql -u root -p
CREATE USER 'your_wordpress_user'@'localhost' IDENTIFIED BY 'your_password';
create your_wordpress_database;
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER ON your_wordpress_database.* TO 'your_wordpress_user'@'localhost';
# (you can of course use stricter privileges, for example only SELECT,INSERT,UPDATE)

If you did not name the WordPress database the same on the remote server as on your local computer, you have to adjust the .sql file before loading it in the database.

Moving WordPress Installation Directory to the Server

If you customized your WordPress install you will not only want to move your database to the production server, but also the directory that holds your WordPress installation.

# 1. replace local url in files with production url:
find /your_wordpress_directory -type f -exec sed -i 's/your-wordpress.local/your-domain.com/g' {} \;
# this step is only neccessary if you actually hardcoded your url somewhere in the files. You shouldn't but in my experiences it happens anyway.

# 2. compress wordpress directory
tar -zcvf wp.tar.gz /var/www/your_wordpress_directory

# 3. Upload wp.tar.gz to webserver
# 3.1 Connect to server

# uncompress wp.tar.gz
tar -zxvf wp.tar.gz
# if you did not uncompress the directory to where you want it you can move it 

Edit the config.php in case your remote database user differs from your local user (which it should)

And that should be it. Remember to test your WordPress site thoroughly on the production server as it might differ from your local machine.

It should be noted that WordPress does not recommend doing it this way. Here is their way of moving WordPress to a new server. I like the way described above as it catches all: It will change all absolute internal links in posts and pages, all occurrences in the database and also all hardcoded urls you might have in your theme. It also works very well when moving multi-site wordpress installations. But you should always have a working backup of your wordpress installation, just in case something goes wrong.