Uploading wordpress

This is a very specific yet common case: for some reason, you have to use Wordpress for something that is not a blog (of course it was not on you), so you start making custom plugins,  shaping up a theme with custom functions and filters, and after a few tests and proper changes on wp-config.php you proceed to upload everything to your server… aaand nothing works.

A long ago, I had to figure it out myself and took me more than an hour, so I’m posting this step-by-step guide hoping to save you some time.

Assuming you are working in your local machine, in a subfolder like israelcruz.com/mylocalwp, and want to upload your files to a production server like myproductiondomain.com,  right this way:

  1. Dump database
    $ mysqldump -u root -p my_local_database -r db.dump
  2. Replace each occurrence of ‘israelcruz.com/mylocalwp’ or whatever your local installation folder is, to the production domain name in the dump file you just created:
    $ mkdir export
    $ sed -i 's/israelcruz.com\/mylocalwp/myproductiondomain.com/g' db.dump > remote_db.dump
  3. Import the new database file remote_db.dump in your production database server using phpMyadmin, or ssh:
    $ mysql -uroot -p --default-character-set=utf8 my_remote_database
    $  SOURCE remote_db.dump
  4. Modify wp-config.php to match your remote MySQL settings:

    /** The name of the database for WordPress */
    define('DB_NAME', 'my_remote_database');
    /** MySQL database username */
    define('DB_USER', 'my_remote_user');
    /** MySQL database password */
    define('DB_PASSWORD', 'my_remotepa55');
    /** MySQL hostname */
    define('DB_HOST', 'my_remote_host');

If you upload all your files it should work fine in your remote server, except for one thing; if you are using pretty URLs as in  myproductiondomain.com/my-post-name  you’ll get a 404 error when attempting to visit any page other than homepage, to fix it follow this final step:

  1. Modify .htaccess from this:
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /mylocalwp/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /mylocalwp/index.php [L]

    to this:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

This two lines in WordPress .htaccess are used by Apache’s mod_rewrite to handle custom URLs. If you are working in a local subfolder, you have to remove the subfolder name from them.