-
Notifications
You must be signed in to change notification settings - Fork 23
Install on Ubuntu 18.04
To complete this tutorial, you will need:
*An Ubuntu 18.04 server, with a non-root user with sudo
access.
- Make sure you don’t have Apache or any other web server running on port 80 or 443.
- Update your system:
sudo apt update && sudo apt upgrade
.
Nginx is available in Ubuntu repositories, so you can easily install it using apt
package management.
sudo apt install nginx
On Ubuntu 18.04, Nginx is configured to start running upon installation. You can check the status of the service with the following command:
sudo systemctl status nginx
The output will look something like this:
nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2018-04-29 06:43:26 UTC; 8s ago
Docs: man:nginx(8)
Process: 3091 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 3080 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 3095 (nginx)
Tasks: 2 (limit: 507)
CGroup: /system.slice/nginx.service
├─3095 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
└─3097 nginx: worker process
Assuming you are using UFW
to manage your firewall, you’ll need to open HTTP (80
) and HTTPS (443
) ports.
Enable this by typing:
sudo ufw allow 'Nginx Full'
You can verify the change by running:
sudo ufw status
The output will look something like the following:
Status: active
To Action From
-- ------ ----
22/tcp ALLOW Anywhere
Nginx Full ALLOW Anywhere
22/tcp (v6) ALLOW Anywhere (v6)
Nginx Full (v6) ALLOW Anywhere (v6)
Install the MySQL package with the following command:
sudo apt install mysql-server
Once the installation is completed, the MySQL service will start automatically.
To check whether the MySQL server is running, type:
sudo systemctl status mysql
You'll see output similar to the following:
mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2018-06-20 11:30:23 PDT; 5min ago
Main PID: 17382 (mysqld)
Tasks: 27 (limit: 2321)
CGroup: /system.slice/mysql.service
`-17382 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid
Next, we need to remove some defaults that are dangerous to use in a production environment. To do this, we have to run the script called "mysql_secure_installation"
mysql_secure_installation
It will prompt you for the root password you set up during installation. then, you will be asked a series of questions, beginning with if you'd like to change the root password.
You should answer "Y" (for yes) to all of the remaining questions.
At this point, your database system is now set up and you can move on to installing PHP and Configuring Nginx to Use the PHP Processor.
Since Nginx doesn’t have a built-in support for processing PHP files, so we need to install a separate application such as PHP FPM which will handle PHP files.
To install the PHP and PHP FPM packages run the following command:
sudo apt install php-fpm php-mysql php-cli php-mbstring php-zip
Once the installation is completed, you can check the status of the PHP FPM service with:
systemctl status php7.2-fpm
Before installing Composer, you'll need to install the necessary dependencies. To do so, run:
sudo apt install curl unzip
Make sure you're in your home directory, then retrieve the installer using curl:
cd ~
curl -sS https://getcomposer.org/installer -o composer-setup.php
Next, we need to verify the data integrity of the script by comparing the script SHA-384 hash with the latest installer hash found on the Composer Public Keys / Signatures page. Copy the hash from that page and store it as a shell variable:
HASH=93b54496392c062774670ac18b134c3b3a95e5a5e5c8f1a9f115f203b75bf9a129d5daa8ba6a13e2cc8a1da0806388a8
Now run the following command to verify that the installation script is not corrupted:
php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
If the hashes match, you will see the following output:
Installer verified
You can confirm that you have installed Git correctly by running the following command
composer
Download and install Git using the apt
package manager:
sudo apt install git
To test your installation, run:
git --version
Install Node.js from the repositories:
sudo apt install nodejs
Install npm
(Node.js package manager):
sudo apt install npm
By following all the previous instructions, you now have all the basic server dependencies required for the application installation.
To create a MySQL database for our application and a user associated with it, you need to access the MySQL client using the MySQL root account:
mysql -u root -p
Enter the appropriate password, which should be the same password used when running mysql_secure_installation
.
Create database with:
CREATE DATABASE vultrdash_db;
You have successfully created your application database.
Execute the following command to create a MySQL user and password. You can change the username and password to something more secure:
CREATE USER 'vultrdash-admin'@'localhost' IDENTIFIED BY 'password';
Allow complete access to the vultrdash_db database for the vultrdash-admin user:
GRANT ALL PRIVILEGES ON vultrdash_db.* TO 'vultrdash-admin'@'localhost';
The vultrdash-admin now has all privileges on all the tables inside the vultrdash_db database. To reload the grant tables and apply changes, you need to perform a flush-privilege operation using the flush statement:
FLUSH PRIVILEGES;
You are done creating a new user and granting privileges.
First, create a directory that will serve as the root directory for the application:
sudo mkdir -p /var/www/vultrdash
If want to work with the project files using a non-root user account, you’ll need to change the folder owner and group by running:
sudo chown yassine:yassine /var/www/vultrdash
Replace yassine with your sudo non-root username.
Now, you can move into the www directory and clone the application repository on GitHub using git:
cd /var/www
git clone https://github.com/Qoraiche/Vultrdash.git vultrdash
Install PHP dependencies and optimize class autoloader map using composer
:
composer install
Install Node.js dependencies using npm
:
npm install
Copy and rename the configuration file:
cp .env.example .env
The next thing you should do after creating the configuration file is to set your application key to a random string:
php artisan key:generate
The application is now set. In the next step, you will configure the web server.
You will now configure the web server by creating a new application server block, instead of editing the default one.
Open a new server block with:
sudo nano /etc/nginx/sites-available/vultrdash
Add the following content to the new server block configuration file. Ensure you replace the your_server_ip
within the server block with your server IP address:
server {
listen 80;
server_name vultrdash your_server_ip;
root /var/www/vultrdash/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
After adding the content, save the file and exit the editor.
We need to create a symbolic link from the new server block configuration file located in /etc/nginx/sites-available
directory to the /etc/nginx/sites-enabled
by using the following command:
sudo ln -s /etc/nginx/sites-available/vultrdash /etc/nginx/sites-enabled/
Check for any syntax errors by running:
sudo nginx -t
####Application Environment
Open the .env
file (located in /var/www/vultrdash
) using your favorite text editor (e.g. with nano: sudo nano .env
), and follow the steps bellow:
Add the following lines to the file to configure the production application environment:
APP_ENV=production
APP_DEBUG=false
APP_ENV
is an environment variable that specifies that the application is in production, while APP_DEBUG
is an environment variable that specifies if the application should run in debug mode or not. You have set it to false for now.
####Setting Up Database Credentials (Required)
In order to retrieve data from the application’s database you created earlier, you will need to set up and configure the required database credentials from within the Vultrdash application.
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=[YOUR_DB_NAME]
DB_USERNAME=[YOUR_DB_USERNAME]
DB_PASSWORD=[YOUR_DB_PASSWORD]
####API Authentication (Required)
Since the application using Vultr API, you will need to enable your personal access token within your vultr account (Members Area → Account → Settings API).
Add the generated access token to the VULTR_AUTHKEY
environment variable:
VULTR_AUTHKEY=[YOUR_API_KEY]
####Slack Notifications (Optional)
To receive notifications on your slack channel, you will need to configure an "Incoming Webhook" integration for your slack team. this integration will provide you with a URL which you can add to the NOTIFICATION_SLACK_WEBHOOK_URL
environment variable:
NOTIFICATION_SLACK_WEBHOOK_URL=[YOUR_WEBHOOK_URL]
The .env
file will look something like this:
APP_NAME=Vultrdash
APP_ENV=production
APP_KEY=base64:u1uwAyrR2NvyMdQAq/6VUc8uDkMUtO42ORMnkRY2agQ=
APP_DEBUG=false
APP_URL=http://localhost
LOG_CHANNEL=stack
VULTR_AUTHKEY=[YOUR_API_KEY]
NOTIFICATION_SLACK_WEBHOOK_URL=[YOUR_WEBHOOK_URL]
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=[YOUR_DB_NAME]
DB_USERNAME=[YOUR_DB_USERNAME]
DB_PASSWORD=[YOUR_DB_PASSWORD]
.....
Save the file and exit the editor.
Combine all of application's configuration files into a single, cached file:
php artisan config:cache
You can now use Artisan to update your database with the tables from the application. Run this command to do that:
php artisan migrate
After setting up the required credentials and updating the database schema, you can now easily interact with the database.
In order to start the application with some data, you will load a set of dummy data into the database:
php artisan db:seed
You just concluded the last step required to successfully deploy the Vultrdash application. you configured the web server by creating a server block and properly set the web root in order to make the web application accessible then you built the application database.
Finally, reload Nginx web server:
sudo systemctl reload nginx
You can now run and test out the application. Visit http://your_server_ip in your favorite browser, then log in using the default administrator login credentials:
email: [email protected]
password: admin
Remember to change the default login credentials.
The following image is the screenshot of the Vultrdash application that you should see at your server's IP address:
img[/img]