Published in



Prep our Remote Ubuntu to Run an MQTT Broker — AWSSeries # Episode 02

Let’s install these packages in our remote Ubuntu 20.04 LTS image:


We are preparing our environment to run an MQTT Broker, mosquitto from the Eclipse project repo (next post:).

Here are the scripts, step-by-step:

##01_step: Download theses two tools: PuTTY & PuTTYGen; link:#https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html#-----------------------------------------------------------##02-step: Upgrade/Update your linux distribution:$ sudo apt-get upgrade$ sudo apt-get update#-----------------------------------------------------------##03-step: Apache2 Installation:$ sudo apt-get install apache2#-----------------------------------------------------------##04-step: Enable ports 80 e 443 -  Apache2 Firewall:$ sudo ufw app info "Apache Full"$ sudo ufw allow in "Apache Full"#-----------------------------------------------------------##05-step: Apache2 Services controls:$ sudo systemctl start apache2.service$ sudo systemctl stop apache2.service$ sudo systemctl restart apache2.service$ sudo systemctl reload apache2.service$ sudo systemctl status apache2.service#-----------------------------------------------------------##06-step: PHP Installation:$ sudo apt-get install php libapache2-mod-php php-mysql$ sudo systemctl restart apache2#-----------------------------------------------------------##07-step:  phpinfo() Testing:$ sudo nano /var/www/html/phpinfo.php# Copy/paste this: '<?php phpinfo(); ?>' (sem aspas) inside the file 'phpinfo.php'# Open your browser: Mysql Instalation:#HINT: during Mysql installation mark "Apache2" option by hitting the space bar. An '*' do select it;$ sudo apt-get install mysql-server$ sudo mysql_secure_installation (root password creation & type 'y' for all options - My password: 'root1234'$ sudo mysql -u root -p (type password for db)$ > exit;#-----------------------------------------------------------##09-step: PHPMyadmin Installation:$ sudo apt-get update#$ sudo apt-get install phpmyadmin php-mbstring php-gettext  #ubuntu 18$ sudo apt install phpmyadmin php-mbstring php-zip php-gd php-json php-curl  #ubuntu 20#remover  sudo apt-get --purge remove phpmyadmin php-mbstring php-zip php-gd php-json php-curl#-----------------------------------------------------------##10-step: MySql Installation & Configuration - Fixing Logins:$ # Creating login/password for root and phpmyadmin users$ sudo mysql -u root -p$ > SELECT user,authentication_string,plugin,host FROM mysql.user;$ # The user 'root' have no password. Let's fix it:$ > ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root1234';$ # Granting all privileges to 'root' user:$ > GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;$ > FLUSH PRIVILEGES;$ # Doing the same thing to 'phpmyadmin' user: $ > CREATE USER 'phpmyadmin'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'root1234';$ # Granting all privileges to 'phpmyadmin' user:$ > GRANT ALL PRIVILEGES ON *.* TO 'phpmyadmin'@'localhost' WITH GRANT OPTION;$ > FLUSH PRIVILEGES;$ # From that point on, we have two users, with the same passwords
$ # and privileges in the mysql database;
$ # Confirming that both users have their login and password saved$ > SELECT user,authentication_string,plugin,host FROM mysql.user;$ > exit;$ sudo systemctl restart apache2# For testing phpmyadmin, open in your browser:#[your_ip/phpmyadmin]
#login: 'root' or 'phpmyadmin'#password: 'root1234'#if error, fix it!:/ https://www.linode.com/community/questions/17036/how-do-i-fix-a-1045-error-when-trying-to-log-into-phpmyadmin##11-step: Now, let's hinder the visit of hackers: / We will
# establish login and password to access our phpmyadmin structure.
$ sudo nano /etc/apache2/conf-available/phpmyadmin.conf----------------------------------------------<Directory /usr/share/phpmyadmin>Options FollowSymLinksDirectoryIndex index.php
AllowOverride All <----- Add/save this line only:)
----------------------------------------------$ sudo systemctl restart apache2$ sudo nano /usr/share/phpmyadmin/.htaccess----------------------------------------------AuthType BasicAuthName "Restricted Files"AuthUserFile /etc/phpmyadmin/.htpasswdRequire valid-user----------------------------------------------# By restricting direct access to phpmyadmin,
# open a login and password box if someone accesses / phpmyadmin
# directory
$ sudo htpasswd -c /etc/phpmyadmin/.htpasswd jaythree# password:******# In the case you wanto to add another user:$ sudo htpasswd /etc/phpmyadmin/.htpasswd username_2# password: [your_password]#-----------------------------------------------------------##12-step: Now we are going to create a www-data group and transfer #the 'root' permission (after all, you are not going to access your
# directories on the page server using '' root ');
# Follow the step-by-step:
# To upload the php pages in the html directory, initially give
# permission to the 'ubuntu' user;
$ ls$ sudo chgrp -R www-data /var/www/html (it alters to www-data group)$ ls# Now let's add the ubuntu user to this newly created group:$ sudo usermod -a -G www-data ubuntu (add ubuntu to group www-data)$ ls$ sudo chmod -R 2775 /var/www/html (permissions rwx)$ ls$ logout; (now open PuTTY again!)#-----------------------------------------------------------##13-step: Python Installation (Ubuntu 20.04 LTS already comes with it):#$ sudo apt install python3.8$ sudo apt install python3-pip#-----------------------------------------------------------##14-step: Mosquitto Installation:$ sudo apt-get update$ sudo apt-get install mosquitto mosquitto-clients
# Mosquitto Control cmds:
# *****************************************************# Mosquitto init/stop/restart/status:$ sudo service mosquitto start$ sudo service mosquitto stop$ sudo service mosquitto restart$ sudo service mosquitto status##15-step: Now Download and Install
# Filezilla # https://filezilla-project.org/
# Configure it:
click site manager > new site > name: ubuntu_20_aws > SFTP > user: ubuntu > load keys .ppk file
Edit > Setting > SFTP > Add key file button
File > Site manager > Connect
Type: Remote site: /var/www/htmlTo test: save index.php (any content) file and past to public directory
There you have it!In the next Episode let's finally upload letsEncrypt certs:)#-----------------------------------------------------------
video 1. Note: During installation, I had not noticed that my numeric keypad was locked, and when typing the password for the phpmyadmin user, it got only the characters without the numbers; the error on phpMyAdmin dashboard originated from that typo; but continuing, resilience, this is the word, I, as a legitimate hobbyist, ended up correcting the password by typing: sudo dpkg-reconfigure phpmyadmin (site) \o/

