Requirements

Before installing YTMusicAPI PHP, ensure your system meets the following requirements:

Requirement Version Notes
PHP 7.4+ Developed and tested on PHP 8.2
Composer 2.0+ For package management
cURL extension - Required for HTTP requests
JSON extension - Required for API communication
Note: While the library is designed to work with PHP 7.4+, it has been developed and thoroughly tested on PHP 8.2. Some examples in the documentation may use PHP 8.0+ features like named parameters.

Composer Installation

The easiest way to install YTMusicAPI PHP is through Composer:

composer require ytmusicapi/ytmusicapi

This will automatically download the library and its dependencies, including the rmccue/requests package used for HTTP communication.

Verify Installation

Create a simple test script to verify the installation:

<?php
require "vendor/autoload.php";

try {
    $yt = new Ytmusicapi\YTMusic();
    echo "YTMusicAPI PHP is installed correctly!\n";
    
    // Test a simple search
    $results = $yt->search("test", limit: 1);
    echo "Search functionality works: " . count($results) . " result(s) found\n";
    print_r($results);
    
} catch (Exception $e) {
    echo "Installation error: " . $e->getMessage() . "\n";
}

Save the file as test-installation.php.

 

Run this script with:

php test-installation.php

Autoloading

YTMusicAPI PHP uses a custom autoloading approach to stay close to the original Python structure. The main class and all mixins are automatically included when you include the Composer autoloader.

<?php
require "vendor/autoload.php";

// Now you can use any part of the library
$yt = new Ytmusicapi\YTMusic();
$results = $yt->search("your query");
Note: In order to stay as close as possible to the original Python structure, the library bypasses standard PSR-4 autoloading to maintain compatibility with the Python version's structure. All necessary files are included automatically.

Authentication

To access your personal YouTube Music data (playlists, library, history), you need to authenticate your requests. Please see the authentication page for more information.

Troubleshooting

Common Issues

Class 'Ytmusicapi\YTMusic' not found

Solution: Make sure you've run composer install and included the autoloader:

require "vendor/autoload.php";

cURL Error: Could not resolve host

Solution: This is usually a network connectivity issue. Ensure your server can reach YouTube Music servers and that cURL is properly configured.

HTTP 403 Forbidden Errors

Solution: Google has been stricter with bot detection. Try using authentication or consider if you're running on a commonly flagged hosting provider, which is most of them.

SSL Certificate Issues

Solution: Update your CA bundle or configure cURL to handle SSL properly:

// If you encounter SSL issues, you may need to configure the session
$session = new \WpOrg\Requests\Session();
$session->options["verify"] = "/path/to/cacert.pem";
$yt = new Ytmusicapi\YTMusic(null, null, $session);

Getting Help

If you encounter issues not covered here:

Important: This PHP port is currently behind the Python version in updates. The Python version may have solutions to issues that haven't been ported yet.