Installation
MadelineProto offers multiple installation methods to suit different project setups. Choose the method that works best for you.
Recommended : Use Composer for production projects. The PHAR method is best for quick testing and prototyping.
Quick Start (PHAR)
The fastest way to get started is using the PHAR distribution. This method automatically downloads MadelineProto and handles all dependencies.
Download madeline.php
Create a new PHP file with this code: <? php
if ( ! file_exists ( 'madeline.php' )) {
copy ( 'https://phar.madelineproto.xyz/madeline.php' , 'madeline.php' );
}
require 'madeline.php' ;
$MadelineProto = new \danog\MadelineProto\ API ( 'session.madeline' );
$MadelineProto -> start ();
$me = $MadelineProto -> getSelf ();
$MadelineProto -> logger ( $me );
Run the script
Execute via CLI or browser: The script will download MadelineProto automatically on first run.
Follow login prompts
Enter your phone number or bot token when prompted. A session file will be created to persist your login.
Alpha Version Notice : The PHAR distribution may contain alpha versions. For production, use Composer to install stable releases.
Composer Installation (Recommended)
For production projects, install MadelineProto via Composer to get stable versions and better dependency management.
From Scratch
Starting a new project? Set it up with these commands:
Create project directory
mkdir my-telegram-bot
cd my-telegram-bot
Initialize Composer
composer init --name= "myname/mybot" --type=project --require= "danog/madelineproto:^8.0"
Create your bot file
Create bot.php: <? php
require 'vendor/autoload.php' ;
use danog\MadelineProto\EventHandler\Attributes\ Handler ;
use danog\MadelineProto\EventHandler\ Message ;
use danog\MadelineProto\EventHandler\SimpleFilter\ Incoming ;
use danog\MadelineProto\ SimpleEventHandler ;
class MyBot extends SimpleEventHandler
{
public const ADMIN = "@me" ; // Change this!
public function getReportPeers ()
{
return [ self :: ADMIN ];
}
#[ Handler ]
public function handleMessage ( Incoming & Message $message ) : void
{
$message -> reply ( "Hello from MadelineProto!" );
}
}
MyBot :: startAndLoop ( 'bot.madeline' );
Add to Existing Project
Already have a Composer project? Just add MadelineProto:
composer require danog/madelineproto
Then require the autoloader in your code:
<? php
require 'vendor/autoload.php' ;
use danog\MadelineProto\ API ;
$MadelineProto = new API ( 'session.madeline' );
$MadelineProto -> start ();
Docker Installation
MadelineProto provides official Docker images for multiple platforms.
linux/amd64
linux/arm64
linux/riscv64
CLI Bot (Recommended)
Create bot.php
Create your bot file with event handlers (see examples above).
Create Dockerfile
FROM hub.madelineproto.xyz/danog/madelineproto:latest
COPY bot.php /app/
CMD [ "php" , "/app/bot.php" ]
Build and run
docker build -t my-telegram-bot .
docker run -it --name telegram-bot my-telegram-bot
Web Docker
For web-based bots served via HTTP:
FROM hub.madelineproto.xyz/danog/madelineproto:latest
COPY . /app/
EXPOSE 8080
CMD [ "php" , "-S" , "0.0.0.0:8080" , "-t" , "/app" ]
Using Databases with Docker
To use MySQL, PostgreSQL, or Redis with Docker, use docker-compose:
version : '3.8'
services :
bot :
image : hub.madelineproto.xyz/danog/madelineproto:latest
volumes :
- ./bot.php:/app/bot.php
depends_on :
- redis
command : php /app/bot.php
redis :
image : redis:alpine
volumes :
- redis_data:/data
volumes :
redis_data :
Then configure Redis in your bot:
use danog\MadelineProto\ Settings ;
use danog\MadelineProto\Settings\Database\ Redis ;
$settings = new Settings ;
$settings -> setDb (
( new Redis )
-> setDatabase ( 0 )
-> setPassword ( 'your_password' )
);
MyBot :: startAndLoop ( 'bot.madeline' , $settings );
Verification
Verify your installation by checking the MadelineProto version:
<? php
require 'vendor/autoload.php' ; // or require 'madeline.php';
use danog\MadelineProto\ API ;
echo "MadelineProto version: " . API :: RELEASE . " \n " ;
Version Selection
# Latest stable version (recommended)
composer require danog/madelineproto
# Specific version
composer require danog/madelineproto:^8.0
# Development version
composer require danog/madelineproto:dev-master
The PHAR method always downloads the latest available version from https://phar.madelineproto.xyz/madeline.php. PHAR versions may be alpha/beta releases. Check the actual version after download.
Updating
Composer
composer update danog/madelineproto
PHAR
Delete madeline.php and run your script again - it will download the latest version:
rm madeline.php
php bot.php
Next Steps
Check Requirements Ensure all PHP extensions are installed
Quick Start Guide Build your first bot in minutes
Troubleshooting
Installation fails with memory errors
Increase PHP memory limit: php -d memory_limit=512M composer install
Check Requirements and install missing extensions. On Ubuntu: sudo apt install php8.2-mbstring php8.2-xml php8.2-gmp php8.2-curl
Download manually: wget https://phar.madelineproto.xyz/madeline.php
Or use Composer instead for more reliable installation.
Always verify you’re running PHP 8.2 or higher (64-bit) . Check with: php -v
php -r "echo PHP_INT_SIZE * 8 . ' bit';"