How to install v8js for PHP on Windows

Published on Author Yani6 Comments

This is a simple tutorial to help you install v8js for PHP on Windows.

 

If you want to install v8js for PHP on Linux, you can follow this tutorial:
https://blog.xenokore.com/how-to-install-v8js-for-php-on-linux/

 

Let’s get started.

 

First check if your PHP has Thread Safety, as we’ll need to know that to download the correct module. You can run a simple command in Windows to check this. It might be possible that you have to navigate to the PHP folder, but you can also find this by using a php_info(); file.

php -i | findstr "Thread"

This will output something like: Thread Safety => enabled

 

Now download the appropriate v8js module, depending on your PHP version, if you are unsure, you can run php -v to find out your PHP version.

If you need another version you can check out:

 

An easy way to download x64 binaries is to download one of the full PHP builds by Jan-E here:
https://www.apachelounge.com/viewtopic.php?t=6359

You can then simply copy over the files you need.

 

Now that you have all the files you need, extract them in their respective folders:

These files go in your \php\ folder:

  • v8.dll
  • icui18n.dll (php7)
  • icuuc.dll (php7)

And this file goes in your \php\ext\ folder:

  • php_v8js.dll

 

Now the last thing you have to do is add the following to the end of your php.in file:

; V8 Javascript Engine Module
extension=php_v8js.dll

 

Now restart your webserver and you’re all done!

 

Let’s test it out with a simple script:

$v8 = new V8Js();
$v8->executeString("print('hello world');");

Output: hello world

 

There we go, it’s as simple as that! Remember that it does not have any sort of DOM, so running commands on window. and document. will not work without first creating the DOM. There are some ways to do this by loading a javascript implementation of the DOM, but that’s for another time.

 

Have fun!

 

 

6 Responses to How to install v8js for PHP on Windows

  1. hello Yani,
    thank you for your article.
    I’m now searching, indeed, for some “javascript implementation of the DOM” which will allow me to use a function like that
    document.createElement(…)

    Do you have some information ?
    regards
    Thomas

    • It might be that you are running PHP x64, in which case you’ll also need v8js x64.
      I have updated the article and included a link to Jan-E’s PHP builds that contains this.

      • I got the issue as above guy, checking at wampserver tray icon, on PHP extension v8js was enabled, but couldn’t execute sample code.
        Checking at PHP log: PHP Warning: PHP Startup: Unable to load dynamic library ‘….php7.0.10/ext/php_v8js.dll’ – The specified module could not be found.

        I’m install x86 version of wampserver, downloading x86 binary of v8js

        • Have you placed the files in the correct folder? The php_v8js.dll file does not go into the php folder but the php/ext/ folder.

Leave a Reply

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