想要在新服务器上测试迁移的wordpress网站,但它会重定向到旧的URL

时间:2017-05-10 09:03:56

标签: wordpress .htaccess amazon-ec2

Hi Team,

I have a wordpress website, which I have migrated to a new Amazon AWS EC2 Linux Free Tier Instance.

The steps I followed are:
1. Backed up wordpress files(public_html folder) and database.
2. Installed LAMP, SSL and PhpMyAdmin on new server(followed Amazon Tutorials).
3. Copied wordpress files backup to new server under /var/www/html folder.
4. Created required database and required user on new server.
5. Edited wp-config.php with required details: dbname, dbuser, dbpassword, ...
6. Imported the backedup database file on new server.
7. Tried accessing the new url which installed wordpress.

Everything upto here worked fine.

But now, when I access wp-admin console or home page url, it redirects to the old server and instead of displaying the EC2 public DNS name in the browser address bar, the old url is displayed which I do not want (I understand I have not changed the domain mapping to the new server ip address yet.)

Because unless and until I am sure, that the site functions well on new server, I do not want to map the domain name to the new server ip address.

I want to test my site functioning on the new server without mapping the domain name to the new server ip and I want the EC2 instance public DNS to be displayed in the browser's address bar.

I have tried several ways for doing this: 
- Edited /etc/hosts with ip and EC2 public DNS name.
- Replaced old url with new url in database backup file using notepad++ as 
  well as the script on github.
- Changed the old url in .htaccess as well.
- Added certain constants in wp-config.php.
- Manually changed the url entries in database for certain tables like 
  cp_options, cp_posts, cp_postmeta

But all lead to server disconnection, phpmyadmin hangs and wp-admin also doesnt open up.

I need to stop and start the new server to access all these again.

Request you to please help me if I am missing anything or following any wrong step. 

3 个答案:

答案 0 :(得分:0)

我猜,您的新域名与旧域名不同。如果是这样,您应该为新数据库执行以下SQL:

UPDATE [table_prefix]options SET option_value = REPLACE(option_value, '[from]', '[to]') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE [table_prefix]wp_posts SET post_content = REPLACE (post_content, '[from]', '[to]');
UPDATE [table_prefix]postmeta SET meta_value = REPLACE (meta_value, '[from]','[to]');
UPDATE [table_prefix]termmeta SET meta_value = REPLACE (meta_value, '[from]','[to]');
UPDATE [table_prefix]posts SET `guid` = replace(`guid`, '[from]','[to]');

[table_prefix] - 是你的$ table_prefix(在wp-config.php中查找)
[from] - 是您的旧网站网址(例如http://example-old.com
[to] - 是您的新网站网址(例如http://example-new.com

答案 1 :(得分:0)

简而言之,您需要将旧路径替换为数据库中的新路径。

打开你的phpmyadmin - >选择适当的数据库名称 转到wp_options表有两个option_name 1)siteurl 2)home_url请更改为新域名。

登录到您的新网站管理员面板后,转到永久链接并选择普通,然后选择post_name url,它会将旧网址反映到您数据库中的新网址。

答案 2 :(得分:0)

Hi Team,

This is resolved. 

The issue was with the linux server memory. It is only 1 GiB for t2.micro instance, whereas my website requires 1.95 GiB to run.

The website was migrated successfully, all the files, database, url changes were fine; but the wp-admin did not open and server was getting disconnected as CPU utilization was crossing limits.

Happy, was able to spot this out.

Was able to spot it out as below:
Renamed all plugins directories and then tried opening wp-admin page which opened successfully with the new server domain name. (Thanks Kulikov and Kuldip: your suggestions followed and worked).

Then, activated plugins one by one; and as the number of plugins increased, noticed that server started responding slowly. Then checked the CPU utilization graph under monitoring in EC2 console which showed limits extended. Also checked using top.

Thanks