Search code examples
phpwgetstatic-pages

Wordpress/PHP create a static copy of the page


I need to make a static page from the dynamic one with all assets downloaded and all the links converted to local ones and download it in some tmp folder. Like when you press Ctrl+S in a browser. I tried using wget with shell_exec:

shell_exec("wget -E -H -k -p http://youmightnotneedjquery.com/  2>&1");

The problem is that it works perfectly when I run it from console, but when I use shell_exec, I get an error

Permission denied youmightnotneedjquery.com/index.html: No such file or directory Cannot write to 'youmightnotneedjquery.com/index.html' (No such file or directory).

As I understand, there is some problem with permissions, I tried to create a seperate directory with some high permissions and www-data as owner and specify it in the command using -O flag, but I get an error that I can't use -k and -O flags at the same time. So I hope to solve that issue with permission, but I still have to specify the destination folder somehow. Or maybe there's a php solution without wget that I can use, as it seems not quite hard but a lot of work to do.


Solution

  • Helped using -P flag and creating a folder with owned www-data

    shell_exec("wget -E -H -k -p http://mysite.local/ -P some-temp-folder 2>&1")