[UBUNTU] Server EBIKE Full Package - fourslickz/notes GitHub Wiki
**CHANGE USER MODE TO root (full privileges) **
sudo su -
SET PRINTER HARDWARE ID AS Printer0
nano /etc/udev/rules.d/90-ebike.rules
90-ebike.rules
ACTION=="add", SUBSYSTEMS=="usb", ATTRS{idVendor}=="04b8", ATTRS{idProduct}=="0e11", SYMLINK+="printer0", MODE="0777"
you have to reboot this server to apply this function
UTILITIES
apt -y install lsb-release apt-transport-https ca-certificates
apt -y install net-tools
apt -y install wget
apt -y install curl
apt -y install git
FCGIWRAP
apt-get install fcgiwrap
systemctl enable fcgiwrap
systemctl start fcgiwrap
systemctl status fcgiwrap
SMOKEPING
apt-get install smokeping
systemctl enable smokeping
systemctl start smokeping
disable apache2
systemctl stop apache2
systemctl disable apache2
REDIS-SERVER
apt-get install redis-server
systemctl enable redis-server
systemctl start redis-server
PHP
apt -y install software-properties-common
add-apt-repository ppa:ondrej/php
apt-get update
apt-get install php7.4-{bcmath,bz2,cgi,cli,common,curl,fpm,gd,gmp,imagick,intl,json,mbstring,mcrypt,memcache,memcached,mysql,readline,soap,uuid,xml,zip}
systemctl enable php7.4-fpm
systemctl start php7.4-fpm
PHPMYADMIN
cd /usr/local/src
wget https://files.phpmyadmin.net/phpMyAdmin/5.1.3/phpMyAdmin-5.1.3-english.tar.gz
tar zxvf phpMyAdmin-5.1.3-english.tar.gz
cp -r phpMyAdmin-5.1.3-english /usr/share/pma
NGINX
apt-get install nginx
systemctl enable nginx
systemctl start nginx
nano /etc/nginx/sites-available/default
NGINX default
server {
# Default Port
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.html index.php;
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;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
location = /smokeping/smokeping.fcgi.dist {
fastcgi_intercept_errors on;
fastcgi_param SCRIPT_FILENAME /usr/lib/cgi-bin/smokeping.cgi;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
}
location /smokeping {
alias /usr/share/smokeping/www/;
index smokeping.fcgi.dist;
gzip off;
}
# LARAVEL APP
#------------------- ebike-apps --------------------------------
location /apps {
alias /opt/ebike-app/public;
try_files $uri $uri/ @apps;
satisfy any;
allow all;
index index.php;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
index index.php;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
}
location @apps {
rewrite /apps/(.*)$ /apps/index.php?/$1 last;
}
#------------------- end ebike-apps --------------------------------
#------------------- PHPMYADMIN ------------------------------------
location /pma {
alias /usr/share/pma;
index index.php;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
index index.php;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
}
#------------------- PHPMYADMIN ------------------------------------
}
MARIADB SERVER (MYSQL)
apt-get install mariadb-server
systemctl enable mariadb
systemctl start mariadb
COMPOSER
curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php
php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer
PYTHON-3
apt-get install python3
apt-get install python3-pip
pip3 install pyserial
pip3 install escpos
pip3 install flask
pip3 install flask_cors
NODEJS
curl -sL https://deb.nodesource.com/setup_16.x -o nodesource_setup.sh
bash nodesource_setup.sh
apt-get install -y nodejs
apt-get install -y build-essential
LARAVEL-ECHO-SERVER
npm install -g laravel-echo-server
SUPERVISOR
apt-get install supervisor
systemctl enable supervisor
systemctl start supervisor
nano /etc/supervisor/conf.d/laravel-echo-server.conf
laravel-echo-server.conf
[program:echo-server]
process_name=%(program_name)s
command=/usr/bin/laravel-echo-server start --dir=/opt/ebike-app
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=root
redirect_stderr=true
stdout_logfile=/opt/ebike-app/storage/logs/echoserver.log
SOCKET-SERVER FOR RFID READER
cp /opt/ebike-app/socket_server/server-{location}.py /opt/ebike-app/server.py
nano /etc/supervisor/conf.d/sensor-listener.conf
sensor-listener.conf
[program:sensor-listener]
process_name=%(program_name)s
command=/usr/bin/python3 /opt/ebike-app/socket_server/server.py
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=root
redirect_stderr=true
stdout_logfile=/var/log/sensor-listener.log
GUNICORN
pip3 install gunicorn
SETUP PRINTER SERVICE
cd /opt/
git clone https://github.com/fourslickz/ebike-wsgi.git
nano /opt/ebike-wsgi/server.py
server.py
change brand, title, and callcenter
printer_device = '/dev/printer0'
liner = '----------------------------------------\n'
brand = 'EBIKE'
title = 'Eco Green Park'
location = 'Jl. Raya Pandan Rejo No.91, Bumiaji, Kota Batu\n'
thanks = 'Terima kasih atas kunjungan Anda\n'
callCenter = 'Nomor HP : 0812-1697-2306\n'
cut = 'E0'
nano /etc/systemd/system/wsgi.service
wsgi.service
[Unit]
Description=Gunicorn instance to serve myproject
After=network.target
[Service]
User=root
Group=root
WorkingDirectory=/opt/ebike-wsgi
ExecStart=/usr/local/bin/gunicorn --bind 0.0.0.0:8080 wsgi:app
[Install]
WantedBy=multi-user.target
systemctl enable wsgi.service
OPENVPN-CLIENT
apt-get install openvpn
wget -O /etc/openvpn/client.conf https://ebikecloud.mitranetwork.id/vpn-conf/ebike-{location}.ovpn
systemctl start openvpn@client
systemctl enable openvpn@client
systemctl status openvpn@client
EXPORT DATABASE
mysqldump -u rental -p rental > ./backupdb-ebike.sql
IMPORT DATABASE
for old server use only
mysql -u root -p
mysql> create database rental;
mysql> grant all privileges on rental.* to 'rental'@'localhost' identified by 'jtp';
mysql> flush privileges;
mysql> exit;
mysql -u rental -p rental < ./backupdb-ebike.sql
CLONE REPO EBIKE-APP
for new server use only
cd /opt/
git clone https://github.com/fourslickz/ebike-app.git
cd /opt/ebike-app/
bash deploy.sh
nano .env
change LOCATION, LOCATION and CALL_CENTER
LOCATION=jtp2
LOCATION_TITLE="Eco Green Park"
CALL_CENTER="0812-1697-2306"
php artisan config:clear
CRONJOB
crontab -e
* * * * * /usr/bin/php /opt/ebike-app/artisan ebike:update
* * * * * /usr/bin/php /opt/ebike-app/artisan logebike:update
* * * * * /usr/bin/php /opt/ebike-app/artisan pendapatan:upload