Converting a dynamic PHP/mySQL website to an archi

2019-04-15 05:59发布

问题:

I have a PHP/mySQL site that is no longer going to get any new content added. But I'd like to keep what I do have as an archive and keep it online. Ideally I'd like to convert it to a static site so that it no longer requires a database.

If anyone else has gone through this process, are there any tools, scripts, or methodologies that can automate this or at least make this easier? I'd want to be able to do things like make sure that all the links still work (so they'd have to somehow be converted to correctly point to the new static versions), things like that.

I have ssh access to the server in question. I'm relatively comfortable with both PHP and Python so tools using those languages would be ideal.

Note: there are two basic reasons I'm doing this:

  1. cost, as it's much cheaper to host just a collection of static files than a dynamic website (I'm using NearlyFreeSpeech and with the bandwidth I'm using I estimate my costs would go down to well under $1/month).
  2. spammers have somehow found my site and keep signing up for accounts (at which point, they're blocked from making comments anyway, but it's still annoying).

回答1:

I have recently used the following to good effect:

wget --mirror -w 2 -p --html-extension --convert-links -P folder_to_save_to http://mysite.com

You might need to use the full path to your wget script. This will change all the links so that your site is fully static and self contained.



回答2:

If you have shell access to any linux machine (perhaps even your own webserver would suffice), I'd recommend that you just spider and download a mirror of your own site using wget. Wget is a utility which is designed to mirror sites as flat files, and it has been in use for quite some time. I believe it should serve you well:

http://www.gnu.org/software/wget/manual/wget.html

I hope that's helpful.

Chris



回答3:

Using PHP you could write a simple script that would do this:

  1. Save current page.
  2. Follow links from that page and saving those pages (and for each page repeat from 1).
  3. Replace URLs on current page with those leading to saved pages.