PHPackages                             jakoch/phantomjs-installer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. jakoch/phantomjs-installer

ActiveCustom-installer[Utility &amp; Helpers](/categories/utility)

jakoch/phantomjs-installer
==========================

A Composer package which installs the PhantomJS binary (Linux, Windows, Mac) into `/bin` of your project.

3.0.3(11mo ago)1515.4M—7.8%43[1 issues](https://github.com/jakoch/phantomjs-installer/issues)20MITPHPPHP &gt;5.3CI passing

Since Jul 29Pushed 5mo ago9 watchersCompare

[ Source](https://github.com/jakoch/phantomjs-installer)[ Packagist](https://packagist.org/packages/jakoch/phantomjs-installer)[ RSS](/packages/jakoch-phantomjs-installer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (17)Used By (20)

phantomjs-installer
===================

[](#phantomjs-installer)

[![Latest Stable Version](https://camo.githubusercontent.com/364e5cc9094a30f441346bff41b09d09eca04580f22e1ba6fb23362f7b61fbd0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a616b6f63682f7068616e746f6d6a732d696e7374616c6c6572)](https://packagist.org/packages/jakoch/phantomjs-installer)[![Total Downloads](https://camo.githubusercontent.com/08544a0d5f45aa44b3c501b80dde1369d99f4cb4348b18b0d384f367da2b71c0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a616b6f63682f7068616e746f6d6a732d696e7374616c6c6572)](https://packagist.org/packages/jakoch/phantomjs-installer)[![Build Status](https://github.com/jakoch/phantomjs-installer/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/jakoch/phantomjs-installer/actions/workflows/ci.yml)[![License](https://camo.githubusercontent.com/46f3ba5f05a2ce9f8af50f73d29b23ccadbe39be3f59308c045a2be3643a2fc6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6a616b6f63682f7068616e746f6d6a732d696e7374616c6c6572)](https://packagist.org/packages/jakoch/phantomjs-installer)

A Composer package which installs the PhantomJS binary (Linux, Windows, Mac) into `/bin` of your project.

##### Table of Contents

[](#table-of-contents)

- [phantomjs-installer](#phantomjs-installer)- [Table of Contents](#table-of-contents)
    - [Installation](#installation)
    - [How to require specific versions of PhantomJS?](#how-to-require-specific-versions-of-phantomjs)
    - [How does this work internally?](#how-does-this-work-internally)
    - [PhantomBinary](#phantombinary)
    - [Override platform requirements](#override-platform-requirements)
    - [Downloading from a mirror](#downloading-from-a-mirror)
    - [Automatic download retrying with version lowering on 404](#automatic-download-retrying-with-version-lowering-on-404)

Installation
------------

[](#installation)

To install PhantomJS as a local, per-project dependency to your project, simply add a dependency on `jakoch/phantomjs-installer` to your project's `composer.json` file.

```
{
    "require": {
        "jakoch/phantomjs-installer": "^3"
    },
    "config": {
        "bin-dir": "bin"
    },
    "scripts": {
        "post-install-cmd": [
            "PhantomInstaller\\Installer::installPhantomJS"
        ],
        "post-update-cmd": [
            "PhantomInstaller\\Installer::installPhantomJS"
        ]
    }
}
```

For a development dependency, change `require` to `require-dev`.

The default download source used is: You might change it by setting a custom CDN URL, which is explained in the section "[Downloading from a mirror](#downloading-from-a-mirror)".

By setting the Composer configuration directive `bin-dir`, the [vendor binaries](https://getcomposer.org/doc/articles/vendor-binaries.md#can-vendor-binaries-be-installed-somewhere-other-than-vendor-bin-) will be installed into the defined folder. **Important! Composer will install the binaries into `vendor\bin` by default.**

The `scripts` section is necessary, because currently Composer does not pass events to the handler scripts of dependencies. If you leave it away, you might execute the installer manually.

Now, assuming that the scripts section is set up as required, the PhantomJS binary will be installed into the `/bin` folder and updated alongside the project's Composer dependencies.

How to require specific versions of PhantomJS?
----------------------------------------------

[](#how-to-require-specific-versions-of-phantomjs)

The environment and server variable `PHANTOMJS_VERSION` enables you specify the version requirement at the time of packaging.

You can also set the `phantomjs-version` in the `extra` section of your `composer.json`:

```
 "extra": {
   "jakoch/phantomjs-installer": {
     "phantomjs-version": "2.1.1"
   }
 }
```

The search order for the version is 1) $\_ENV, 2) $\_SERVER, 3) `composer.json` (extra section), 4) fallback to v2.1.1 (hardcoded latest version).

How does this work internally?
------------------------------

[](#how-does-this-work-internally)

1. **Fetching the PhantomJS Installer**

In your composer.json you require the package "phantomjs-installer". The package is fetched by composer and stored into `./vendor/jakoch/phantomjs-installer`. It contains only one file the `PhantomInstaller\\Installer`.

2. **Platform-specific download of PhantomJS**

The `PhantomInstaller\\Installer` is run as a "post-install-cmd". That's why you need the "scripts" section in your "composer.json". The installer creates a new composer in-memory package "phantomjs", detects your OS and downloads the correct Phantom version to the folder `./vendor/jakoch/phantomjs`. All PhantomJS files reside there, especially the `examples`.

3. **Installation into `/bin` folder**

The binary is then copied from `./vendor/jakoch/phantomjs` to your composer configured `bin-dir` folder.

4. **Generation of PhantomBinary**

The installer generates a PHP file `PhantomInstaller\\PhantomBinary` and inserts the path to the binary.

PhantomBinary
-------------

[](#phantombinary)

To access the binary and its folder easily, the class `PhantomBinary` is created automatically during installation.

The class defines the constants `BIN` and `DIR`:

- `BIN` is the full-path to the PhantomJS binary file, e.g. `/your_project/bin/phantomjs`
- `DIR` is the folder of the binary, e.g. `/your_project/bin`

Both constants are also accessible via their getter-methods `getBin()` and `getDir()`.

Usage:

```
use PhantomInstaller\PhantomBinary;

// get values with class constants

$bin = PhantomInstaller\PhantomBinary::BIN;
$dir = PhantomInstaller\PhantomBinary::DIR;

// get values with static functions

$bin = PhantomInstaller\PhantomBinary::getBin();
$dir = PhantomInstaller\PhantomBinary::getDir();

```

This feature is similar to `location.js` of the [phantomjs module](https://github.com/Medium/phantomjs/blob/master/install.js#L93) for Node.

Override platform requirements
------------------------------

[](#override-platform-requirements)

The environment and server variables `PHANTOMJS_PLATFORM` and `PHANTOMJS_BITSIZE` enable you to override the platform requirements at the time of packaging. This decouples the packaging system from the target system. It allows to package on Linux for MacOSX or on Windows for Linux.

Possible values for

- `PHANTOMJS_PLATFORM` are: `macosx`, `windows`, `linux`.
- `PHANTOMJS_BITSIZE` are: `32`or `64`.

Downloading from a mirror
-------------------------

[](#downloading-from-a-mirror)

You can override the default download location of the PhantomJS binary file by setting it in one of these locations. Listed in order of precedence (highest first):

- The environment variable `PHANTOMJS_CDNURL`
- The server variable `PHANTOMJS_CDNURL`
- In your `composer.json` by using `$['extra']['jakoch/phantomjs-installer']['cdnurl']`:

```
 "extra": {
   "jakoch/phantomjs-installer": {
     "cdnurl": "https://github.com/Medium/phantomjs/releases/download/v1.9.19/"
   }
 },
```

**Default Download Location**

The default download location is Bitbucket: `https://api.bitbucket.org/2.0/repositories/ariya/phantomjs/downloads/`. You don't need to set it explicitly. It's used, when `PHANTOMJS_CDNURL` is not set.

**Mirrors**

You might use one of the following mirror URLs as a value for `PHANTOMJS_CDNURL`:

- `https://cnpmjs.org/downloads/` - USA
- `https://npm.taobao.org/mirrors/phantomjs/` - China
- `https://github.com/Medium/phantomjs/` - USA
- `https://repo1.maven.org/maven2/com/github/klieber/phantomjs/` - USA
- `https://mirrors.huaweicloud.com/phantomjs/` - China

This list of mirrors is not complete. If you know another mirror, please don't hesitate to add it here.

The mirror URLs are also not hardcoded, except for the Github URL. This enables you to point to any PhantomJS mirror or download folder you like. For instance, you could point to the URL of the download folder of your company, where the binaries are stored: `PHANTOMJS_CDNURL=https://cdn.company.com/downloads/phantomjs/`.

Automatic download retrying with version lowering on 404
--------------------------------------------------------

[](#automatic-download-retrying-with-version-lowering-on-404)

In case downloading an archive fails with HttpStatusCode 404 (resource not found), the downloader will automatically lower the version to the next available version and retry. The number of retries is determined by the number of hardcoded PhantomJS versions in `getPhantomJSVersions()`. This feature was added, because of the problems with v2.0.0 not being available for all platforms (see issue #25).

###  Health Score

59

—

FairBetter than 99% of packages

Maintenance62

Regular maintenance activity

Popularity59

Moderate usage in the ecosystem

Community39

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 89.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~264 days

Recently: every ~768 days

Total

16

Last Release

343d ago

Major Versions

1.9.8 → 2.0.02015-03-08

2.1.1-p09 → 3.0.02020-07-18

### Community

Maintainers

![](https://www.gravatar.com/avatar/3a4ac38be149d29b9cd37b203a37d3f1684a6aeeb28779105c86f358e226a7f4?d=identicon)[jakoch](/maintainers/jakoch)

---

Top Contributors

[![jakoch](https://avatars.githubusercontent.com/u/85608?v=4)](https://github.com/jakoch "jakoch (152 commits)")[![berlinger-rarents](https://avatars.githubusercontent.com/u/22027226?v=4)](https://github.com/berlinger-rarents "berlinger-rarents (6 commits)")[![boedah](https://avatars.githubusercontent.com/u/1183125?v=4)](https://github.com/boedah "boedah (2 commits)")[![da-eto](https://avatars.githubusercontent.com/u/145482?v=4)](https://github.com/da-eto "da-eto (2 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")[![adam187](https://avatars.githubusercontent.com/u/156628?v=4)](https://github.com/adam187 "adam187 (1 commits)")[![stefanzweifel](https://avatars.githubusercontent.com/u/1080923?v=4)](https://github.com/stefanzweifel "stefanzweifel (1 commits)")[![alexstewartja](https://avatars.githubusercontent.com/u/6935309?v=4)](https://github.com/alexstewartja "alexstewartja (1 commits)")[![grasmash](https://avatars.githubusercontent.com/u/539205?v=4)](https://github.com/grasmash "grasmash (1 commits)")[![maksymilian-bogun](https://avatars.githubusercontent.com/u/3738944?v=4)](https://github.com/maksymilian-bogun "maksymilian-bogun (1 commits)")[![sascha-egerer](https://avatars.githubusercontent.com/u/1651414?v=4)](https://github.com/sascha-egerer "sascha-egerer (1 commits)")

---

Tags

composerphantomjsphantomjs-installationphpheadlessphantomjsbinaries

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jakoch-phantomjs-installer/health.svg)

```
[![Health](https://phpackages.com/badges/jakoch-phantomjs-installer/health.svg)](https://phpackages.com/packages/jakoch-phantomjs-installer)
```

###  Alternatives

[microweber/screen

A PHP Class to interact with PhantomJs and capture screenshot of a webpage

632226.0k1](/packages/microweber-screen)[hybridlogic/phantomjs

A PHP library to execute PhantomJS scripts and return their results.

57158.3k](/packages/hybridlogic-phantomjs)[luka-dev/headless-task-server-php

Helper for sending requests to luka-dev/headless-task-server

109.6k](/packages/luka-dev-headless-task-server-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
