If you have migrated a Drupal site from local development server to a live server or from one host to another host, you will generally encounter a 404 error when accessing the pages after migration. Do not freak out, this is pretty normal and can be resolved easily. Let's go through what I did so far to migrate from one host to another.
Process of migrating a Drupal Site from one host to another host:
On the old server:
- Preparation on the website
- Logged in as Admin
- Disabled clean URLs (Administration » Configuration » Search and metadata )
- Flushed all cache
- Backup Site Files
- Logged in to the old host account
- Accessed File Manager (Cpanel)
- Right-clicked on public_html and compress (created a zip file- public_html.zip)
- rename the public_html.zip to sitebackup.zip
- Downloaded the sitebackup.zip file
- Backup the database
- From the Cpanel, accessed "phpMyAdmin"
- Exported the database
- If you want you can also download and backup email accounts, email forwarders etc. Refer to backup section in Cpanel
On the New Server
- Restore the Drupal Site files
- Logged in to the old host account
- Accessed File Manager (Cpanel)
- Opened public_html
- Uploaded the sitebackup.zip file from the old server
- Extracted sitebackup.zip file (a folder is created by the name of the zip file i.e. sitebackup)
- Opened sitebackup folder
- Copied all contents from sitebackup folder and moved to public_html folder
- Deleted sitebackup folder
- Creating a new database
- Accessed Cpanel > MySqlDatabases
- Created a new database. (Noted the name of the database)
- Created a new user for the new database created and set password (noted the username and the password)
- Restoring the database
- Accessed Cpanel > phpMyAdmin
- Clicked on the new database
- Imported the database file from old server to this one
- Changing Settings.php
- Accessed Cpanel > File Manager
- Navigated to the folder "public_html/sites/default/" and downloaded a copy of settings.php. Then deleted the existing setting.php copy under "public_html/sites/default/"
- Edited the downloaded settings.php file - edited database properties in settings.php with the new database name, database username and password
- Uploaded the edited setting.php file to "public_html/sites/default/"
- Opened the site in a browser. Home page displayed. But on clicking the other links, "404 error" encountered.
- Attempted to login site.com/?=user but the recaptcha not displaying.So unable to login. (You can also enable "$update_free_access = TRUE;" in settings.php to run update.php. But I didn't do that.
- Checked "public_html" and there is no .htaccess file
- Extracted the sitebackup.zip again. The progress log of extracting shows .htaccess file being extracted. But .htaccess file is not found in the extract sitebackup folder.
- On the local computer, extracted the sitebackup.zip file which was downloaded to my computer earlier.
- Uploaded the .htaccess to public_html but the file is still not visible.
- On the local computer, renamed .htaccess to htaccess (without the dot)
- Uploaded htaccess (without the dot) to public_html
- Renames htaccess to .htaccess
- On the browser, opened the website.
- Bingo! Site is working now