There are many ways in which you can migrate your WordPress site from MAMP into its final home, to make it “live”. The way I’m going to show, has worked well for beginners.
What you will need:
- Access to the cPanel (or similar) on your server
- Migrate DB plugin (or similar) in your local installation
- FTP access to the server, or a way to upload files to your server (in cPanel>Files>File Manager)
To achieve the move, we’ll need to follow these steps:
- Export your local database
- Create a database and user in the server
- Import your local database into the server’s database
- Move all your files from your local folder to the server
- Modify wp-config.php to link WordPress to the new database
- Refresh your permalinks
Step 1: Export Your Local Database
To export your local database, install in the Migrate DB plugin (you can search for it in Plugins>Add New and install normally). Once installed, and activated, go to Tools>Migrate DB.
What this plugin does is not just export the database, but it also replaces in your database all the URLs, so instead of pointing to something like http://localhost:8888/my-site, they’ll point to http://www.my-site.com.
On the first field, enter the new URL of your site. If it’s in a subfolder, enter that subfolder’s name as well in both paths. As for the second field, the local path, you can find that in cPanel, in the left-side column, under WWW Directory:
So, after entering both paths, it should look something like this (in this case, I’m installing in the root directory):
Notice how the “http:” is missing from the first address, but you do need the two slashes (“//”), and there is not trailing slash on either address.
You can compress the file with gzip if you like, but if your site is not too large, you don’t need to. We are going to uncompress the file later, anyway.
Click the “Migrate” button, and save the file it generates somewhere handy. We’ll use it later.
Step 2: Create a Database and User in the Server
In cPanel, go to Databases>MySQL Database Wizard. It has 3 steps:
Enter a name for your database. It must be at most 16 characters (including the prefix your host will assign to you). Make it hard to guess for added safety.
The next step is to add a user for that database. This user will be just for the database, and nothing else. Also make it hard to guess, and at most 16 characters. I recommend using the password generator (just make sure to paste it in a file so you don’t lose it, we’ll be copying and pasting other things on the next step).
Finally, grant all permissions to the user you made, to the database.
Step 3: Import Your Database
In cPanel, go to Databases>phpMyAdmin, and click on the left-hand side on the database you just created.
Open the file generated by Migrate DB in a text editor (whichever you use to create web pages), and copy all its contents into the text area in the SQL tab in phpMyAdmin, and click Go.
It may look like nothing happened, but if you click on Structure, you should be able to see all your WordPress tables.
Step 4: Move all your files
If you know how to FTP, simply upload all the files to your server.
If you don’t, you should learn, but you can always use the file uploader in cPanel (Files>File Manager).
In the File Manager, go to your Web Root. If you are installing in a sub-folder, navigate to that folder.
In you local computer, navigate to the folder with all the files in your WordPress installation (MAMP), select them and compress them. In Mac, select all the files, right-click and choose “Compress Items”. In PC, select all the files, right-click and choose Send to…>Compressed (Zipped) Folder. This will generate a file with the ZIP extension.
In the file manager, click “Upload”, and browse until you find your ZIP file. Once the upload is done, click the back to home button. You should see the ZIP file in your folder, select it, and click “Extract”. If you don’t see your files right away, click the “Reload” button.
If you want, once you see all your files, you can delete the ZIP.
Step 5: Modify wp-config.php
In the File Manager (or via FTP), click on wp-config.php, and then “Code Editor” in the top navigation.
Change the following code (around line 18):
/** The name of the database for WordPress */
/** MySQL database username */
/** MySQL database password */
/** MySQL hostname */
This is the information from step 2. The hostname is usually localhost, but if you have issues with it, you may have to contact your host, or check their knowledge base.
Step 5: Refresh Your Permalinks
Your site should be up and running!
If your links aren’t working, login to the Dashboard (on the “live” site), then go to Settings>Permalinks, and click the “Save” button. You don’t have to make changes, just clicking the button fixes things.
Common mistakes are:
- Uploading the files to the wrong folder. The files must be directly in the folder you specified on Migrate DB. Unless you said it was going to be in a sub-folder, all the files should sit directly in the root (public_html).
- Entering the wrong database, username and password in wp-config.php. Although localhost is probably ok, make sure you enter the other 3 values.
- Wrong URL in Migrate DB. Open the file generated by Migrate DB, and do a search for the URL, and make sure the URLs are accurate. If you made a mistake, in Structure, select all the tables, and then “Witch Selected” choose “Drop”, and start over (repeat steps 1 and 3).
- Some images are broken. If only a few images are broken, like your logo, or in widgets, you may need to manually change those. While Migrate DB will fix most URLs, it won’t make changes to paths hardcoded in your theme, widget content, among others. If your theme was done properly, you shouldn’t have to do too many of these.