installation.rst 4.0 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. If you would like composer to install the PhantomJS executable to a
  54. custom location when installing dependencies, set the bin dir location
  55. 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 to
  69. the bin locaiton you defined in your ``composer.json`` file. As
  70. mentioned above, you will need to tell the client where to find your
  71. PhantomJS executable as it is not installed in the default location:
  72. .. code:: php
  73. use JonnyW\PhantomJs\Client;
  74. $client = Client::getInstance();
  75. $client->setPhantomJs('/path/to/phantomjs');
  76. Installing from tarball
  77. -----------------------
  78. The PHP PhantomJS library contains several depedencies in order to
  79. function so it is recommended that you install it via composer as this
  80. will handle your dependencies for you. If you do wish to install it from
  81. a `tarball release <https://github.com/jonnnnyw/php-phantomjs/tags>`__
  82. then you will need to install the dependencies manually.
  83. The PHP PhantomJS library currently requires the following depdencies:
  84. - `Symfony Config Component <https://github.com/symfony/Config>`__ ~2.5
  85. - `Symfony Dependency Injection
  86. Component <https://github.com/symfony/DependencyInjection>`__ ~2.5
  87. - `Symfony Filesystem
  88. Component <https://github.com/symfony/filesystem>`__ ~2.5
  89. - `Twig templating Component <https://github.com/fabpot/Twig>`__ ~1.16
  90. - `PhantomJS <http://phantomjs.org/>`__ ~1.9
  91. Make sure the components are in your include path and that the PhantomJS
  92. executable is installed to your projects bin folder as mentioned in the
  93. `Custom Installation <#custom-installation>`__ section.