Use BitWasp Bitcoin-php library
https://github.com/Bit-Wasp/bitcoin-php
<?php
use BitWasp\Bitcoin\Bitcoin;
use BitWasp\Bitcoin\Key\PrivateKeyFactory;
$network = Bitcoin::getNetwork();
$privateKey = PrivateKeyFactory::create(true);
$publicKey = $privateKey->getPublicKey();
$address = $publicKey->getAddress(); // returns AddressInterface
echo $address->getAddress($network); // prints address for $network as string
If you want to create Bitcoin address from Public key string check documentation for Factory classes
or newer versions:
<?php
use BitWasp\Bitcoin\Bitcoin;
use BitWasp\Bitcoin\Address\AddressCreator;
use BitWasp\Bitcoin\Key\PrivateKeyFactory;
use BitWasp\Bitcoin\Key\KeyToScript\Factory\P2pkhScriptDataFactory;
$network = Bitcoin::getNetwork();
$privateKey = PrivateKeyFactory::create(true);
$publicKey = $privateKey->getPublicKey();
$addrCreator = new AddressCreator();
$factory = new P2pkhScriptDataFactory();
$scriptPubKey = $factory->convertKey($publicKey)->getScriptPubKey();
$address = $addrCreator->fromOutputScript($scriptPubKey); // returns AddressInterface
echo $address->getAddress($network); // prints address for $network as string