Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use PHP to control a headless Chrome or Chromium browser: install the chrome-php/chrome Composer package, make a browser executable available on the Linux host, navigate to the page, wait for the page state you need, save the screenshot, and close the browser. A PHP screenshot library does not render websites by itself; it drives a browser engine that does.

What you need on the Linux server

The direct PHP route covered here is chrome-php/chrome, which controls Chrome or Chromium. The project states compatibility with PHP 7.4–8.5 and Chrome/Chromium 65 or later, and says it is tested on Linux. Treat those as project-stated requirements for the documented package; check the version you install before deploying.

  • A Linux environment where the PHP process can run.
  • Composer and the chrome-php/chrome package.
  • A Chrome or Chromium executable installed on the host and accessible to the PHP process.
  • A writable destination for the image, plus enough disk space and permissions for the browser process to run.

Install the package from your project directory:

composer require chrome-php/chrome

The library looks for a browser path in CHROME_PATH and otherwise attempts to find Chrome or use chrome. If your distribution installs Chromium under a different executable name or location, provide the executable explicitly when creating the browser factory. The exact path depends on how Chrome or Chromium was installed on your server.

Capture a basic screenshot from PHP

This example opens a page, waits for navigation, saves a PNG, and closes the browser even if navigation or capture throws an error:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Lenovo Business Laptop - Linux Mint (Cinnamon) - Intel i5-1335U, 16GB RAM, 256GB SSD, 15.6" FHD 1920x1080 Display, Full Keyboard, Fast Charging
  • Intel Core i5-1335U Processor (12M Cache, 12 Threads, up to 4.6 GHz) - 256GB Solid State Drive - 16GB DDR4 SDRAM
  • 15.6" FHD (1920x1080) Non-Touch Anti-Glare Display - Intel UHD 620 Integrated Graphics - Stereo Speakers
  • 720p HD Webcam with Privacy Shutter. Integrated Microphone - Intel Dual Band Wireless-AC (2x2) 8265, Bluetooth Version 4.2
  • I/O Ports: 2x USB 3.0, 1x USB 3.1 Type-C 3.1, Headphone/Mic Combo Port, 4-in-1 Card Reader, HDMI, Kensington Mini-Lock Slot
  • Linux Mint (Cinnamon) 64-Bit - Keyboard with Full NumberPad - Fast Charging
<?php

require __DIR__ . '/vendor/autoload.php';

use HeadlessChromiumBrowserFactory;

$browserFactory = new BrowserFactory();
$browser = $browserFactory->createBrowser();

try {
    $page = $browser->createPage();
    $page->navigate('https://example.com')->waitForNavigation();
    $page->screenshot()->saveToFile(__DIR__ . '/screenshot.png');
} finally {
    $browser->close();
}

Replace the URL and output path with values appropriate to your application. The PHP process must have permission to write to that path. If the screenshot is an artifact for CI or another workflow, put it somewhere that workflow actually collects.

Why the cleanup block matters

Chrome is a separate process. The finally block closes it after a successful capture and also when an exception interrupts the work. Without cleanup, repeated jobs can leave browser processes behind and consume server resources.

Choosing an explicit browser executable

If automatic discovery fails, pass the installed executable path using the factory’s executable argument. For example, adapt this pattern to the actual path on your host:

$browserFactory = new BrowserFactory('/path/to/chrome-or-chromium');

Do not assume that every Linux image uses the same binary name or location. Verify the path in the same runtime environment that launches PHP, particularly in containers and service accounts.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
HP 17 Business Laptop - Linux Mint Cinnamon - Intel Quad-Core i5-10210U, 32GB RAM, 1TB PCIe NVMe SSD + 1TB Storage HDD, 17.3" Inch HD+ (1600x900) Display
  • Intel Core i5-10210U (up to 4.2GHz) - 1TB PCIe NVMe + 1TB HDD - 32GB DDR4 SDRAM
  • 17.3" HD+ (1600x900) Display, Intel UHD Graphics 620
  • Built in HD 720p Webcam with Microphone - Bluetooth Version4.2
  • I/O Ports: 2x USB 3.1 (Data Only), 1x USB 2.0, 1x HDMI, 1x Headphone/Microphone Combo Jack
  • Linux Mint Cinnamon 64-Bit - 6-Row Keyboard w/ Full Numberpad

