Skip to content

Instantly share code, notes, and snippets.

@Troplo
Created November 20, 2019 04:17
Show Gist options
  • Save Troplo/f334e4eb170a02f3b296853224ee10d6 to your computer and use it in GitHub Desktop.
Save Troplo/f334e4eb170a02f3b296853224ee10d6 to your computer and use it in GitHub Desktop.
TROPLO'S WEBSERVER TUTORIAL
## Installing
### NGINX
First we're going to need to login to your Vultr server via SSH. This can be done via multiple methods. Assuming you've already logged into the "root" user of your Vultr server. We can now get started.
First as root, run the command:
apt install nginx -y
You should see some output. Assuming nginx installed successfully, we can go ahead and move to PHP-FPM.
### PHP-FPM
We're up to installing PHP-FPM. This is how you can achieve this.
Firstly, as with nginx, also applies with PHP-FPM, you need to run the following command:
apt install php-fpm -y
By default this installs php7.2, For this tutorial php7.2 will do.
If you need another version, such as 7.3, you can run:
apt install software-properties-common
add-apt-repository ppa:ondrej/php
apt update
apt install php7.3-fpm
However, I suggest doing the first one because it has less steps, of course if that doesn't work you can attempt the second option. Now that we've installed PHP-FPM successfully. We can move over to installing MariaDB/MySQL.
### MariaDB/MySQL
Now that we've installed the above applications, we can install our database software, Here are the commands that you need to run to install it:
apt install mariadb-server
You may or may not get a prompt asking for a new root password. If you didn't get a prompt, You can read the Configuring > MariaDB/MySQL section of this tutorial.
## Configuring
### PHP-FPM
Now we're onto the configuration section of this tutorial. We're first going to configure PHP-FPM
Out of the box its already configured as we need. So we won't be configuring it in this tutorial.
However the php.ini file can be found here: `/etc/php/7.2/fpm/php.ini` or `/etc/php/7.3/fpm/php.ini` if you followed the php7.3 installation step. That configuration file can be used to change error reporting, max upload size, etc. You can edit the file with a program called `nano` or `vim`. Remember to restart php-fpm whenever you change that file with the command
systemctl restart php7.2-fpm
or
systemctl restart php7.3-fpm
depending on which version you decided to install.
### MariaDB/MySQL
Now onto MariaDB/MySQL. It's a fairly easy configuration, and doesn't require modifying any files.
There is 1 command you'll need to run to secure MariaDB's root account with a password.
When running you should see an output that tells you to enter your current root password, but because you haven't set one yet, you can just press enter. Now you can set a root password. You can answer the rest of the questions to your needs. I recommend entering the answer Y for all the yes and no questions.
### NGINX
Now we can finally configure NGINX. This tutorial will be teaching you how to configure 1 domain for your NGINX configuration, but you can add more if you want.
Firstly you need to edit the file /etc/nginx/sites-available/default
That is the default example configuration file provided by NGINX.
You can edit it with nano, which we will be using today. If it isn't installed you can install it with the command:
apt install nano
Once installed, you can edit the file with the command:
nano /etc/nginx/sites-available/default
Once opened, you should see the file contents, you can navigate through the file with the arrow keys on your keyboard, go to line 39, or find where it says `index index.html index.htm index.nginx-debian.html;` add index.php to the end before the ; it should look something like this: `index index.html index.htm index.nginx-debian.html index.php;`, this allows you to visit folders on your website without including index.php on the end. Now we need to make NGINX to work with PHP-FPM. This can be done on line 57, or where `#location ~ \.php$ {` is. This requires modifying, It should look something like this below, feel free to copy it.
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php7.2-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php7.2-fpm:
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
Once modified. It's now time to save the file, this can be accomplished via doing CTRL + X, Y, then enter. Now you've saved your new NGINX configuration!
Run the command:
systemctl restart nginx
That restarted NGINX, now you can upload your files to /var/www/html where your website directory is. Be sure to delete the file `index.nginx-debian.html`, because that displays the default nginx is installed page. If you want to install phpMyAdmin here are instructions.
### phpMyAdmin
This is an optional step, this is just if you want a panel to setup and add MySQL databases. First step, run this command.
apt install zip unzip -y && cd /var/www/html && wget https://files.phpmyadmin.net/phpMyAdmin/4.9.1/phpMyAdmin-4.9.1-all-languages.zip && unzip phpMyAdmin-4.9.1-all-languages.zip && mv phpMyAdmin-4.9.1-all-languages phpmyadmin && rm -rf phpMyAdmin-4.9.1-all-languages.zip
Yep! That's a long command, but it should do everything automatically. Then you can visit your Vultr Server IP address, example: 192.0.2.1/phpmyadmin, and phpMyAdmin should load and you can login with the login details you set earlier (Username is root by default).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment