网站/WordPress从虚拟主机搬家到VPS上

拖了一个月终于着手并且完成了。其实没有什么难的。但是因为我对Linux的了解非常局限,还是花了一番功夫,同时学了很多东西,在这里记一下。没有试图写一篇“手把手教你搬WP”,只是记录一些我觉得有帮助的东西,希望做同样的事情的且同样不是那么牛逼的Linux学习者们有用:)

虽说是WordPress搬家,但是任何一个小型网站搬家都差不多这样了吧,嘿嘿。

如果用cPanel和MySQLAdmin之类的东西可能就很傻瓜,但是第一cPanel太贵了(竟然要425多刀一年,我都笑了),第二VPS都买了必须必须要抓住每一个学Linux的机会啊。

过程如下(断断续续弄了好几天…):

环境

虚拟主机和VPS都是host2ez的,最牛逼的主机提供商。系统是CentOS Linux 5.6,apache(现在改名叫httpd)已经装好了,再装

yum php mysql mysql-server

就成。

文件

这个简单,cPanel把虚拟主机上文件打包,VPS上wget下来就好。WP的独立性做的好,文件路径改变不会有什么问题。备份用的插件BackUpWordpress倒因为出问题了,不能识别路径,我直接禁用掉了,VPS嘛马上弄个备份方案还不容易,不需要用WP的插件了。在[wordpress path]/wp_config.php里把信息改一下,数据库部分的怎么改见下面。

数据库

对数据库命令不了解的同学建议先看一下mysql的教程。我不能把所有操作都写出来…这次弄这个还学了不少数据库的东西…tutorial很容易搜到,我觉得有一个比较好的命令列表点 这里,里面包括了所有常用的命令。

在虚拟主机的cPanel – mysqladmin里备份出.sql文件,传上VPS,导入文件的命令是

mysql – u user_name -p database_name < file_name.sql

很多地方写的-p后面跟密码,我用的版本-p后面不跟东西,回车以后才提示输密码,可能是新版本不提倡显式输入密码了吧。非要用的话就–password=”xxxxxx”

如果你导出文件选的是整个mysql,需要打开文件把database”information_schema”部分删掉,否则会失败,这个db貌似是mysql自己的,不能改..不懂

之后要建立一个用户并给此用户分配使用相应db的权限,虽然我们也可以直接把root用户写进wp_config.php但是稍微有点安全意识的程序员都不会想要这么做的…虽然权限没什么大不了的,但是名字叫root就是不行! 所以进数据库:

mysql -u root -p

进去以后添加用户:

mysql> create user 'username'@'localhost' identified by 'mypass';

分配权限:

mysql> grant all privileges on databasename.* to username@localhost;
mysql> flush privileges;

然后就把这个用户甩给Wordpress啦(编辑wp_config.php)

测试的时候有一些问题

上面完了就能http进vps的ip看到博客了,但是不要去点任何东西…因为数据库里“本站”的地址还是原来的域名,这样如果你原来的网站还开着那么随便点个链接就进到原来网站了,如果没开那就can’t find page啦。

而且因为没法进后台改,所以只好进mysql改了

mysql> use viaxlcom_viaxlcom;
mysql> select * from wp_options where option_value rlike "^http";
+-----------+---------+-------------+----------------------------+----------+
| option_id | blog_id | option_name | option_value               | autoload |
+-----------+---------+-------------+----------------------------+----------+
|         2 |       0 | siteurl     | http://axlarts.com/blog      | yes      |
|        39 |       0 | home        | http://axlarts.com           | yes      |
|        41 |       0 | ping_sites  | http://rpc.pingomatic.com/ | yes      | 
+-----------+---------+-------------+----------------------------+----------+
3 rows in set (0.06 sec)
update wp_options set option_value="http://12.34.56.78/blog" where option_id=2;
update wp_options set option_value="http://12.34.56.78" where option_id=39;

这样就把VPS上的网站地址改成本身的IP了。

————————————-
另外我发现一些插件会出现权限问题,比如JW player(放flv视频用的插件),没法启用插件因为提示不能写目录,我整个www目录都是755权限,设置成777以后可以开启了,然后再弄回来。这个问题解决了但是原因一直不知道,直到我因为另一个问题搜了一下才搞明白。

另一个问题是:更新插件update的时候会提示我输入ftp帐号,以前没这事啊,于是我就去装了个vsftpd(ftp的服务端),设置好能更新了,但是为什么?后来搜到这篇文章 <Auto Update WordPress Without FTP> 解决了ftp的问题并且意识到上面的问题也和这个有关系,即因为目录的owner不是httpd,所以网站脚本没有对文件操作的权限。

