Setup a Static IP for PHP HTTPS

Learn how to route native PHP HTTP traffic through a QuotaGuard Static IP. Includes full code examples.

Prerequisites

N/A

Instructions

Run example
QUOTAGUARDSTATIC_URL=... php https.rb

Be sure to set QUOTAGUARDSTATIC_URL to your Connection URL from the QuotaGuard Dashboard.

Test in Docker
docker build -t qg-static-php-https-example .
docker run -e QUOTAGUARDSTATIC_URL=... qg-static-php-https-example

Code Samples

https.php
<?php

require 'vendor/autoload.php';

use GuzzleHttp\Client;

if (!getenv('QUOTAGUARDSTATIC_URL')) {
    throw new Exception('Missing environment variable');
}

$quotaguard = parse_url(getenv('QUOTAGUARDSTATIC_URL'));

$client = new Client([
    'proxy' => [
        'http'  => "http://{$quotaguard['user']}:{$quotaguard['pass']}@{$quotaguard['host']}:{$quotaguard['port']}",
        'https' => "http://{$quotaguard['user']}:{$quotaguard['pass']}@{$quotaguard['host']}:{$quotaguard['port']}",
    ],
]);

$response = $client->request('GET', 'https://ip.quotaguard.com');

echo $response->getBody();

?>

Docker File
FROM php:7.4-apache

WORKDIR /app/

# Install dependencies
RUN apt-get update && apt-get install -y \
    curl \
    zip \
    unzip

# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# Install GuzzleHttp
RUN composer require guzzlehttp/guzzle

# Copy PHP script
COPY https.php https.php

CMD [ "php", "https.php" ]