Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running your first OT on Ubuntu Linux #2

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
178 changes: 178 additions & 0 deletions running-your-first-ot-server/setup-webserver-linux.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
# Setting up your ubuntu linux server
guiding to setup your very own ubuntu linux server with a webserver plus the ability to deploy your tfs server
Ralumbi marked this conversation as resolved.
Show resolved Hide resolved

> We are not responsible for the mistakes you make
Ralumbi marked this conversation as resolved.
Show resolved Hide resolved

# Getting started
Rent a ubuntu server 18.04 or higher from a trusted hosting company such as ovh.com or install for the sake of learning experience ubuntu server 18.04 or higher on another computer or if you are on windows use virtualbox to get your ubuntu server.
Ralumbi marked this conversation as resolved.
Show resolved Hide resolved

Once you're set we will start by accessing our server. If you're on windows you should get putty(click here), if you're on macOS or Linux you can use the terminal which is standard available. With putty just follow the screen ( insert your domain/ip-address and click ok ) for macOS and linux users type:

```bash
ssh username@domain/ipaddress
```
`username example => root
domain/ipaddress example => yourdomain.com or 127.0.0.1`

Now you will be prompted for your password (if in putty you will be prompted for the password as soon you click on Open) Insert your password and presh enter (you will not see what you type, so make sure you type your password in the right order). Now we are in our server :)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PuTTY misspelled
Missing full stop at the end of sentence.
presh -> press


## Update and Upgrade the system
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing newline after header

The first thing we will do is updating our ubuntu server with the following command
```bash
sudo apt update && sudo apt upgrade -y
```
We are using 'sudo' since I do not know if you're running as root user or as regular user. When you're logged in as regular user. No problem! Just enter your password when the terminal asks for your password. With the command above you will update the connected repository's the server is connected to and when the server is done updating the repository's it will directly upgrade all the packages which were updated.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something here doesn't flow/make sense.
The guide should specify whether to work as root or regular user.


# Installing the webserver

Now we will get to the more difficult part of the entire server setup, installing nginx, php-fpm, mariadb-server with phpmyadmin.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Omit Now we will get to the more difficult part of the entire server setup - not informative.

```bash
sudo apt install nginx php-fpm mariadb-server -y
```
The installation process is now triggered.When this is finished we will install phpmyadmin to handle our database server (which is mariadb)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space, capitalization (MariaDB)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the part as its not necessary to be there.

```bash
sudo apt install phpmyadmin -y
```
Now we are set to get some configurations going!

## Configuring the webserver
First we want to know which version of php-fpm is installed we will check this by writing the following command in the terminal
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Package names should be marked as "code" with the tilde, e.g.: php-fpm