/var/www目录的owner要设置成httpd的运行者(可以用ps aux或者top命令查看),可能是www,apache或者nobody或者其他的。我的是apache,所以在chown apache:apache /var/www -R之后update就不用输ftp了,我立刻关了vsftpd依然ok,可见之前是绕了弯子了,没权限还用ftp操作文件…

绑域名

进godaddy面板直接改A地址就好了,没有别的要操作的。

但是因为我本来虚拟主机上就放了两个网站,所以怎么在一个VPS上绑定多个域名多个网站?之前用cPanel是傻瓜操作,没有怎么弄?这个我也弄了好半天最终解决了,马上再写一篇单独说吧

好啦好啦,到此结束,路人有问题可以在下面留言~

9,279 thoughts on “网站/WordPress从虚拟主机搬家到VPS上

  1. JorgeDus

    This one is staying open in a tab for the rest of the day so I can come back and re read certain parts, and a look at tailortarget suggests I will be doing the same with a few more pages here too, this is going to be a deep dive over the coming hours.

    Reply
  2. Damianwem

    Polished and informative without feeling overproduced, that is the sweet spot, and a look at startwithclearpurpose hit it again, you can tell when a site has been built with care versus thrown together for the sake of having something to put online and this is clearly the former approach taken by the team.

    Reply
  3. LutherGeals

    Felt the post handled a sensitive angle of the topic with appropriate care, and a look at explorelimitlessthinking extended that careful handling across related material, sites that can navigate delicate territory without causing damage are rare and require a level of judgement that comes from experience rather than from following any clear playbook.

    Reply
  4. QuincySania

    Took my time with this rather than rushing because the writing rewards attention, and after buildclarityforward I had even more to absorb, the kind of content that pays back the patient reader rather than punishing them with empty filler is something I look for and rarely find in regular searches lately.

    Reply
  5. Erikmyday

    I learned more from this short post than from longer articles I read earlier today, and a stop at growwithintentiondaily added even more useful detail without going off topic, this site clearly knows how to keep things focused without sacrificing depth which is a hard balance to strike for any writer.

    Reply
  6. SterlingRet

    Glad I gave this a chance instead of bouncing on the headline, and after exploregrowthmindset I was certain I had made the right call, snap judgements based on titles miss a lot of good content and this is a reminder to slow down and check things out before scrolling past in a hurry.

    Reply
  7. KaleGelry

    Solid stuff, the kind of post that I will probably refer back to later this month when the topic comes up again, and a look at growwithsmartchoices only confirmed I should bookmark the site as a whole rather than just this single page for future reference and use across coming weeks.

    Reply
  8. Cooperblali

    Glad I clicked through from where I did because this turned out to be worth the time spent, and after createvalueconsistently I had a fuller picture, the kind of content that earns its visitors through delivering value rather than chasing them through aggressive advertising or constant pop ups appearing everywhere on the screen lately.

    Reply
  9. Irabig

    Thank you for the genuine effort here, it shows in every paragraph and not just the headline, and after my visit to hupblob I was sure this site cares about getting things right rather than chasing clicks, which is the main reason I will come back later this week to read more.

    Reply
  10. TommyArrak

    Stands apart from similar pages by actually being useful, that is high praise these days, and a look at growfocusedresults kept that standard going, you can tell when a site is built around the reader versus around metrics and this one clearly belongs to the first category for sure based on what I read.

    Reply
  11. QuincySania

    Closed the post with a small satisfied sigh, and a stop at buildclarityforward produced the same gentle exhale, content that ends well is content that respects the rhythm of reading and the writers here have clearly thought about how their pieces close rather than just trailing off when they run out of things to say.

    Reply
  12. Gregnib

    Adding to the bookmarks now before I forget, that is how good this is, and a look at authenticlivinggoods confirmed the rest of the site is worth saving too, this is one of those rare finds that justifies the time spent searching the web for once which is a relief in the current environment.

    Reply
  13. LawsonAmete

    Nice and clean, that is the best way to describe the writing here, no clutter and no wasted words, and a quick visit to brightfuturedeals kept that going, I appreciate when a site treats its readers like people who can think for themselves without needing constant hand holding through every paragraph.

    Reply
  14. Hughnerie

    Reading this site over the past week has changed how I evaluate content in this space, and a look at discovergrowthpaths extended that recalibration, the standards I bring to reading on the topic have shifted upward as a direct result of regular exposure to this kind of work and that shift will outlast any single reading session.

    Reply
  15. DeonNug

    Now adjusting my mental model of how the topic fits into the broader landscape, and a look at jazbrood extended that adjustment, content that affects my structural understanding rather than just my factual knowledge is content with deeper impact and this site is providing those structural updates at a meaningful rate consistently across topics.

    Reply
  16. KeenanSog

    Going to share this with a friend who has been asking the same questions for a while now, and a stop at learnandtransformfast added a few more pages I will pass along too, this is the kind of generous information that earns a small thank you from me right now and again later this week.

    Reply
  17. CamdenThize

    Closed my email tab so I could read this without interruption, and a stop at findyourwinningpath earned the same protected attention, when content is good enough to defend against the usual digital distractions you know it deserves better than the half attention most online reading gets in a typical busy day.

    Reply
  18. Elmerfreta

    Now planning to write about the topic myself eventually using this post as a reference, and a look at discoverwhatworksbest would also serve in that future piece, content that becomes raw material for my own writing rather than just informing my reading is content with multiplicative value and this site is generating that multiplicative effect.

    Reply
  19. JeremyPhosy

    Easily one of the better explanations I have read on the topic, and a stop at createprogresssystems pushed it even higher in my mental ranking of useful resources, the kind of site that beats the average not by trying harder but by simply caring more about what it puts out daily which always shows.

    Reply
  20. Cooperblali

    Worth a quiet moment of recognition for the consistency I have noticed across multiple posts, and a stop at createvalueconsistently continued that consistent quality, sites that maintain quality across many pieces rather than peaking on one viral post are sites with real editorial discipline and this one has clearly developed that discipline carefully.

    Reply
  21. KentDal

    Stands out for actually being useful instead of just being long, and a look at createfocusedmomentum kept that going, length without value is the default mode of most blogs these days but this site has clearly chosen a different path which I respect a lot as a reader who values careful editing decisions like that.

    Reply
  22. Gregnib

    Will be passing this along to a few people who would benefit from the perspective shared here, and a stop at authenticlivinggoods only added to what I will be sharing, this kind of generous content deserves to circulate widely rather than getting buried in some search engine algorithm tweak that pushes it down the rankings.

    Reply
  23. LawsonAmete

    If I had encountered this site five years ago I would have been telling everyone about it, and a look at brightfuturedeals extended that retrospective enthusiasm, the version of me who used to recommend favourite blogs frequently would have made sure friends knew about this one and that earlier enthusiasm is partially returning to me here.

    Reply
  24. ZacharyDeamn

    Took my time with this rather than rushing because the writing rewards attention, and after hobcar I had even more to absorb, the kind of content that pays back the patient reader rather than punishing them with empty filler is something I look for and rarely find in regular searches lately.

    Reply
  25. KendallBligo

    Really nice to see things explained without overcomplicating the topic, the words flow naturally and stay easy to follow, and a short visit to growintentionally only added to that experience because the same simple approach is used across the rest of the page too without any change in tone.

    Reply
  26. Irabig

    The overall feel of the post was professional without being stuffy, and a look at hupblob kept that approachable expertise going, finding the right register for technical content is hard but this site has clearly figured out how to sound knowledgeable without slipping into that distant lecturing tone that loses readers in droves every time.

    Reply
  27. KeenanSog

    Going to share this with a friend who has been asking the same questions for a while now, and a stop at learnandtransformfast added a few more pages I will pass along too, this is the kind of generous information that earns a small thank you from me right now and again later this week.

    Reply
  28. Hughnerie

    Honestly the simplicity of the explanation made the topic click for me in a way other writeups had not, and a look at discovergrowthpaths continued that clarity into related areas, when a writer gets the level of explanation right the reader does the heavy lifting themselves and the post just enables it.

    Reply
  29. ZacharyDiowl

    Felt the writer respected the topic without being precious about it, and a look at discoverwhatworks continued that respectful but unfussy treatment, finding the right register for serious topics is hard and this site has clearly figured out how to take the topic seriously while still being readable for casual visitors regularly.

    Reply
  30. Elmerfreta

    The way the post stayed on topic throughout without going on tangents was really refreshing, and a look at discoverwhatworksbest kept that focused approach going, discipline like this in writing is rare and worth recognising because most writers cannot resist wandering off into related subjects that dilute their main point and confuse readers along the way.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *