Notifications
Clear all

Setup the Raspberry Pi

2 Posts
2 Users
3 Likes
1,602 Views
WolfgangW
(@wolfgangw)
Member
Joined: 4 years ago
Posts: 70
Topic starter  

Hi Folks,

many may not need this, but it might be helpful for some of you.

It took me quite some while to find a matching setup for my Raspberry Pi 4. It was quite confusing to research in Internet to see one say so, another one say different. At the end, I found my way and I think this could be useful for some of you. The confusing part was mostly when I used commands for Linux which was working one day, and very strange not working, when I tried to make a reproduction of this.

First let me explain, what was my intention, before you just start copy and paste all of that.

I wanted to create a system, which doesn't have all that programs I would never need. I needed a system which has a webserver - at least for internal use. Also I needed PHP and MySQL - I used to use the MariaDB, which is working pretty well. I also used to install some programs which not everyone is going to need, like Mono.

Background for this is, that I want to write all measuring values into a Database which I setup into that MariaDB, matching for my needs. Also I am going to use the Means whenever I want to send a measuring value from a sensor to the broker on the Raspberry Pi. (this part is what I am recently working on)

What you need is

  1. Raspberry Pi 4 - I use it 4GB version for my trials 
  2. 32GB SD-Card - enough for try
  3. On my Windows computer the programs SD-Card-Formatter and Win32DiskImager
  4. Windows Remote Desktop (will not run for first)
  5. putty
  6. patience friends, patience

 

First sure you are downloading the basic Raspian/Debian OS on your computer. With the Win32DiskImager you can "burn" that OS to your Raspberry Pi. So, after some basic settings which doesn't take long time, you can start. But you are sure not finish. There is no database, no webserver and/or whatever you may need. With the following information, which you can use one by one for copy and paste inside putty-window.

one thing first. I used to make backup from my SD-Card after every huge step I made. Means after I was finish I had a bunch of backup-files made with Win32DiskImager which help me a lot not always start from the beginning. I also included several reboots, necessary or not, that is the way I made and it is working.

 

# 1. First steps after start and setup your Raspberry Pi
sudo apt-get update && sudo apt-get upgrade -y
sudo reboot now

# 1.2 remove unnecessary Programs
sudo -i
sudo apt-get remove wolfram-engine minecraft-pi python-minecraftpi sonic-pi python3-numpy smartsim penguinspuzzle timidity scratch nuscratch python3-pygame python-pygame python-tk python-picraft bluej claws-mail greenfoot minecraft-pi nodered geany libreoffice* -y
apt-get autoremove --purge
sudo reboot now

# 2. install Remote Desktop Service for Windows Access
sudo apt-get install xrdp -y
sudo reboot now

# 3.1 Apache2 Webserver
sudo apt install apache2 -y
sudo apt install php libapache2-mod-php -y
sudo systemctl start apache2
sudo systemctl enable apache2

# 3.2 MySQL
sudo apt install mariadb-server php-mysql -y
sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo mysql_secure_installation

