You move WordPress from a subdomain to the main domain on the same cPanel account by copying the site into the main domain’s folder, with a separate database for the copy. The source subdomain stays untouched. In this procedure you do not change MX records, DNS or email mailboxes, and you do not delete the subdomain or the main domain.
If the site is Multisite, has an active store, or you do not know how it is set up, do not improvise: agree the procedure with the person who maintains it.
Step 1: Find the subdomain folder and the main domain folder
Log in to cPanel as described in How to log in to cPanel and on the “Alati” (Tools) page open “Domeni” (Domains). The row “Glavni domen” (Main domain) has a link to the main domain’s directory. Write down the path shown in that row. Take the subdomain’s path from its own row on the same page. If you cannot find it there, do not assume a path and do not continue until you have established it.
Also look at what is already in the main domain’s folder. If the main domain does not open on this hosting, sort that out first by following How to connect a domain to hosting. You do not change DNS here. Also check whether the subdomain’s folder is inside the main domain’s folder, because that changes step 5.
Step 2: Make separate backups
Make two separate backups, each in its own folder, and keep them outside all public folders, which means outside both folders from step 1 and outside anything that opens in a browser. Do not mix files from different backups.
- The source (subdomain). A copy of its files, as described in How to make a backup of your site, and an export of its database to an SQL file from phpMyAdmin, as described in How to access a database (phpMyAdmin). The database name is in
wp-config.php, in the lineDB_NAME. - The existing main site. A copy of all the files in the main domain’s folder and an export of its database, if the site uses one. If the folder holds only a start page, save that too.
- Copies in JetBackup. “Restore & Download” shows the copies and their date in the “Created” column. This is an addition, not a replacement for the copies above.
Do not leave SQL files in a public folder. Also write down the source’s “WordPress Address (URL)” and “Site Address (URL)” from “Settings” → “General”, and the lines WP_HOME and WP_SITEURL in wp-config.php, if they exist.
Step 3: Create a separate database and user for the copy
The copy must not share a database with the source subdomain: if it did, changing the address or rolling back would change the source too. So in cPanel, on the “Alati” (Tools) page, open “Database Wizard”. The first step of the wizard is “Korak 1: Kreirajte bazu” (Step 1: Create a database). Follow the remaining steps, including the database user and its access to the database, in the cPanel documentation. Give the user access to the new database only.
Then export the source database again, right before the import, so the copy is fresh. Changes made on the source after that export will not be in the copy. Import the export into the new database in phpMyAdmin, on the “Import” tab. You open phpMyAdmin and choose the database as in How to access a database (phpMyAdmin), and at import check that the new database is selected, not the source one.
Do not send the new database name, user and password in a ticket, do not put them in a screenshot, and do not write them anywhere except the working copy’s wp-config.php.
Step 4: Check the main domain’s HTTPS before the move
In cPanel open “SSL/TLS Certificates” → “Status” and look at the rows of the main domain, the base name and www, as described in How to check your SSL certificate (HTTPS). Then open both names in a browser at an address that starts with https:// and compare with the panel. If they disagree or a warning appears, do not continue with the move until you have sorted it out following that guide. Do not click past the warning.
Step 5: Prepare a complete working copy outside the public folders
Do not configure anything in the main domain’s folder: while files with an unconfigured wp-config.php sit there, someone else’s request can open them. Prepare everything in a separate folder outside all document roots, that is, outside the folders of the main domain, the subdomain and any other site.
- Before copying, establish what belongs to which site. If the subdomain’s folder is inside the main domain’s folder, or the files are mixed, check file by file what is whose. If it is not clear, do not continue and agree the procedure with the person who maintains the site. Do not touch system folders such as
.well-known, or the files of other sites. - Copy, do not move, all of the subdomain’s WordPress files into the separate folder, including hidden files such as
.htaccess. You open the File Manager and check the folder path as in How to upload files (FTP or File Manager), but that guide covers opening a folder and uploading, not copying. If you cannot see hidden files, turn on showing them in the File Manager settings. The original stays on the subdomain, and you do not change itswp-config.php. - In the working copy’s
wp-config.phpenter the details of the new database from step 3:DB_NAME,DB_USERandDB_PASSWORD, andDB_HOSTonly if it differs for the new database from what is already there. Do not disclose the details to anyone. - In the same file set
WP_HOMEandWP_SITEURLto the main domain’s address, the way the WordPress documentation describes. If those lines already exist, replace their values rather than adding the same lines again. The database still holds the old subdomain address, so without this the site would lead to it. - The copy uses the space of your plan. If the account is close to its limit, copying can fail.
Step 6: Put the prepared files in place at the agreed time
- At the agreed time, move only the files of the old main site out of the main domain’s folder, outside the public folders; you already saved them in step 2. Leave system folders such as
.well-known, other sites and the subdomain’s folder, if it is inside, where they are. Do not mix old and new files. - Right after that, put the prepared files from the working copy from step 5 into the main domain’s folder. Do not delete the working copy until the checks are done.
- Log in to the admin at the new address.
Do not change the addresses in the content with a raw SQL replace in phpMyAdmin: WordPress stores part of its data with the length of the text recorded, so such a replace can break it. The same documentation lists tools that do it correctly, such as WP-CLI and plugins for replacing addresses. If you do not have such a tool, agree the procedure with the person who maintains the site before any change to the database.
If pages other than the home page give an error, check whether .htaccess was put in place.
Step 7: Check after the move, each one separately
- HTTPS, again. In cPanel look at “SSL/TLS Certificates” → “Status” for the main domain, the base name and www, then open both names at an address that starts with https:// and compare with the panel. Do not click past a warning.
- The site. Open the home page, a few inner pages with images and the admin, and check the address in the browser.
- Sending and receiving email. Send a test message from an independent address to an address on your domain and back, and check receiving in webmail, as described in How to set up email in Outlook or Gmail. You do not change MX in this procedure. If MX was changed anyway, read Not receiving email after changing MX records.
- The contact form. Send a test message through the form and check that it reaches the form’s recipient. Check the form separately from email, because the site itself sends the message.
If something does not work
You restore only the previous state of the main site: move the new files out of the main domain’s folder, outside the public folders, and put back the main site’s files from its backup from step 2, without touching system folders, other sites or the subdomain. Its database was not changed. You do not overwrite the source database or import anything into it, and the subdomain stays as it was. Do not delete the copy’s new database until you have checked you do not need it.
Watch for orders, comments and messages that arrived after the move: they are only in the new database and will not be visible on the old main site. Before rolling back, save an export of the new database and agree the procedure with the person who maintains the site.
Do not delete the subdomain or the main domain in cPanel. If that does not help, open a ticket and include the names of the main domain and the subdomain, the time with the time zone, the exact text of the error or a screenshot without passwords, and the step where you stopped. Do not send passwords, database details or the content of the SQL file.