Wait for the page state you intend to capture

waitForNavigation() is a useful baseline, but it only establishes that the navigation event completed. A modern page may still be fetching data, rendering a client-side component, loading images, or showing a transient state. Choose a readiness condition that represents the visual state your screenshot is supposed to show.

  1. Navigate to the target URL.
  2. Wait for navigation or another suitable browser event.
  3. For dynamic content, wait for an application-specific signal, such as the expected heading or component becoming visible.
  4. Capture only after the intended state is present; set timeouts so a missing condition does not leave a job waiting indefinitely.

The Playwright PHP guide recommends making page state explicit and checking a meaningful condition such as an expected heading’s visibility. There is no universal wait rule: the right condition depends on the site. A screenshot records one moment, not the interaction sequence that led to it.

Choose viewport, full-page, or clipped output

Match the capture scope to the purpose. A viewport capture records what fits in the browser window; a full-page capture includes content beyond the fold; a clipped capture limits the image to a region. The library documents viewport sizing, rectangular clipping, and full-page capture. Its full-page example uses getFullPageClip() together with captureBeyondViewport => true.

Capture type Use it when Implementation consideration
Viewport You need the visible browser-sized state, such as a responsive layout check. Set a consistent viewport when comparing captures or targeting a specific screen size.
Full page Below-the-fold material matters, such as a long article or landing page. Enable full-page clipping and capture beyond the viewport. Very long pages can create large artifacts and may expose more sensitive content.
Clipped region You need a specific rectangular area rather than the whole page. Define the rectangle in the page coordinate space and verify it still targets the intended content at the selected viewport.

For a component-only result, use the library’s clipping or element-related capabilities as appropriate to the version you installed. The available documentation establishes rectangular clipping, but not a universal selector recipe for every package release; consult that release’s API documentation rather than assuming an option name.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Panasonic Toughbook CF-31 MK5 Rugged Laptop, 13.1in i5, 8GB 256GB (Renewed)
  • [ULTRA-RUGGED DESIGN] MIL-STD-810G and IP65 certified. Built to survive 6-foot drops, heavy rain, and extreme vibrations. Features a magnesium alloy chassis with an integrated carry handle for maximum portability
  • [4G LTE - WORK ANYWHERE] Integrated 4G LTE Multi-Carrier Mobile Broadband. Stay connected to the internet in remote areas or on the road without relying on Wi-Fi or phone hotspots. True mobile freedom for field professionals
  • [1200-NIT SUNLIGHT READABLE] 13.1" XGA Touchscreen with CircuLumin technology. At 1200 nits, it is nearly 4x brighter than a standard laptop, ensuring perfect visibility under direct, intense sunlight
  • [LINUX UBUNTU PRE-INSTALLED] Fast, secure, and bloatware-free. Optimized for developers, network engineers, and diagnostic software that thrives in a stable, open-source environment
  • [LEGACY SERIAL PORT] Features a native RS-232 Serial Port, HDMI, and USB 3.0. Essential for connecting directly to industrial machinery, CNCs, and automotive diagnostic tools without unreliable adapter

Set output format and image quality

The documented screenshot API supports PNG, JPEG, and WebP, with PNG as the default. The quality option applies to JPEG or WebP, not PNG. Choose PNG when lossless detail or sharp text is important; JPEG or WebP can be useful when file size matters, but check that the chosen quality preserves the details your use case needs. The screenshot can be saved directly to a file.

Keep the format consistent when screenshots are used for visual comparisons. A format change, browser change, font change, or different rendering environment can alter the resulting pixels even if the page looks equivalent to a person.

Deployment, reliability, and security considerations

Browser installation and permissions

Install the browser as well as the Composer package. Confirm that the PHP worker can execute it and that the process can write the output file. A command that works in an interactive shell may fail under PHP-FPM, a queue worker, or a container if that service has a different environment or permissions.

