LinuxWeb Servers

How to install PHP Proxy server Ubuntu and Debian

PHP Proxy will allow you to host a proxy service on a VPS or Dedicated server. It’s not a complicated setup and this article will guide you through the process. A Proxy is a way to circumvent blocks put in place by ISPs. This could be a block by an ISP or government. You visit the proxy over HTTPS, enter the website URL and the proxy server will grab the website for you and display it. The IP of the proxy server is shown to the website. Your IP is kept hidden. Unlike other Proxy software like Squid Proxy, PHP Proxy provides an interface to type URLs into. This guide details how to install PHP Proxy in a Linux Server.

Most Proxy services don’t keep logs of activity and we’re not going to either. We use this guide to set up a basic proxy service at prox.onl. It’s spread over multiple geographical locations. The actual website for the proxy is not pretty. It’s just designed as a test.

Install Nginx and PHP

This guide assumes you have a Debian NVMe VPS running Debian 11 or Debian 12. You can use this guide to install PHP Proxy on an Ubuntu server. As the root user, run the commands below. Your Proxy server should have a hostname that resolves to it.


# Run installer. If using Debian 9/Ubuntu 18, install php7.0. If using a newer OS # install a newer PHP (apt install php8.1 php8.1-fpm etc)

apt install nginx
apt install apache2
apt install php7.0 php7.0-fpm php7.0-curl php7.0-mbstring php7.0-xml php7.0-zip
systemctl enable nginx
systemctl enable php7.0-fpm

# Install Composer

apt install composer

Install PHP Proxy Linux

So now that you have NGINX and PHP installed, it’s time to install PHP Proxy. But first, we should remove the default HTML files.

rm /var/www/html/*

Next, use Composer to set up PHP Proxy. The files will be deployed to the /var/www/html folder. But if you want to point the files to a different location. Update the path.

composer create-project athlon1600/php-proxy-app:dev-master /var/www/html

At this point, we need to allow NGINX access to the files and folder. We CHOWN the folder with the -R flag

chown -R www-data:www-data /var/www/html/

Configure NGINX

So now we need to make some changes to NGINX so it knows what domain name we want to use and where the files for this domain name are located. We already know they are located at /var/www/html. First, we need to create a configuration file. Create the file, switching the name of the file for your domain or subdomain.

nano /etc/nginx/sites-available/uk.prox.onl

And inside the file, paste the below code.

server {
         listen 80;
         root /var/www/html;
         index index.php index.html index.htm index.nginx-debian.html;
         server_name uk.prox.onl www.prox.onl;
         location / {
             try_files $uri $uri/ =404;
        proxy_busy_buffers_size   512k;
        proxy_buffers   4 512k;
        proxy_buffer_size   512k;
        fastcgi_connect_timeout 60;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;

         }
   location ~ \.php$ {             
          include snippets/fastcgi-php.conf;             
          fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;     
          } 
       add_header X-Content-Type-Options nosniff;
       add_header X-Frame-Options "SAMEORIGIN";
       add_header X-XSS-Protection "1; mode=block";
   
    location ~ /\.ht {
          deny all;
          }
}

NOTE- Modify the following sections. If PHP 7.4 is installed, there is no need to modify the fastcgi_pass unix section. But If you use a different PHP version, update the path to the FPM socket. For PHP 8.1 it’s usually /var/run/php/php8.1-fpm.sock. If you get this bit wrong, you will see 503 errors when visiting the proxy server.

  • server_name
  • fastcgi_pass unix:

We’ve added some additional PHP-FPM settings to this article since it was written. These will help prevent errors.

Enable Configuration

Now we need to disable the default configuration and enable the new confirmation we just created. If you want to use SSL, don’t worry, we will configure this last. So use the commands below to unlink the default configuration and link the new one. Update the command with your domain name.

# Unlink Default config
unlink /etc/nginx/sites-enabled/default

# Link new config
ln -s /etc/nginx/sites-available/uk.prox.onl /etc/nginx/sites-enabled/

# Reload NGINX
systemctl reload nginx 

You should now have a working proxy. Visit your domain name and try it out. It’s likely you will want to configure an SSL so, let’s finish up with that.

Configure PHP Proxy to use SSL

Configuring servers with an SSL used to be tedious but with Certbot it became a lot easier. With NGINX it’s even easier because we can do everything automatically. Let’s get started.

Install Certbot

Install the dependencies for Certbot and Certbot itself.

apt install certbot python3-certbot-nginx

Next, generate an SSL. You would enter your domain name or subdomain or both. We are using a subdomain so we just need our certificate to cover uk.prox.onl.

sudo certbot --nginx -d uk.prox.onl

And finally, to send all traffic to SSL. Select option 2 which is displayed in the console now. So if you visit your site now, the connection should be rerouted to SSL. Certbot will renew the certificate when required. That’s it. Installed completed. Looking for a High Availability VPS Server?

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button