I just want to download, install and setup WordPress using PHP.

I can do it using WP-CLI and command line and it worked.

Now I want to do it using with WP-CLI and PHP.

I read Run WP-CLI using PHP

The answer of above question suggest following code to test.

$output = shell_exec("wp --info");
echo "<pre>".$output."</pre>";

I tried it, but it return nothing. How can I solve this issue?

Notes :

  • I am testing this with localhost (XAMPP).
  • wp --info working fine on command prompt.
  • shell_exec() working fine with other normal non wp commands.
  • 1
    if you are trying to do it from the web, than it will never work as no secure host will let you run a shell script – Mark Kaplun Aug 7 '18 at 10:18
  • @MarkKaplun Even in dedicated server? – I am the Most Stupid Person Aug 7 '18 at 10:33
  • You can get this to work on a dedicated server (though it may not be a the best idea for security reasons as Mark Kaplun pointed out) but it will require some setup to allow the apache user that executes php to run these commands. – Iceable Aug 7 '18 at 11:20
  • a dedicated server.... maybe if you are the only one that uses it, but this is a security smell, and if you configure the server to allow this any attacker that will succeed in executing a php script on your server will "own" it. If you are looking into creating wordpress site via a web interface you will have to find a more subtle ways. – Mark Kaplun Aug 7 '18 at 12:25
  • sorry, but downvoted this, as this sounds like a permission issue somewhere which will be impossible to even guess without access to your machine. Regardless, my previous comments stand, this is not the way to go whatever you are trying to do. – Mark Kaplun Aug 9 '18 at 11:36

Please check if PHP is running in safe mode. excel_shell is disabled when PHP is running in safe mode.

You can check this running the phpinfo() function.

Tip: You could make a install script in bash and execute that from PHP. This way it's easier to test on the command line first, and then wrap it in PHP.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.