Related Posts

00#Episode — AWS Essentials — Intro to AWS — AWSSeries

01#Episode — AWS — Login to Ubuntu 20 — Access Remote Ubuntu via PuTTY SSH Session — AWSSeries

02#Episode — AWS — LAMP — Prep our Remote Ubuntu to Run an MQTT Broker — AWSSeries (this one)

03#Episode — AWS — IP Plus DNS — How to Link Your Sub/Domain Name With Your AWS Instance Running Ubuntu — AWSSeries

04#Episode — AWS — LetsEncrypt — How To Installing the TLS / SSL LetsEncrypt Certificate on Remote Ubuntu Server 20.04 — AWSSeries

05#Episode — Soon… Be tuned!:)

Fig 1. Ubuntu 20.04 LTS on the cloud!

Credits & References

Microgênios — Treinamento em Sistemas Embarcados — Microchip Regional Partner — Microchip Certified Brazilian Training Education Startup & a Simplício-owned enterprise o/

AWS Essentials — Learn from AWS technical instructors about the AWS Platform, global infrastructure, security, and the core services by Udemy

This course is delivered by actual AWS technical instructors who teach fundamental and advanced AWS courses around the globe. In this course, you will learn essential concepts of the AWS global infrastructure, platform, and core services, so that you can begin, or, continue your journey of growing your business using AWS Cloud technology. We encourage your participation on the discussion board and feel free to ask any questions about the course or AWS certification.

AWS Documentation by Amazon

Apache The Definitive Guide, 3rd Edition by O’Reilly’s CD bookshelves

Fig 2. This is my FileZillla dashboard ready to rock!

At this point and time, I just want to say thank you for sticking along with Jungletronics & Kidstronics and I’m hoping you’ve learned a lot from it as well as have had a good time as much as I had; so just a quick bye: Happy New 2021 Year! Here Comes The Sun!




J of Jungle + 3 Plats Arduino/RPi/Pic = J3

Recommended from Medium

What is Interface Testing? Types, Strategy And Tools

Goodbye PHP, Goodbye Mailchimp: How to build a simple Email List directly from your Landing Page

Project Zone — A zone for programmers.

Why Hire A Bootcamp Developer?

Ansible- Before You Start Playing

Creating Effective REST APIs with FastAPI

AWS Lambda: Amazon Serverless Computing

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


Hi, Guys o/ I am J3! I am just a hobby-dev, playing around with Python, Django, Lego, Arduino, Raspy, PIC, AI… Welcome! Join us!

More from Medium

Deploy Django App Using Elastic Beanstalk and CodePipeline

How To Run External Script Inside Django Environment

Getting Started with Flask Development

A Django Blog In VS Code — Self-Service Django Password Reset