Hyperz Documentation > Knowledgebase > PHP Websites > Initial Setup & First Website

Initial Setup & First Website


This document references as an additional to Installing an EJS Website.

This document will teach you how to install PHP with NGINX.

Table of Contents

Step 1 - Dependencies & Port

First, let's make sure we are up to date on Ubuntu 20.04.

sudo apt update

Now, we need to install PHP on our VPS.

sudo apt-get install php7.4 -y
php --version

Next, we need to change the port that Apache is using (because we don't want apache, we want NGINX.)

Navigate to /etc/apache2/ports.conf.

Now you will want to change where it says Listen 80 to say Listen 8080. This will change the port Apache is listening on from port 80 to listen on port 8080.

Now, we need to change the port inside of /etc/apache2/sites-enabled/000-default.conf.

Navigate to the above directory, and change <VirtualHost *:80> to say <VirtualHost *:8080>.

Now, just restart Apache.

sudo systemctl restart apache2 #SystemD
sudo service apache2 restart #SysVInit

Step 2 - PHP to NGINX Extensions

We need to install the extensions for PHP to properly work with NGINX.

sudo apt-get install php7.4-fpm php7.4-cli php7.4-mysql php7.4-curl php7.4-json -y

Once all the packages are installed, start the PHP7.4-FPM service and enable it to start at system reboot:

systemctl start php7.4-fpm
systemctl enable php7.4-fpm

Step 3 - Folder Creation

First, we need to navigate to your /var/www directory.

Next, lets create a new folder, and you want to just name it your domain. So for example if my domain that I am setting up a PHP website on is https://store.hyperz.net/ then I would want to create a folder in this directory just called store.hyperz.net.

Now, paste in your PHP website files inside of this newly created folder. This includes your index.php and any other folder or files that are apart of your PHP website.

If your website has a configuration file. Feel free to fill that out at this point.

Step 4 - Configuration

Navigate to your /etc/nginx/sites-available/default file.

Add in a new server block for your PHP website:

server {
    listen 80;
    server_name example.com;
    root /var/www/example.com;
    index index.php;

    location ~ .php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        autoindex on;
        autoindex_exact_size on;

Next, we can restart NGINX with sudo systemctl restart nginx.

Now it is time to create an SSL cert so our website can be secure! This is very easy to do as we have already installed Certbot!

Simply run this command in your terminal: sudo certbot --nginx -d example.com after replacing example.com with the domain you intend to create the certificate for.

Make sure you have pointed your domain to your VPS with a DNS A record already!

If it asks you for a redirect option, press 2.

Was this article helpful?

15 out of 29 found this helpful