— HaeramKim, BuildYourOwnIoTPlatform — 1 min read
NOTE: this notes are from “Build Your Own IoT Platform” by Anand Tamboli. And I can’t speak english very well, so some sentences or word might be inappropriate and might have some misunderstandings.
ufw app list
: Show all available applications.ufw allow <application_name>
: Allow that application.ufw enable
: Run firewall.ufw status
: Show firewall status.ufw app info "<application_name>"
: Show information of that application.ufw allow in "<application_name>"
: It also allows that application. I don’t know the difference between using and not using “in” command.1apt update2apt install apache2
1ufw allow in "Apache Full"
80
for HTTP and port 433
for HTTPS1apt install mysql-server
1mysql_secure_installation
1* This will prompt additional configuration console.2* You have to select `0(LOW)` for `password validation policy`.
1mysql
1* Query for showing all root account:
1SELECT user,authentication_string,plugin,host FROM mysql.user WHERE user="root";
1* Query for modifying password for root account:
1ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '$YOUR_PASSWORD';2FLUSH PRIVILEGES;
1* And this is expected result when you type show-root query:
1| user | authentication_string | plugin | host |2| root | *A0AF1999141933B3B4C7 3AE72544AB01849669F98 | mysql_native_password| localhost |
1apt install php libapache2-mod-php php-mysql
/etc/apache2/mods-enabled/dir.conf
1<IfModule mod_dir.c>2DirectoryIndex index.php index.html index.htm index.cgi index.pl index.xhtml 3</IfModule>
13. Restart apache2 server
1systemctl restart apache2
14. Test whether the server works correctly:
1vi /var/www/html/test.php2# And add php script below to it3<?php4 echo "php ok";5?>
1apt update2apt install phpmyadmin php-mbstring php-gettext
1* NOTE: php-gettext is not stable in Ubuntu 20.04. This is why you have to choose Ubuntu 18.04 when creating droplet.2* While Installing PHPMyAdmin, several configuration console might be prompted. Here is recommened selection:
1# Configure database for phpmyadmin with dbconfig-common 2Yes3
4# What kind of server do you plan to use5Apache2 # You have to tap spacebar to select this opiton.6
7# Communication8Unix socket9
10# Set database name, username, password on your own11# Some errors might be occured when you select password policy to MEDIUM(1) or HIGH(2). That's why you have to choose LOW(0) when you select policies.
1phpenmod mbstring2systemctl restart apache2
htaccess
feature of apache to securing it.1# Open /etc/apache2/conf-available/phpmyadmin.conf and modify to:2Alias /phpmyadmin /usr/share/phpmyadmin3<Directory /usr/share/phpmyadmin>4 Options SymLinksIfOwnerMatch5 DirectoryIndex index.php6 AllowOverride All 7.....8.....
1* Add following contents to the file
1# Open /usr/share/phpmyadmin/.htaccess2AuthType Basic3AuthName "Restricted Files"4AuthUserFile /etc/phpmyadmin/.htpasswd5Require valid-user
1* Set admin password
1htpasswd -c /etc/phpmyadmin/.htpasswd $USERNAME2# And then entering password line will be prompted
www.example1.com
and www.example2.com
…, It is called virtual host1mkdir -p /var/www/<your-domain>/html2chown -R $USER:$USER /var/www/<your-domain>/html3chmod -R 755 /var/www/<your-domain>
1# Make index.php in /var/www/<your-domain>/html/2# And then add following contents to the file:3<?php4 echo("Hi...this is our webpage with domain name !");5?>
1# Make <your-domain>.conf file in /etc/apache2/sites-available/2# And then add following contents:3<VirtualHost *:80>4 ServerAdmin admin@<your-domain>5
6 ServerName <your-domain>7 ServerAlias www.<your-domain>8
9 DocumentRoot /var/www/<your-domain>/html10
11 ErrorLog ${APACHE_LOG_DIR}/error.log12 CustomLog ${APACHE_LOG_DIR}/access.log combined13</VirtualHost>
1* And then enable virtual host:
1a2ensite <your-domain>.conf2a2dissite 000-default.conf3
4# Typing command below must prints "Syntax OK"5apache2ctl configtest6
7# Restart server8systemctl restart apache2
Let’s Encrypt
and Certbot
.1add-apt-repository ppa:certbot/certbot2apt install python-certbot-apache
1# When you registered www-prefixed domain2# like "www.example.com", add "www.<your-domain>" too.3certbot --apache -d <your-domain>
1* After this command runs, you have to enter email address for notification and agree with policy stuff.2* And also, you have to select "redirect" option when selection console is prompted.3* When messages saying "Congratulations!" is printed, it's done.4* You can verify the Certificate with `http://www.ssllabs.com/ssltest/analyze.html?d=<your-domain>` page.
1# Register repository2curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -3
4# Install NodeJS & NPM5apt install nodejs6
7# Verify installation (Check version)8nodejs -v9npm -v
1npm install -g --unsafe-perm node-red
1880
.1ufw allow 1880/tcp
/root/.node-red/settings.js
. You have to overwrite this file.1# Install tool2npm install -g node-red-admin3
4# Get hashed password5node-red-admin hash-pw
1* After typing the last command, password input console will be shown. Enter a password u like.2* And then, hashed password will be printed to the console. Copy it to paste in `settings.js`.32. Modify `settings.js`
1# Open settings.js and modify it to:2adminAuth: {3 type: "credentials",4 users: [5 {6 username: "<your-username>",7 password: "<hashed-password>",8 permissions: "*"9 },10 ] 11}, 12...
1node-red > node-red.log &