installation.rst 3.7 KB

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