{"id":10391,"date":"2019-06-06T17:17:16","date_gmt":"2019-06-06T17:17:16","guid":{"rendered":"https:\/\/www.mageworx.com\/blog\/?p=10391"},"modified":"2022-05-16T11:58:19","modified_gmt":"2022-05-16T11:58:19","slug":"how-to-transfer-magento-2-site-from-localhost-to-server","status":"publish","type":"post","link":"https:\/\/www.mageworx.com\/blog\/how-to-transfer-magento-2-site-from-localhost-to-server","title":{"rendered":"How to Transfer Magento 2 Site from Localhost to Server?"},"content":{"rendered":"\n<!-- SEO Ultimate (http:\/\/www.seodesignsolutions.com\/wordpress-seo\/) - Code Inserter module -->\n<!-- Google Tag Manager (noscript) -->\r\n<noscript><iframe src=\"https:\/\/www.googletagmanager.com\/ns.html?id=GTM-5DTCW7B8\"\r\nheight=\"0\" width=\"0\" style=\"display:none;visibility:hidden\"><\/iframe><\/noscript>\r\n<!-- End Google Tag Manager (noscript) -->\n<!-- \/SEO Ultimate -->\n\n<span class=\"span-reading-time rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\">Reading Time: <\/span> <span class=\"rt-time\"> 11<\/span> <span class=\"rt-label rt-postfix\">minutes<\/span><\/span>\n<p>The process of transferring a Magento 2-based site from one local host to another one is not a time-consuming process. However, it has a number of nitty-gritty details &amp; special aspects that should be taken into consideration before plunging into the process.<\/p>\n\n\n\n<p>In this blog post, we will make transferring a Magento 2 site from localhost to server as easy as Lego. Let\u2019s have an insight.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Main Steps<\/strong><\/h2>\n\n\n\n<p>To begin with, let\u2019s take a look at the main steps of transferring:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Magento 2 site sanity check on the current host (A);<\/li><li>Getting the remote host ready (B);<\/li><li>Remote host check (B);<\/li><li>Getting data ready for transfer; 4.1. File dump; 4.2. Database dump;<\/li><li>Data transfer;<\/li><li>Data unpacking; 6.1. Files unpacking; 6.2. Import of databases;<\/li><li>Access data correction on the remote host (B);<\/li><li>Correction of access permissions to files and directories;<\/li><li>Standard procedures before launching Magento;<\/li><li>Magento performance checks on the remote host (B);<\/li><li>Solution of frequent issues.<\/li><\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Easy as Lego: Step-by-Step Guidelines<\/strong><br><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. Magento 2 site sanity check on the current host<\/h3>\n\n\n\n<p>All is easy here: run and check. Usually, an order (full cycle) should be created for such purposes. Then check:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li> search; <\/li><li> product pages,<\/li><li>  categories, <\/li><li> customer\u2019s account. <\/li><\/ul>\n\n\n\n<p>This is an important stage as it allows you to steer clear from wrestling with questions regarding when exactly something has stopped operating after moving to a new host. Also, this will save you from the necessity to deal with the basic host issues that can be resolved in advance (A).<\/p>\n\n\n\n<p>I encourage you NOT to transfer a <em>by halves <\/em>operating Magento without any urgent need. It is much easier to deal with all issues on the current host (A) before starting the process of transferring. Proved and tested \u2015 this will save you both time and the pain in the neck.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. Getting the remote host (B) ready <br><\/h3>\n\n\n\n<p>The server, on which the Magento copy is deployed, must meet the minimum requirements for your Magento version.<br><\/p>\n\n\n\n<p>Study the official documentation to find out more about those requirements: <a href=\"https:\/\/devdocs.magento.com\/guides\/v2.3\/install-gde\/system-requirements-tech.html\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">https:\/\/devdocs.magento.com\/guides\/v2.3\/install-gde\/system-requirements-tech.html<\/a><br><\/p>\n\n\n\n<p>The environment must be set up before proceeding to the next steps of the transferring process (web-server with a virtual host, PHP, database).<br><\/p>\n\n\n\n<p>Unfortunately, the configuration of each separate part is beyond the pale of this article. However, you can easily find the required additional information on the web. So, it should be of no difficulty.<br><\/p>\n\n\n\n<p>I recommend paying special attention to the presence of the required PHP extensions.<br><\/p>\n\n\n\n<p class=\"has-text-align-center\"><em><strong>Should you have any questions on any step of this tutorial, please leave a comment. I\u2019ll do my best to answer all of them.<\/strong><\/em><br><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. Remote host check (B)<br><\/h3>\n\n\n\n<p>Before transferring Magento, make sure it works on the new host and the host itself operates properly. First, check that the web-server responds at the stated address (we assume that the host has been already configured).<br><\/p>\n\n\n\n<p>In my example, I use the standard path that is available right after Apache2 on the Linux server was installed: &nbsp;<br><\/p>\n\n\n\n<p class=\"has-text-color\" style=\"color:#3e0dde\">&gt; \/var\/www\/html<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo -u apache echo \"&lt;?php phpinfo();?&gt;\" &gt; \/var\/www\/html\/index.php<\/code><\/pre>\n\n\n\n<p class=\"has-vivid-cyan-blue-color has-text-color\">*Here and further, the commands will be run from the corresponding users if required. If the command is run without a username, then command execution should be meant as from the current user and the availability of any corresponding permissions.  &nbsp; <\/p>\n\n\n\n<p>If no errors appear after running this command, then it all went well and your file `index.php` must be available at the following address: {host}\/index.php. The result in your browser should look about like this (though much still depends on your PHP version): &nbsp; <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"982\" height=\"818\" src=\"https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/1-1.png\" alt=\"How to Transfer Magento 2 Site from Localhost to Server? | MageWorx Magento Blog\" class=\"wp-image-10398\" srcset=\"https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/1-1.png 982w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/1-1-600x500.png 600w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/1-1-768x640.png 768w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/1-1-250x208.png 250w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/1-1-696x580.png 696w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/1-1-504x420.png 504w\" sizes=\"auto, (max-width: 982px) 100vw, 982px\" \/><\/figure><\/div>\n\n\n\n<p>If something went wrong and you do not see info about your PHP version, please address a corresponding guide on the configuration of a web-server you need.<\/p>\n\n\n\n<p>Also, I recommend studying the logs in advance \u2015 this will save a bunch of your time.<\/p>\n\n\n\n<p>Next, check that the database service has been launched and operates properly:<br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql -u root -p<\/code><\/pre>\n\n\n\n<p>As a result, you should successfully connect to MySQL. Use the `exit` command to exit.<\/p>\n\n\n\n<p class=\"has-vivid-cyan-blue-color has-text-color\">* Enter login and password you used when setting up MySQL.<\/p>\n\n\n\n<p>Further, after connecting to MySQL successfully, you\u2019d need to check the existing databases. &nbsp;&nbsp;&nbsp;<br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SHOW databases;<\/code><\/pre>\n\n\n\n<p>Names of the databases that you are planning to transfer must not be the same as the ones that already exist on the new server. In case there are similar databases, this problem should be solved manually by deleting an existing but not used database, for instance, or by renaming a Magento database you intend to transfer. Note that you must necessarily enter the changed name in the configuration file of the Magento environment `app\/etc\/env.php`.<\/p>\n\n\n\n<p>Your result should look about as follows:<br><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"736\" height=\"381\" src=\"https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/2.png\" alt=\"How to Transfer Magento 2 Site from Localhost to Server? | MageWorx Magento Blog\" class=\"wp-image-10399\" srcset=\"https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/2.png 736w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/2-600x311.png 600w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/2-250x129.png 250w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/2-696x360.png 696w\" sizes=\"auto, (max-width: 736px) 100vw, 736px\" \/><\/figure><\/div>\n\n\n\n<p>Also, you\u2019d need to check that the service itself has been launched and listens to the standard port using the <em>netstat<\/em> utility: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>netstat -vulntp | grep -i mysql<\/code><\/pre>\n\n\n\n<p>Your result will look about as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt; tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      3366\/mysqld<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">4. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Getting data ready for transfer<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">4.1. File dump<\/h4>\n\n\n\n<p>Before creating a file dump, I strongly encourage you to take all unnecessary files away from the Magento directory, if there are ones, i.e., old dumps, cache, logs, etc. <br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rm -rf var\/cache\/* var\/page_cache\/* var\/generation\/* var\/composer_home\/cache\/* var\/log\/* pub\/static\/*<\/code><\/pre>\n\n\n\n<p>This will allow you to shorten the process. Besides saving you from transferring unnecessary files, you will avoid using server space without any particular need.<\/p>\n\n\n\n<p class=\"has-vivid-cyan-blue-color has-text-color\">*Do NOT forcibly delete `.htaccess` and other hidden files, if you use Apache2 web-server (the `rf` command doesn\u2019t delete them by default). These files are required for correct Magento operation.<br><\/p>\n\n\n\n<p>Now, go to the directory where our Magento is in the local server (A). In my example, it is:<br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt; \/Users\/sergei\/PhpstormProjects<\/code><\/pre>\n\n\n\n<p>The directory with Magento is named under <code> aws-botapi<\/code>. <br><\/p>\n\n\n\n<p>Let\u2019s create an archive for its further transfer to the remote host (B):<br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tar -zcf aws-botapi.tar.gz aws-botapi<\/code><\/pre>\n\n\n\n<p>You should check that the archive has been created:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ls -la aws-botapi.tar.gz<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">4.2. Databases dump<br><\/h4>\n\n\n\n<p>If there are several separate databases that are arranged locally on your Magento site, then all of them must be transferred. In my example, two databases are used. You can find them in the configurations of the Magento environment `app\/etc\/env.php` in the `db =&gt; connection =&gt; ` section. <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"456\" height=\"658\" src=\"https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/3.png\" alt=\"How to Transfer Magento 2 Site from Localhost to Server? | MageWorx Magento Blog\" class=\"wp-image-10402\" srcset=\"https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/3.png 456w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/3-416x600.png 416w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/3-250x361.png 250w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/3-291x420.png 291w\" sizes=\"auto, (max-width: 456px) 100vw, 456px\" \/><\/figure><\/div>\n\n\n\n<p>Now, dump all the databases:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysqldump -u root -p db1 | gzip &gt; .\/db1.sql.gz\nmysqldump -u root -p db2 | gzip &gt; .\/db2.sql.gz\n<\/code><\/pre>\n\n\n\n<p class=\"has-vivid-cyan-blue-color has-text-color\">*Use such info as database username and database name.<br><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Data transfer<\/h3>\n\n\n\n<p>Transfer Magento files dump using the `scp` utility (copying via ssh) or use any other means at your convenience (for example, copying via `ftp`): <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>scp -i ~\/.ssh\/myprivatekey.pem aws-botapi.tar.gz ec2-user@52.12.187.98:\/home\/ec2-user<\/code><\/pre>\n\n\n\n<p>Where,<br><\/p>\n\n\n\n<p>a) &nbsp;-i ~\/.ssh\/myprivatekey.pem is the path to the private key for connection (ignore this if you use solely password);<\/p>\n\n\n\n<p>b) ec2-user is the username for connection;<\/p>\n\n\n\n<p>c) 52.12.187.98 is the server address;<\/p>\n\n\n\n<p>d)<strong> \/home\/ec2-user <\/strong>is the absolute path on the server, to where we copy the files.<br><\/p>\n\n\n\n<p class=\"has-vivid-cyan-blue-color has-text-color\">*If you use a port that is different from the standard one, do not forget to identify it using a separate parameter (for example, `-P 6000` for &nbsp;6000 port).<br><\/p>\n\n\n\n<p>After copying is completed, you will see a line of the kind:<br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt; aws-botapi.tar.gz                                             100%  312MB   4.3MB\/s   01:11 <\/code><\/pre>\n\n\n\n<p>Repeat the same actions for files dump:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>scp -i ~\/.ssh\/myprivatekey.pem db1.sql.gz ec2-user@52.12.187.98:\/home\/ec2-user\nscp -i ~\/.ssh\/myprivatekey.pem db2.sql.gz ec2-user@52.12.187.98:\/home\/ec2-user\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">6. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Data unpacking<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">6.1. Files unpacking<\/h4>\n\n\n\n<p>On the server (B), let\u2019s navigate to the directory, which we copied the archives to. Let\u2019s unpack the Magento files to the directory of the local host:<br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt; tar -zxf aws-botapi.tar.gz -C \/var\/www\/html\/<\/code><\/pre>\n\n\n\n<p>Make sure to check that the files have been unpacked correctly:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ls -la \/var\/www\/html<\/code><\/pre>\n\n\n\n<p>If the Magento files have been unpacked to the sub-directory, transfer them using either `mv` or `cp` commands. <\/p>\n\n\n\n<h4 class=\"wp-block-heading\">6.2. Import of databases<\/h4>\n\n\n\n<p>Connect to MySQL on the server (B):<br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql -u root -p<\/code><\/pre>\n\n\n\n<p>Now, let\u2019s create a new database:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE DATABASE IF NOT EXISTS db1 CHARACTER SET utf8 COLLATE utf8_general_ci;<\/code><\/pre>\n\n\n\n<p class=\"has-vivid-cyan-blue-color has-text-color\">*The result should look about like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt; Query OK, 1 row affected (0.01 sec)<\/code><\/pre>\n\n\n\n<p>Make the similar actions in case you\u2019ve got other databases.<br><\/p>\n\n\n\n<p>Then, import databases from the dump:<br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gunzip &lt; \/home\/ec2-user\/db1.sql.gz | mysql -u root -p db1\ngunzip &lt; \/home\/ec2-user\/db2.sql.gz | mysql -u root -p db2\n<\/code><\/pre>\n\n\n\n<p>Connect to MySQL:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql -u root -p<\/code><\/pre>\n\n\n\n<p>and check that all the databases are present:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SHOW databases;<\/code><\/pre>\n\n\n\n<p>The list of all databases must get available, including ours:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>+--------------------+\n| Database           |\n+--------------------+\n| db1                |\n| db2                |\n| information_schema |\n| mysql              |\n| performance_schema |\n+--------------------+\n5 rows in set (0.00 sec)\n<\/code><\/pre>\n\n\n\n<p>Select the database we\u2019ve just imported:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>USE db1;<\/code><\/pre>\n\n\n\n<p>and check the presence of tables:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SHOW tables;<\/code><\/pre>\n\n\n\n<p>In case the tables have not been created or they are empty, check the dump file itself and repeat the whole process once again except for the step when a new database was created (as it already exists).<br><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">7. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Access data correction on the remote host (B)<\/h3>\n\n\n\n<p>The main data that should be changed in Magento after being transferred is 1) basic URLs and 2) access keys to MySQL:<br><\/p>\n\n\n\n<p><strong>Changing basic URLs<\/strong><br><\/p>\n\n\n\n<p>You will need to change all old paths in the `core_config_data` table. To start with, let&#8217;s localize these fields using the \u2018value\u2019 query that includes the old address. Let\u2019s suppose that the old website address was &#8216;1001101010.com&#8217;, then the search command will look as follows:<br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT * FROM core_config_data WHERE `value` LIKE '%1001101010.com%' \\G<\/code><\/pre>\n\n\n\n<p class=\"has-vivid-cyan-blue-color has-text-color\">*`\\G` at the end of the query instead of `;` will make the records better readable.<\/p>\n\n\n\n<p class=\"has-vivid-cyan-blue-color has-text-color\"><strong>** Don\u2019t forget to use `table_prefix` before table names if it was installed.<\/strong><br><\/p>\n\n\n\n<p>The result will look about like that:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql&gt; SELECT * FROM core_config_data WHERE `value` LIKE '%1001101010.com%' \\G\n*************************** 1. row ***************************\nconfig_id: 2\n    scope: default\n scope_id: 0\n     path: web\/unsecure\/base_url\n    value: http:\/\/1001101010.com\/\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>*************************** 12. row ***************************\nconfig_id: 2401\n    scope: default\n scope_id: 0\n     path: web\/secure\/base_url\n    value: https:\/\/1001101010.com\/\n*************************** 13. row ***************************\nconfig_id: 2402\n    scope: default\n scope_id: 0\n     path: web\/secure\/base_link_url\n    value: https:\/\/1001101010.com\/\n13 rows in set (0.00 sec)\n<\/code><\/pre>\n\n\n\n<p>At this point, our goal is to change the old address to a new one. For this purpose, let\u2019s make sure that it should be changed in all lines indeed (it is so most of the time except for some rare cases that involve the configuration of 3rd party modules) and run the following query:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>UPDATE `core_config_data`\n SET `value` = replace(value, '1001101010.com', 'mynewdomain.com')\n WHERE `value` LIKE '%1001101010.com%';\n<\/code><\/pre>\n\n\n\n<p>It will replace all occurrences of `1001101010.com` lines in the `value` field to the `mynewdomain.com` line.<br><\/p>\n\n\n\n<p>The result should be about as follows (the number of lines should be equal):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt; Query OK, 13 rows affected (0.00 sec)\n&gt; Rows matched: 13  Changed: 13  Warnings: 0\n<\/code><\/pre>\n\n\n\n<p>The following request:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT * FROM core_config_data WHERE `value` LIKE '%1001101010.com%' \\G<\/code><\/pre>\n\n\n\n<p>Now, it\u2019s time to <a href=\"https:\/\/www.mageworx.com\/magento2-order-editor-extension.html\" data-type=\"URL\" data-id=\"https:\/\/www.mageworx.com\/magento2-order-editor-extension.html\">proceed to editing<\/a> the file of the environment `app\/etc\/env.php` (from the Magento root; in the example, it was `\/var\/www\/html\/`). <br><\/p>\n\n\n\n<p>Let\u2019s open it in a text editing program (I use <em>Nano <\/em>though it\u2019s surely the question of personal preferences).<br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nano \/var\/www\/html\/app\/etc\/env.php<\/code><\/pre>\n\n\n\n<p>Then edit data in `&#8217;db&#8217; =&gt; &#8216;connection&#8217;` by specifying the accurate data from the new server in the &#8216;username&#8217; and &#8216;password&#8217; fields.<\/p>\n\n\n\n<p class=\"has-vivid-cyan-blue-color has-text-color\">*<strong>IMPORTANT!<\/strong> If your database is located on a remote server, there is no need to change data. The only thing you need to do is to make sure there is access from the current server to that remote database. (For example, that it has been added to the firewall whitelist on the database server).<\/p>\n\n\n\n<p class=\"has-vivid-cyan-blue-color has-text-color\">Use the &#8216;localhost&#8217; value in the &#8216;host&#8217; field to understand whether the connection is local or not.<br><\/p>\n\n\n\n<p>Next, save the file.<br><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">8. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Correction of access permissions to files and directories<br><\/h3>\n\n\n\n<p>In order to accurately set up access permissions, you need to know from which user and with which group your web-server runs. <\/p>\n\n\n\n<p>Most frequently, it is either `apache` for CentOS or `www-data` in Ubuntu. As a rule, the username equals the group name. However, on different servers, this may differ. <br><\/p>\n\n\n\n<p>The following command will help you figure it out:<br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ps aux | egrep '(apache|httpd)'<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"906\" height=\"170\" src=\"https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/4.png\" alt=\"How to Transfer Magento 2 Site from Localhost to Server? | MageWorx Magento Blog\" class=\"wp-image-10405\" srcset=\"https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/4.png 906w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/4-600x113.png 600w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/4-768x144.png 768w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/4-250x47.png 250w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/4-696x131.png 696w\" sizes=\"auto, (max-width: 906px) 100vw, 906px\" \/><\/figure>\n\n\n\n<p>As a result, in the first column, you\u2019ll see username (the group name is likely to be the same. However, if you are unsure, use the `groups apache` command, where `apache` is the username in order to check it out).<\/p>\n\n\n\n<p>The first thing after this, we will need to transfer all files and directories inside Magento to the web-server user (it is `apache` in the example. For the `www-data` user simply replace &nbsp;`apache:apache` to `www-data:www-data`, and similarly for others): <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo chown -R apache:apache \/var\/www\/html<\/code><\/pre>\n\n\n\n<p>Next, check whether the changes have been applied or not:<br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ls -la \/var\/www\/html<\/code><\/pre>\n\n\n\n<p>All files and directories (except for the parent one marked as `..` must have a user and the `apache` group (if `www-data` is a web-server user in your system, then it should be marked as an owner):<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"664\" height=\"454\" src=\"https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/5.png\" alt=\"How to Transfer Magento 2 Site from Localhost to Server? | MageWorx Magento Blog\" class=\"wp-image-10406\" srcset=\"https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/5.png 664w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/5-600x410.png 600w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/5-250x171.png 250w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/5-218x150.png 218w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/5-614x420.png 614w\" sizes=\"auto, (max-width: 664px) 100vw, 664px\" \/><\/figure><\/div>\n\n\n\n<p>Now, it is required to accurately set up access permissions to the Magento files and directories. According to the documentation, the following setup is highly recommended:<br><\/p>\n\n\n\n<p class=\"has-vivid-cyan-blue-color has-text-color\">*All commands must be run from root Magento!, consistently 1 after 1. In the example, the Magento root on the server is `\/var\/www\/html`.<\/p>\n\n\n\n<p>Use the `pwd` command to check the current location.<br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>find var generated vendor pub\/static pub\/media app\/etc -type f -exec chmod u+w {} +\nfind var generated vendor pub\/static pub\/media app\/etc -type d -exec chmod u+w {} +\nchmod u+x bin\/magento\n<\/code><\/pre>\n\n\n\n<p class=\"has-vivid-cyan-blue-color has-text-color\">*If the current user lacks permissions to run these commands, use the user\u2019s `root `  ( `sudo` command, like `sudo find &#8230;`)<br><\/p>\n\n\n\n<p>9. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Standard procedures before launching Magento<br><\/p>\n\n\n\n<p>It is time to check that Magento launches from the command line. To begin with, let\u2019s test the standard output of the commands you\u2019ve got access to:<\/p>\n\n\n\n<p class=\"has-vivid-cyan-blue-color has-text-color\">*Now, after setting up permissions, any access to Magento will be made from the same web-server user that generates files, cache files, statics, etc. If you ignore this, Magento may stop running and you will be forced to restore permissions once again (the previous step in these guidelines).<br><\/p>\n\n\n\n<p class=\"has-vivid-cyan-blue-color has-text-color\">**For accurate operation, you\u2019ll need to find the right  <code> php <\/code> interpreter on your server. Usually, ` php` alias refers to the up-to-date version. However, you\u2019ll often need to indicate the full path, such as `\/usr\/bin\/php72` for example.<br><\/p>\n\n\n\n<p class=\"has-vivid-cyan-blue-color has-text-color\">***Here and further, all Magento commands will run from the Magento root directory on the server (B).<br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo -u apache php bin\/magento list<\/code><\/pre>\n\n\n\n<p>This will make the list with the commands available in the commands line: <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"1299\" height=\"885\" src=\"https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/6.png\" alt=\"How to Transfer Magento 2 Site from Localhost to Server? | MageWorx Magento Blog\" class=\"wp-image-10407\" srcset=\"https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/6.png 1299w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/6-600x409.png 600w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/6-1200x818.png 1200w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/6-768x523.png 768w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/6-250x170.png 250w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/6-218x150.png 218w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/6-696x474.png 696w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/6-1068x728.png 1068w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/6-616x420.png 616w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/figure><\/div>\n\n\n\n<p>If it all went successfully, you can proceed to the further commands:<br><\/p>\n\n\n\n<p class=\"has-vivid-cyan-blue-color has-text-color\">*If before the transfer you didn\u2019t clear directories with cache and the generated files, this is the right time to do that using the following command:<br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo rm -rf var\/cache\/* var\/page_cache\/* var\/generation\/*<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo -u apache php bin\/magento setup:upgrade<\/code><\/pre>\n\n\n\n<p>You can avoid running this command, but I still recommend making sure that all the modules are written and no errors occur. As a result, you\u2019ll see a list with modules, which were processed, while not seeing any errors in the process.<br><\/p>\n\n\n\n<p>Perform compilation in order to generate the necessary Magento files:<br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo -u apache php bin\/magento setup:di:compile<\/code><\/pre>\n\n\n\n<p class=\"has-vivid-cyan-blue-color has-text-color\">*At this point, it is critical to detect all errors that have occurred. Otherwise, Magento will run improperly. If no errors have been found, then everything is just perfect. ? <\/p>\n\n\n\n<p>Then, generate statics ( if the production mode is enabled. To check your current mode, use the following command: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo -u apache php bin\/magento deploy:mode:show<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo -u apache php bin\/magento setup:static-content:deploy\n<\/code><\/pre>\n\n\n\n<p class=\"has-vivid-cyan-blue-color has-text-color\">*To generate statics for a specific locale, specify it as a parameter after the command. For example, `sudo -u apache php bin\/magento setup:static-content:deploy ru_RU` will be used for the Russian locale.<br><\/p>\n\n\n\n<p>Congratulations! You\u2019ve successfully transferred your Magento2 store from localhost to properly operate on a new server. Now, open it in a browser by entering a new address! <br><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1809\" height=\"917\" src=\"https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/ac.jpg\" alt=\"How to Transfer Magento 2 Site from Localhost to Server? | MageWorx Magento Blog\" class=\"wp-image-10408\" srcset=\"https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/ac.jpg 1809w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/ac-600x304.jpg 600w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/ac-1200x608.jpg 1200w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/ac-768x389.jpg 768w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/ac-250x127.jpg 250w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/ac-696x353.jpg 696w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/ac-1068x541.jpg 1068w, https:\/\/www.mageworx.com\/blog\/wp-content\/uploads\/2019\/06\/ac-829x420.jpg 829w\" sizes=\"auto, (max-width: 1809px) 100vw, 1809px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">10. &nbsp;Troubleshooting: frequent issues<br><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Issue #1<\/h4>\n\n\n\n<p><strong>Problem:<\/strong><\/p>\n\n\n\n<p>If when copying the archive, you receive a message of the kind:<br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>scp: \/var\/www\/html\/aws-botapi.tar.gz: Permission denied<\/code><\/pre>\n\n\n\n<p>Then you should check where you\u2019ve copied the archive on the server in the first instance. It is highly likely that the user who intends to connect lacks permissions to make a record in this directory (`\/var\/www\/html` in the example). <\/p>\n\n\n\n<p><strong>Solution:<\/strong><\/p>\n\n\n\n<p>This can be solved by changing the directory where you try to copy upon running the ` scp ` command or connecting to the server and adjusting the access permissions to this directory for the current user:  <\/p>\n\n\n\n<p>`sudo chown -R ec2-user \/var\/www\/html` (make a user the owner of the `\/var\/www\/html` directory and of all the included files and directories), or <\/p>\n\n\n\n<p>`sudo chmod -R o+w \/var\/www\/html` (permits all (`o-ther`) making a record (`w-rite`) in the directory `\/var\/www\/html`). <\/p>\n\n\n\n<p>Use these commands with caution as they directly influence your system security.<br><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Issue #2<\/h4>\n\n\n\n<p><strong>Problem:<\/strong><\/p>\n\n\n\n<p> If when importing databases, the following error occurs`ERROR 1049 (42000): Unknown database &#8216;db1&#8217;` (where `db1` is the name of a database), then your database has not been created.<\/p>\n\n\n\n<p><strong>Solution:<\/strong><\/p>\n\n\n\n<p>Try to access`mysql` and re-create this database once again.<br><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Issue #3<\/h4>\n\n\n\n<p><strong>Problem:<\/strong><\/p>\n\n\n\n<p>If when changing files and directories owner, you see the command `chown: invalid user: &#8230; `, then you likely specified web-server user on your server incorrectly.<\/p>\n\n\n\n<p><strong>Solution:<\/strong><\/p>\n\n\n\n<p>Consult the corresponding guides on the configuration of the server in your system or use the `ps aux` utility to determine the right user.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Issue #4<br><\/h4>\n\n\n\n<p><strong>Problem:<\/strong><\/p>\n\n\n\n<p>If there are PHP errors when starting Magento on a new server ( as a rule, it means the absence of some PHP extensions)&#8230;<\/p>\n\n\n\n<p><strong>Solution:<\/strong><\/p>\n\n\n\n<p>This can be solved by the installation of the missing extensions.<br><\/p>\n\n\n\n<p>a) `PHP&#8217;s json extension is required to use Monolog&#8217;s NormalizerFormatter` &nbsp;\u2015<\/p>\n\n\n\n<p> *php-json* extension is missing;<\/p>\n\n\n\n<p>b) `PHP Fatal error: &nbsp;Uncaught Error: Class &#8216;DOMDocument&#8217; not found in &#8230;` \u2015<\/p>\n\n\n\n<p> *php-xml* extension is missing;<\/p>\n\n\n\n<p>c) `PHP Fatal error: &nbsp;Class &#8216;IntlDateFormatter&#8217; not found in &#8230;` \u2015<\/p>\n\n\n\n<p> *php-intl* extebnsion is missing.<br><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Issue #5<\/h4>\n\n\n\n<p><strong>Problem:<\/strong><\/p>\n\n\n\n<p>If PHP extensions are missing when running the `composer update` command, you\u2019ll see the following errors:<\/p>\n\n\n\n<p>For example,<\/p>\n\n\n\n<p>`phpunit\/phpunit 6.5.14 requires ext-mbstring * -&gt; the requested PHP extension mbstring is missing from your system.`<\/p>\n\n\n\n<p><strong>Solution:<\/strong><\/p>\n\n\n\n<p>To deal with such errors, you need to simply install PHP extensions the composer is referring to. For example, `yum install php-mbstring`. <\/p>\n\n\n\n<p>A full list of the required extensions for your Magento 2 version can be found in the official documentation.<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Bottom Line<\/h2>\n\n\n\n<p>You are all set! In this article, I did my best to present easy to follow steps on transferring your Magento 2 site from localhost to server.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p class=\"has-text-align-center\"><strong><em>If you still have questions or wish to share your opinion, feel free to use the comment section below. I\u2019ll do my best to answer all the questions and concerns!<\/em><\/strong><br><\/p>\n","protected":false},"excerpt":{"rendered":"<p><span class=\"span-reading-time rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\">Reading Time: <\/span> <span class=\"rt-time\"> 11<\/span> <span class=\"rt-label rt-postfix\">minutes<\/span><\/span>The process of transferring a Magento 2-based site from one local host to another one is not a time-consuming process. However, it has a number of nitty-gritty details &amp; special aspects that should be taken into consideration before plunging into the process. In this blog post, we will make transferring a Magento 2 site from [&hellip;]<\/p>\n","protected":false},"author":15,"featured_media":10392,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[255,425],"tags":[438],"class_list":{"0":"post-10391","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-magento-2","8":"category-magento-how-tos","9":"tag-hosting"},"_links":{"self":[{"href":"https:\/\/www.mageworx.com\/blog\/wp-json\/wp\/v2\/posts\/10391","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mageworx.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mageworx.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mageworx.com\/blog\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mageworx.com\/blog\/wp-json\/wp\/v2\/comments?post=10391"}],"version-history":[{"count":26,"href":"https:\/\/www.mageworx.com\/blog\/wp-json\/wp\/v2\/posts\/10391\/revisions"}],"predecessor-version":[{"id":16000,"href":"https:\/\/www.mageworx.com\/blog\/wp-json\/wp\/v2\/posts\/10391\/revisions\/16000"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mageworx.com\/blog\/wp-json\/wp\/v2\/media\/10392"}],"wp:attachment":[{"href":"https:\/\/www.mageworx.com\/blog\/wp-json\/wp\/v2\/media?parent=10391"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mageworx.com\/blog\/wp-json\/wp\/v2\/categories?post=10391"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mageworx.com\/blog\/wp-json\/wp\/v2\/tags?post=10391"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}