Skip to content
ZILLEALI edited this page Jun 19, 2026 · 1 revision

Installation

Requirements

  • PHP 5.4 or newer (the codebase is plain procedural-style OOP, no PHP 8 only syntax is used, so it runs fine on modern PHP too)
  • The sockets-adjacent stream functions, which are part of PHP core (stream_socket_client, fread, fwrite), no extra extension needed for plain connections
  • The openssl PHP extension, only if you plan to connect over api-ssl (see SSL and TLS Connections)
  • Network access from the machine running the script to the router on the API port, usually 8728 for plain API or 8729 for API-SSL

Option 1: Composer

composer require ben-menking/routeros-api

The package uses Composer's classmap autoloading, not PSR-4, so there is no namespace to import. After installing, the global class RouterosAPI is simply available once Composer's autoloader is loaded:

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

$API = new RouterosAPI();

Option 2: Manual include

Since this is a single file with no dependencies, you can skip Composer entirely:

<?php
require __DIR__ . '/routeros_api.class.php';

$API = new RouterosAPI();

This is the same approach used in the examples/ folder in this repository.

Enabling the API on the router

The PHP class is only half the story. RouterOS does not expose the API service by default on a fresh install, and this is the single most common reason a connection silently fails. On the router itself:

/ip service print

Confirm api (port 8728) or api-ssl (port 8729) is enabled and not restricted by an address list that excludes the host you are connecting from. To enable the plain API service:

/ip service set api disabled=no

If you only want API-SSL, leave api disabled and enable api-ssl instead, then read SSL and TLS Connections before writing any PHP.

Also check /ip firewall filter on the router. A default "drop everything not explicitly allowed" input chain will block API connections from anywhere outside the LAN unless you add an explicit accept rule for the API port and source range you are connecting from.

Next step

Continue to Quick Start for a full working connection example.


Documentation contributed by Zill E Ali, Network Engineer and creator of mikrotik-laravel | GitHub | LinkedIn

Clone this wiki locally