Skip to main content

Requirements

Before installing libphonenumber for PHP, ensure your environment meets these requirements:
  • PHP 8.1 to 8.5 - The library supports all current PHP 8.x versions
  • mbstring extension - Required for proper string handling
The library will be updated to use supported versions of PHP without major version bumps.

Install with Composer

The recommended way to install libphonenumber for PHP is via Composer:
composer require giggsey/libphonenumber-for-php
This command will:
  • Download the library and its dependencies
  • Set up PSR-4 autoloading automatically
  • Make all classes available under the libphonenumber\ namespace
Composer will automatically handle the required dependency giggsey/locale.

Alternative: Lite Version

If you only need core phone number parsing, validation, and formatting functionality, consider using the lite version for a smaller package size:
composer require giggsey/libphonenumber-for-php-lite
The lite version excludes additional features like geocoding, carrier mapping, and timezone mapping. Use the standard version if you need these capabilities.

Manual Installation

If you’re not using Composer, you can manually install the library:
  1. Download the source code from GitHub
  2. Set up a PSR-4 compliant autoloader
  3. Manually install dependencies:
Manual installation is not recommended. Use Composer to ensure all dependencies are properly managed and up-to-date.

Verify Installation

After installation, verify everything is working by creating a simple test script:
<?php
require 'vendor/autoload.php';

use libphonenumber\PhoneNumberUtil;

$phoneUtil = PhoneNumberUtil::getInstance();
echo "libphonenumber for PHP is installed successfully!\n";
If you see the success message, you’re ready to start using the library!

Next Steps

Quick Start

Learn how to parse, validate, and format phone numbers

PhoneNumberUtil Reference

Explore all available methods and features

Build docs developers (and LLMs) love