Headless settings, timeouts, and containers

The project exposes options for headless mode, startup and communication timeouts, viewport or window sizing, proxy configuration, and a noSandbox option. The project describes noSandbox as useful in a Docker container; that is not a general security recommendation. The reviewed documentation does not establish a complete production security policy for services that visit arbitrary URLs. Restrict which URLs your application can request and determine an isolation policy suitable for your deployment.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Lenovo V15 Gen 4 - Business Laptop - AMD Ryzen 5 7430U - 15.6" FHD Display - 8GB RAM - 512GB SSD Storage - Integrated AMD Radeon™ Graphics - Webcam Privacy Shutter - Business Black
  • THE POWER TO STAY PRODUCTIVE – Looking to make your everyday work and home life more manageable without breaking the bank? The Lenovo V15 Gen 4 offers long-term reliability with top-of-the-line features to make you your most productive self.
  • CRUSH YOUR TO-DO LIST – The AMD Ryzen CPU pairs quiet performance and enhanced operating power to crush your high-demand workday. It optimizes performance and allows for seamless multitasking.
  • TRUE-TO-LIFE VISUALS – The 15.6” FHD IPS display is anti-glare with 300 nits brightness to see your best outside or in. Its 88% screen-to-body ratio makes viewing detailed applications like spreadsheets a breeze.
  • SEAMLESS COLLABORATION – Lenovo Smart Appearance enhances your camera effects to protect your privacy and to make you the focus of every video conference. Intelligent noise cancelation minimizes distraction and Dolby Audio provides an elegantly sonorous experience.
  • BUILT TO WITHSTAND – Built for military-grade toughness, the V15 Gen 4 is tested to withstand harsh temperatures, pressure, humidity, vibrations and more. Keep your work safe from the board room to your living room and everywhere in between.

Page variability and test evidence

Visual output can vary with viewport, fonts, animations, page data, browser version, and rendering environment. Control those variables when comparing screenshots. A screenshot alone does not prove that a flow worked normally; preserve a trace or another interaction record when the sequence matters.

Protect the resulting files

Pages can show credentials, personal data, or other secrets. Treat images as potentially sensitive artifacts: restrict access, avoid retaining captures longer than necessary, and ensure logs or public artifact locations do not expose them.

Alternatives and trade-offs

Approach Runtime fit When it makes sense Trade-off
ScreenshotNeo Website screenshot API and MCP server; a PHP application can call the API over HTTP. Use it when you want a managed capture call rather than installing and operating a browser alongside PHP. It is a service call rather than a local browser process. Its documented endpoint and options are at ScreenshotNeo documentation.
chrome-php/chrome PHP application plus Chrome or Chromium executable. Use it when the application should control the browser directly from PHP and can install the browser on the Linux host. You operate the browser process, its runtime environment, and output handling.
Playwright PHP The Playwright PHP examples page states PHP 8.2+ and Node.js 20+ prerequisites and shows installing the Composer package and Chromium. Consider it when your team already uses Playwright’s APIs and its documented runtime requirements fit. It adds the documented Node.js prerequisite alongside PHP. Verify requirements against the current release.
Puppeteer Node.js library, not a direct PHP API. Consider it when a separate Node worker or service is acceptable. It is not a drop-in PHP package; the application needs a Node-based capture component or service.

No measured throughput, resource-use, or reliability comparison is established for these options. Reusing a persistent browser process may be suitable for some workloads, but do not assume a speed or resource advantage without testing under your own load, pages, and hosting limits.

