{"id":6936,"date":"2022-11-26T18:24:42","date_gmt":"2022-11-26T12:54:42","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=6936"},"modified":"2022-11-26T18:24:47","modified_gmt":"2022-11-26T12:54:47","slug":"how-to-do-wordpress-website-migration-from-domain-to-subdomain","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/how-to-do-wordpress-website-migration-from-domain-to-subdomain\/","title":{"rendered":"How to do WordPress website migration from domain to subdomain"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Introduction<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this article, we will&nbsp;migrate the WordPress website from the source domain to the subdomain.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Prerequisite<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Server with credentials are needed<\/li>\n\n\n\n<li>Root user or sudo access for the server is essential<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Procedure<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><strong>Step 1:<\/strong> <\/strong>Login into the source domain server and find the document root on the domain configuration file(depends on the webserver installed on server).<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background wp-block-paragraph\">$ sudo cd \/etc\/&lt;webserver&gt;\/sites-available\/domain.conf<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 2:<\/strong> Go to the document root path and take the backup<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background wp-block-paragraph\">$ sudo tar -zcvf wordpress.tar.gz \/home\/domain\/public_html<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 3:<\/strong> Now take backup of the database using mysqldump command.<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background wp-block-paragraph\">$ sudo mysqldump databasename &gt; databasename.sql<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 4:<\/strong> Copy both the backup files to the destination server using SCP command.<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background wp-block-paragraph\">$ sudo scp \/root\/wordpress.tar.gz user@ip:\/root<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background wp-block-paragraph\">$ scp \/root\/databasename.sql user@ip:\/root<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 5:<\/strong> Login to destination server<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create the subdomain configuration file for virtualhost entry using the following command<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background wp-block-paragraph\">$ sudo vim subdomain.com.conf<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Add the below contents accordingly with respect to your subdomain name,<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-background-color has-background\"><code>&lt;VirtualHost *:80&gt;\nServerName sub.domain.com\nServerAlias www.sub.domain.com\nDocumentRoot \/home\/subdomain\/public_html\nErrorLog ${APACHE_LOG_DIR}\/error.log\nCustomLog ${APACHE_LOG_DIR}\/access.log combined\n&lt;\/VirtualHost&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 6:<\/strong> Verify the configuration file syntax using the below command<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background wp-block-paragraph\">$ sudo apachectl configtest<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If the webserver is ngnix then run the following command.<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background wp-block-paragraph\">$ sudo systemctl config nginx<\/p>\n\n\n\n<p class=\"has-black-color has-white-background-color has-text-color has-background wp-block-paragraph\">If there are no syntax errors, then restart the webserver<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background wp-block-paragraph\">$ sudo systemctl restart &lt;webserver&gt;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 7:<\/strong> Lets create the database and the user<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Enter into the MySQL database<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background wp-block-paragraph\">$ sudo mysql<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Run the following queries,<\/p>\n\n\n\n<pre class=\"wp-block-code has-black-color has-white-background-color has-text-color has-background\"><code>&gt; CREATE DATABASE &lt;db_name&gt;;\n&gt; GRANT ALL PRIVILEGES ON db_name.* TO '&lt;db_user&gt;'@'localhost' IDENTIFIED BY 'xxxxxx';\n&gt; FLUSH PRIVILEGES;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 8:<\/strong> Restore backup files to the subdomain document root<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background wp-block-paragraph\">$ sudo cd \/root<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background wp-block-paragraph\">$ sudo tar -xvzf wordpress.tar.gz \/home\/subdomain\/public_html\/<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now restore the mysql database<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background wp-block-paragraph\">$ sudo mysql db_name &lt; databasename.sql<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 9:<\/strong> Modify the wordpress configuration file with the new database details<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Enter into the document root using the below command,<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background wp-block-paragraph\">$ sudo cd \/home\/subdomain\/public_html\/<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">And run the following command edit wordpress configuration file .<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background wp-block-paragraph\">$ sudo vim wp-config.php<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Modify the file with a your database name and user<\/p>\n\n\n\n<pre class=\"wp-block-code has-black-color has-white-background-color has-text-color has-background\"><code>\/** The name of the database for WordPress *\/\ndefine('DB_NAME', 'db_name');\n\n\/** MySQL database username *\/\ndefine('DB_USER', 'db_user\n\n\/** MySQL database password *\/\ndefine('DB_PASSWORD', 'xxxxxx');\n\n\/** MySQL hostname *\/\ndefine('DB_HOST', 'localhost');<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 10:<\/strong> Change the siteurls in the database from http:\/\/domain.com to http:\/\/sub.domain.com.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Run the queries to change the siteurls,<\/p>\n\n\n\n<pre class=\"wp-block-code has-black-color has-white-background-color has-text-color has-background\"><code>&gt; UPDATE wp_options SET option_value = replace(option_value, 'http:\/\/domain.com', 'http:\/\/sub.domain.com') WHERE option_name = 'home' OR option_name = 'siteurl';\n\n&gt; UPDATE tmp6d400b_posts SET guid = replace(guid, 'http:\/\/domain.com', 'http:\/\/sub.domain.com');\n\n&gt; UPDATE tmp6d400b_posts SET post_content = replace(post_content, 'http:\/\/domain.com', 'http:\/\/sub.domain.com');\n\n&gt; UPDATE wp_postmeta SET meta_value = replace(meta_value,'http:\/\/domain.com', 'http:\/\/sub.domain.com');<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 11:<\/strong> Make sure you have the .htaccess file placed under the document root<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If there is no htaccess file in document root, add a default configuration.<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background wp-block-paragraph\">$ sudo vim .htaccess<\/p>\n\n\n\n<pre class=\"wp-block-code has-black-color has-white-background-color has-text-color has-background\"><code># BEGIN WordPress\n&lt;IfModule mod_rewrite.c&gt;\nRewriteEngine On\nRewriteBase \/\nRewriteRule ^index\\.php$ - &#091;L]\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteCond %{REQUEST_FILENAME} !-d\nRewriteRule . \/index.php &#091;L]\n&lt;\/IfModule&gt;\n# END WordPress<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now you can access the website http:\/\/sub.domain.com on browser.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Conclusion:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The migration from the source domain to the subdomain has successfully done by following all these steps.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction In this article, we will&nbsp;migrate the WordPress website from the source domain to the subdomain. Prerequisite Procedure Step 1: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1019],"tags":[],"class_list":["post-6936","post","type-post","status-publish","format-standard","hentry","category-cloud-aws","psol-cat-cloud-aws"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-1NS","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/6936","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=6936"}],"version-history":[{"count":0,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/6936\/revisions"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=6936"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=6936"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=6936"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}