```bash
sudo php -v
```
The output will be looking something similar as this (I am using ubuntu 19.10 here which uses php version 7.3 as default. If you're running on a server you most likely run on 18.04 lts or with the newest version 20.04 lts):

![alt text](https://worldofcoding.net/github-img/otland-gitbook/phpversion.png "phpversion")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this website? It should ideally be just text, let's avoid images of text.


Second we want to do is enabling php in our nginx server and setting the configuration just as we want. So we will be going to edit our nginx config. Now we need to install a command line text editor called "vim". After that we installed it we will directly open the configuration file.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nano is easier than vim but it's just a matter of preference.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I struggle with nano 🔢

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless you know your audience already knows vi, nano is the safe bet. The audience that already knows vi probably wouldn't need this portion of the guide in the first place.

Though, if you are aiming for the neophytes and you know they are using modern systems, such as Ubuntu 20.04LTS, micro should take precedence over nano.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP not php

```bash
sudo apt install vim -y && sudo vim /etc/nginx/sites-available/default
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to chain commands, just put them in two separate lines.
Explaining what && does is unnecessary here, so let's just not use it.

```

Now sit straight up and read carefully on what we're going to do. I am going to give you a few options in the configuration. Underneath here you will find the default configuration file of nginx. ( I only took the part of the config file we are in need to use and left out all the comments which we do use in this tutorial )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now sit straight up and read carefully on what we're going to do.
While funny, this is meta-text and doesn't actually contribute anything. Let's avoid unnecessary prose.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed it.


## Changing the web-root
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally this section is not "necessary" as most people and guides do indeed keep the web root in /var/www/ / /var/www/html/ and rarely ever people need to put more than one "website" on a VPS for OTS.


We can change the 'root' directory of the website folder, if you're only using your server as root leave it in '/var/www/html'. When using it as for example 'john' you can change the directory to your default directory when you come when you login which is: '/home/john' in the default directory of john you can do 'mkdir www' to create a directory for the website and set: '/home/john/www' on line '5' instead of '/var/www/html'.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Linux, the term in use is directory, not folder. Since this is technical documentation, you have to try to use proper terms.


## Configuring php

I already enabled php here by writing 'index.php' on line number '24'. I've uncommented the php location settings we need to use. To make it easy and understanding I made own comments for you guys to know which lines to comment and uncomment, depending on which ubuntu server version you are running ( and assuming you're using ubuntu server 18.04 lts ).
```bash
server {
listen 80 default_server;
listen [::]:80 default_server;

root /var/www/html;

# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;

server_name _;

location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}

# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
################## UBUNTU 18.04 LTS ##################
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
################## UBUNTU 20.04 LTS ##################
# fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;

}

}

```
Now we have to save the file and quit the file, we do this the following way:
`CTRL+C` After that you will just write `:wq` press enter and we have saved and quit the file :)

We are set with the entire webserver now and so its time to check if we actually did everything as we supposed to do, but first we have to restart our web features. We do this with the following commands:
`Change the number of the php-fpm version to one you're using!!!`
```bash
sudo systemctl restart nginx
sudo systemctl restart php7.2-fpm
```
Lets open our browser and goto your ip-address and see how wonderful you are!
Your very own setup and configured server!

# Setup the database user + phpmyadmin

We need to create ourselves a mysql admin account. We will be doing this the following way. Please follow the steps carefully :)

```bash
sudo mariadb
```
![alt text](https://worldofcoding.net/github-img/otland-gitbook/mariadb.png "mariadb")
###### You are inside the database right now!

We will be creating the user 'otadmin' with the password of 'otadminpassword', change these values to what you want it to be!
```bash
create user 'otadmin'@'localhost' identified by 'otadminpassword';
grant all privileges on *.* to 'otadmin'@'localhost';
flush privileges;
exit;
```
Insert these lines one by one.
Now we have setup our database superuser :)

## Configure phpmyadmin
Setup phpmyadmin to access your database via the browser.

Insert the following configuration in a new file inside the nginx folder. The following command will create the file and when you are in insert the configuration posted below.
( same as for the webserver nginx configuration I have made comments for the ubuntu versions inside the php location )
`sudo vim /etc/nginx/sites-available/phpmyadmin`
```bash
server {
listen 2344;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this port?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just took a random port, can be changed to what you desire.

server_name _;
root /usr/share/phpmyadmin;

add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";

client_max_body_size 256M;
error_page 404 @notfound;

location / {
index index.html index.php;
try_files $uri $uri/ /index.php?$args;
}

location ~* \.(gif|jpg|jpeg|png|bmp|js|css)$ {
expires max;
}

location ~ \.php$ {
include snippets/fastcgi-php.conf;

################## UBUNTU 18.04 LTS ##################
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
################## UBUNTU 20.04 LTS ##################
# fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;

}

location @notfound {
return 404 "You're not browsing correctly.";
add_header Content-Type text/plain always;
}

}
```
Now we have to save the file and quit the file, we do this the following way:
`CTRL+C` After that you will just write `:wq` press enter and we have saved and quit the file :)

Now we have to enable the phpmyadmin configuration for nginx we do that by running the next command:
`sudo ln -s /etc/nginx/sites-available/phpmyadmin /etc/nginx/sites-enabled/phpmyadmin`

Finally restart the nginx server with `sudo systemctl restart nginx` and we will be able to access phpmyadmin by http://youripordomain:2344 login with the database username and password we've created.