Sample code for 30+ languages & platforms
PHP Requires Chilkat v11.0.0+

Duplicate openssl pkey -in private.pem -pubout -out pubkey.pem

See more OpenSSL Examples

How to output the public part of a private key: Demonstrates how to duplicate this OpenSSL command:
openssl pkey -in private.pem -pubout -out pubkey.pem

Chilkat PHP Downloads

PHP
<?php

use Chilkat2\PrivateKey;
use Chilkat2\PublicKey;

$pkey = new PrivateKey();

// Load the private key from an PEM file:
try {
    $pkey->LoadPemFile('private.pem');
} catch (\Chilkat2\Exception $e) {
    echo $e->getMessage(), "\n";
    exit;
}

$pubKey = new PublicKey();
$pkey->ToPublicKey($pubKey);

try {
    $pubKey->SavePemFile(false, 'pubKey.pem');
} catch (\Chilkat2\Exception $e) {
    echo $e->getMessage(), "\n";

    exit;
}

echo "Success.\n";