Troubleshooting common failures

  • Browser executable not found: Chrome or Chromium may be absent, installed under another name, or invisible to the PHP service environment. Install it and set the executable path explicitly or configure CHROME_PATH.
  • PHP can run the script but cannot save the image: the output directory may not exist or may not be writable by the PHP process. Use a writable directory and check permissions as the actual service user.
  • Screenshot is blank or missing dynamic content: navigation may have finished before the page rendered the relevant component. Wait for a meaningful page condition rather than relying only on navigation completion.
  • Capture waits too long: a navigation or readiness condition may never occur, or the site may be slow. Set an appropriate timeout, handle timeout exceptions, and distinguish a genuinely missing page state from a slow response.
  • Full-page image cuts off content: a viewport capture may have been used instead of full-page settings. Use the full-page clip and enable capture beyond the viewport as documented by the library.
  • Output differs between runs: fonts, animations, data, viewport, browser version, or rendering environment may have changed. Stabilize these inputs and capture the same page state before comparing.
  • Browser behaves differently in a container: verify executable path, runtime permissions, startup configuration, and timeouts in the container itself. Do not treat disabling the sandbox as a blanket fix or security policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

Instead of installing and managing Chrome or Chromium on the Linux server, PHP can request a capture from ScreenshotNeo’s screenshot API. The following is a complete PHP example using the documented endpoint and a 90-second request timeout; see the API documentation for parameters and response details.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Lenovo IdeaPad Slim 3 Linux Laptop, 15.6" FHD Touchscreen Laptop, 8-Core AMD Ryzen 7 5825U, 16GB RAM, 512GB SSD, Keypad, SD Card Reader, Stylus Pen + External Portable SSD + USB Hub, Linux Ubuntu OS
  • Powerful Linux Laptop: This IdeaPad Slim 3 Laptop comes pre-installed with Ubuntu Linux, offering fast performance, robust security, and a clean, user-friendly experience. Enjoy full customization, seamless hardware compatibility, and access to thousands of open-source apps. Whether you're working, creating, or coding, it's built to keep up with everything you do.
  • A Multitasking Master: The latest AMD Ryzen 7 5825U processor (up to 4.5 GHz) delivers powerful performance with 8 cores and 16 threads for smooth multitasking. Integrated AMD Radeon Graphics provide crisp visuals for streaming, browsing, photo editing, and casual gaming. With smart machine intelligence, it adapts to your needs for a fast, responsive experience.
  • 15.6" Full HD Display: The IdeaPad Slim 3 boasts an 88% screen-to-body ratio for a floating, edge-to-edge visual experience. TÜV Low Blue Light certification reduces eye strain, making it perfect for long work or study sessions.
  • Military-Grade Durability: The smart IdeaPad Slim 3 combines portability and durability, letting you work, study, and play on the go. With a profile 10% slimmer than the previous generation, it's lightweight yet military-grade rugged, ready for anything, anywhere.
  • Versatile Connectivity: Enjoy the security of a built-in webcam with a privacy shutter. Connect effortlessly with multiple ports: 2x USB A, 1x USB C, 1x HDMI, 1x SD Card Reader, 1x Headphone/Microphone combo. Bundle comes with Stylus Pen, 256GB Portable SSD and 5-in-1 Docking Station.
<?php

$url = 'https://example.com';
$query = http_build_query([
    'access_key' => 'YOUR_API_KEY',
    'url' => $url,
]);

$ch = curl_init('https://api.screenshotneo.com/v1/shot?' . $query);
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 90,
]);

$image = curl_exec($ch);
if ($image === false) {
    $error = curl_error($ch);
    curl_close($ch);
    throw new RuntimeException('Screenshot request failed: ' . $error);
}

$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);
if ($status < 200 || $status >= 300) {
    throw new RuntimeException('Screenshot API returned HTTP ' . $status);
}

file_put_contents(__DIR__ . '/screenshot.webp', $image);
  • Cookie and consent banners, newsletter popups, and chat widgets are removed before the shot; each cleanup step can be turned off.
  • Bot checks or CAPTCHAs, blank pages, failed loads, timeouts, and cache hits are not billed; the response includes page-verdict and billing headers.
  • An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients.
  • The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free plan to try 1,000 screenshots a month without a card.

Frequently Asked Questions

Does the PHP process itself render a website?

No. The PHP library controls Chrome or Chromium, which renders the page.

Can I use a screenshot to prove which actions occurred?

No. It records a visual state; use a trace or another interaction record when the action sequence matters.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.