installation.rst 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. Installation
  2. ============
  3. - `Prerequisites <#prerequisites>`__
  4. - `Installing via Composer <#installing-via-composer>`__
  5. - `Custom Installation <#custom-installation>`__
  6. - `Installing from tarball <#installing-from-tarball>`__
  7. Prerequisites
  8. -------------
  9. PHP PhantomJS requires PHP **5.3.0** or greater to run.
  10. Installing via Composer
  11. -----------------------
  12. Install `Composer <https://getcomposer.org/>`__ for your project:
  13. .. code:: shell
  14. $ curl -s http://getcomposer.org/installer | php
  15. Create a ``composer.json`` file in the root of your project:
  16. .. code:: yaml
  17. {
  18. "require": {
  19. "jonnyw/php-phantomjs": "3.*"
  20. },
  21. "config": {
  22. "bin-dir": "bin"
  23. },
  24. "scripts": {
  25. "post-install-cmd": [
  26. "PhantomInstaller\\Installer::installPhantomJS"
  27. ],
  28. "post-update-cmd": [
  29. "PhantomInstaller\\Installer::installPhantomJS"
  30. ]
  31. }
  32. }
  33. It is important that you have the 'scripts' section shown above in your
  34. ``composer.json`` file as it will install the latest version of
  35. PhantomJS for your system to your project's bin folder. It is
  36. recommended that you create a bin folder in the root of your project as
  37. this is where the PHP PhantomJS library will look for your PhantomJS
  38. executable. If you would prefer to use a PhantomJS executable in a
  39. custom location, see the `Custom Installation <#custom-installation>`__
  40. section.
  41. Finally, install the composer depedencies for your project:
  42. .. code:: shell
  43. $ php composer.phar install
  44. Custom Installation
  45. -------------------
  46. If you would prefer to use a custom install location for the PhantomJS
  47. executable, you simply need to tell the client where to find the
  48. executable file:
  49. .. code:: php
  50. use JonnyW\PhantomJs\Client;
  51. $client = Client::getInstance();
  52. $client->setPhantomJs('/path/to/phantomjs');
  53. .. important::
  54. The PHP PhantomJS library also requires a `phantomloader` file that comes bundled with the library and is installed to the bin folder defined in your `composer.json` file. If you are setting a custom path to the PhantomJS executable, you need to make sure that the `phantomloader` file can be found in the bin folder it was installed to.
  55. If you would like composer to install all executable files to a custom bin location when installing dependencies, set the bin dir location in your project's `composer.json` file:
  56. .. code:: yaml
  57. {
  58. "config": {
  59. "bin-dir": "/path/to/your/projects/bin/dir"
  60. }
  61. }
  62. You will need to make sure that this directory exists and is writable by
  63. Composer before running the composer install.
  64. Once you have updated your bin location run composer install to install
  65. PhantomJS:
  66. .. code:: shell
  67. $ php composer.phar install
  68. This should install the correct PhantomJS executable for your system and the required `phantomloader` file to the bin locaiton you defined in your `composer.json` file.
  69. Now you need to tell the client where to find your bin folder:
  70. .. code:: php
  71. use JonnyW\PhantomJs\Client;
  72. $client = Client::getInstance();
  73. $client->setBinDir('/path/to/bin/dir');
  74. Installing from tarball
  75. -----------------------
  76. The PHP PhantomJS library contains several depedencies in order to
  77. function so it is recommended that you install it via composer as this
  78. will handle your dependencies for you. If you do wish to install it from
  79. a `tarball release <https://github.com/jonnnnyw/php-phantomjs/tags>`__
  80. then you will need to install the dependencies manually.
  81. The PHP PhantomJS library currently requires the following depdencies:
  82. - `Symfony Config Component <https://github.com/symfony/Config>`__ ~2.5
  83. - `Symfony Dependency Injection
  84. Component <https://github.com/symfony/DependencyInjection>`__ ~2.5
  85. - `Symfony Filesystem
  86. Component <https://github.com/symfony/filesystem>`__ ~2.5
  87. - `Twig templating Component <https://github.com/fabpot/Twig>`__ ~1.16
  88. - `PhantomJS <http://phantomjs.org/>`__ ~1.9
  89. Make sure the components are in your include path and that the PhantomJS
  90. executable is installed to your projects bin folder as mentioned in the
  91. `Custom Installation <#custom-installation>`__ section.