# Step through the setup as follows:
1: "Enter current password for root" = Quit with Enter (we don't enter anything)
2: "Set root password" = Y (and then assign a password for the user root)
3: "Remove anonymous users" = Y (we don't want such users)
4: "Disallow root login remotly" = Y (we want the user root to only be able to log in locally)
5: "Remove test database and access to it" = Y (we don't need a test database)
6: "Reload privilege tables now" = Y (these have to be reloaded)

# 4.4 Permissions for Port- and IP within my.conf
ssh pi@homenet -p 22

# 3.3 PHPMyAdmin
# sudo apt install php php-mysql -y
sudo apt install php php-mysql -y
sudo apt install phpmyadmin -y
sudo dpkg-reconfigure -plow phpmyadmin
sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin

# 3.4 Mono - only for C#-Users
sudo apt-get install mono-complete -y
sudo apt-get update && sudo apt-get upgrade -y
sudo reboot now

# 3.5 ?? WordPress - if necessary / desired
cd /var/www/html
sudo wget https://wordpress.org/latest.zip
sudo unzip latest.zip
sudo chown -R www-data:www-data wordpress/
sudo reboot now

# 4. Permissions for Raspbian SSH-User
sudo -i
useradd -m USER
passwd PASSWORD2
usermod -s /bin/bash USER
usermod -g users USER
usermod -g ssh USER
sudo gpasswd -a pi ssh
sudo gpasswd -a pi sudo
sudo gpasswd -a USER ssh
ssh pi@homenet -p 22
ssh USER@homenet -p 22

# 4.2 Permissions for MariaDB
sudo mysql -uroot
or - sudo mysql -uroot -hlocalhost -p
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
# We comment out the port by removing the #
# and comment on the bind address by putting the #.

# 4.3 further permissions
sudo systemctl restart mysql
sudo -i
sudo mysql -uroot -hlocalhost -p
create user 'USER'@'192.168.0.%' identified by 'PASSWORD';
GRANT ALL PRIVILEGES ON *.* TO 'USER'@'192.168.0.%' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION;
FLUSH PRIVILEGES;
create user 'pi'@'192.168.0.%' identified by 'PASSWORD2';
GRANT ALL PRIVILEGES ON *.* TO 'pi'@'192.168.0.%' IDENTIFIED BY 'PASSWORD2' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'pi'@'localhost' IDENTIFIED BY 'PASSWORD2' WITH GRANT OPTION;
FLUSH PRIVILEGES;
SELECT User, Host FROM mysql.user WHERE Host <> 'localhost';
exit; # 4.4 Permissions for Port- and IP within my.conf
ssh pi@homenet -p 22
sudo nano /etc/mysql/my.conf
# copy the following lines
port = 3306
bind-address = ::192.168.0.%

# 4.5 Correct the error in the phpmyadmin display
# Approximately line 613 in file
sudo nano +613 /usr/share/phpmyadmin/libraries/sql.lib.php
# use nano to edit!
# ctrl + k - remove lines
# copy and paste the following block instead

function PMA_isRememberSortingOrder($analyzed_sql_results){
return $GLOBALS['cfg']['RememberSorting']
&& ! ($analyzed_sql_results['is_count']
|| $analyzed_sql_results['is_export']
|| $analyzed_sql_results['is_func']
|| $analyzed_sql_results['is_analyse'])
&& $analyzed_sql_results['select_from']
&& ((empty($analyzed_sql_results['select_expr']))
|| ((count($analyzed_sql_results['select_expr'] ) == 1)
&& ($analyzed_sql_results['select_expr'][0] == '*')))
&& count($analyzed_sql_results['select_tables']) == 1;
}

# 5.0 For ESP8266 and MQTT
sudo apt-get install mosquitto -y
sudo apt-get install mosquitto-clients -y

# 5.1 Edit /etc/mosquitto/mosquitto.conf
sudo nano /etc/mosquitto/mosquitto.conf
# Do add the following 3 lines
allow_anonymous = false
password_file /etc/mosquitto/pwfile
listener 1883

# 5.2 Edit the Password-file
sudo mosquitto_passwd -c /etc/mosquitto/pwfile Sensor

# 5.3 Check Status of Broker
sudo systemctl status mosquitto
sudo systemctl start mosquitto
sudo systemctl stop mosquitto
sudo systemctl restart mosquitto
sudo systemctl enable mosquitto

# Ports
# Show list of open ports
netstat -n -A inet
# Show list of active connections
netstat -anp | grep -i listen
lsof -i

https://medium.com/better-programming/how-to-install-mysql-on-a-raspberry-pi-ad3f69b4a094

# USB-Disk mounting - not necessarily
https://jankarres.de/2013/01/raspberry-pi-usb-stick-und-usb-festplatte-einbinden/
sudo apt-get -y install ntfs-3g hfsutils hfsprogs exfat-fuse
sudo mkdir /home/pi/usbstick
sudo blkid -o list -w /dev/null
sudo umount /media/pi/SUNDATA
sudo mount -t vfat -o defaults /dev/sda /home/pi/usbstick

Now until here, you can find your system running well. You don't need to research or try. After the installation of the Raspberry Pi with Debian, it took me around 25 minutes to setup the whole thing, of course no backups been made at this time. But this is now reproducable. At least, no guarantee, for further changes of any of that Linux-commands.  

Have a good time there
Wolfgang

If I am not here, then I am most probably somewhere else


   
Cristian F reacted
Quote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@wolfgangw

Hi Wolfgang

Posted by: @wolfgangw

Hi Folks,

many may not need this, but it might be helpful for some of you.

It took me quite some while to find a matching setup for my Raspberry Pi 4. It was quite confusing to research in Internet to see one say so, another one say different. At the end, I found my way and I think this could be useful for some of you. The confusing part was mostly when I used commands for Linux which was working one day, and very strange not working, when I tried to make a reproduction of this.

You haven't made it clear at all, what exactly was working one day and not the next?, so we can only speculate on what the reason could be.  What were the errors you received? During what operation? What part of the system was actually affected?  Are you able to provide those specific details?

Posted by: @wolfgangw

First let me explain, what was my intention, before you just start copy and paste all of that.

I wanted to create a system, which doesn't have all that programs I would never need. I needed a system which has a webserver - at least for internal use. Also I needed PHP and MySQL - I used to use the MariaDB, which is working pretty well. I also used to install some programs which not everyone is going to need, like Mono.

Background for this is, that I want to write all measuring values into a Database which I setup into that MariaDB, matching for my needs. Also I am going to use the Means whenever I want to send a measuring value from a sensor to the broker on the Raspberry Pi. (this part is what I am recently working on)

Ok, from what you're describing, it sounds like you're trying to setup a typical LAMP Server on your raspberry pi.  For example, if you're not familiar with the term LAMP, it typically refers the following application/software stack (likewise, WAMP for Windows O/S):

LAMP (Linux, Apache, (MySQL or MariaDB), (PHP and or PYTHON))

This is a very common web-server setup in today's world (also referred to as FULL STACK, when employment agencies are looking for these types of developers).

If this is the case, I'd just like to make you aware that there are downloadable versions for Raspberry Pi, such as:

Raspberry Pi OS Lite

...that are already cut down versions, and even further cut down than what you've described, even without a GUI (you can add it later if you wish), specifically built for server applications that you can build upon.

Likewise, there is also an Ubuntu Server, and you can customise the applications installed during the install process, with only the bare essentials you need.

Also, there is also the modern approach these days (you know... that overrated acronym known as DevOps), but probably the most flexible of all solutions, which is to install DOCKER onto your Raspberry Pi, and then download any images you like, and for just about any development scenario you like, and for free - Well worth a look IMHO - You can download and implement many IOT containers for MQTT!

On a final note, I have some concerns with giving all users full DB privileges as you have... it's OK for screwing around I guess, but not something you want to leave in that state in the real world go live production scenario for your network, so do be careful to address those settings when you go live!

Some food for thought.

Cheers.


   
Cristian F and Squish reacted
ReplyQuote