Showing posts with label mysql. Show all posts
Showing posts with label mysql. Show all posts

Tuesday, December 22, 2020

Install mysql / mariadb on raspbian example

 

 

 

How to install MySQL database on raspberry pi


1 sudo apt-get install mysql-server.
2 sudo mysql_secure_installation. 5)Please hit Enter for current root password.
3 sudo mysql -u root -p. ...
4 show databases; ...
5 CREATE DATABASE Demo; ...
6 USE Demo; ...
7 CREATE USER 'admin'@'localhost' IDENTIFIED BY 'admin'; ...
8 GRANT ALL PRIVILEGES ON Demo.* TO 'admin'@'localhost';

 

Example and more details

how-to-install-mysql-database-on-raspberry-pi 

 

 

--30--

Thursday, November 22, 2018

Install Lamp Server on Linux


Install Lamp server

sudo apt install apache2
sudo apt install mysql-server
sudo apt install php-pear php-fpm php-dev php-zip php-curl php-xmlrpc php-gd php-mysql php-mbstring php-xml libapache2-mod-php
sudo service apache2 restart

check php
php -r 'echo "\n\nYour PHP installation is working fine.\n\n\n";'



--30--


Friday, June 9, 2017

Downgrading php from 7.0 to 5.0


Php7 is installed by default on Ubuntu 16.04. 

The copy of gregarius, an RSS aggregator / reader uses php revision greater than 4.  Many of the mysql php core functions, and string editing is needlessly mangled in 7.0, and editing and updating the gregarius package is a very large task.

It is easier to downgrade the php for now than editing gregarius.  FWIW gregarius is pretty much dead in support after 2006, very old, which is sad since it is a nice stable tool.

it requires mysql, but luckily the downgraded php 5 works along with the mysql extensions.

Procedure snarfed from another blog to remove php 7 and install 5.6 from another repository, ondrej.

Remove all the stock php packages
List installed php packages with dpkg -l | grep php| awk '{print $2}' |tr "\n" " " then remove unneeded packages with sudo aptitude purge your_packages_here or if you want to directly remove them all use :
sudo apt-get purge `dpkg -l | grep php| awk '{print $2}' |tr "\n" " "`
Add the PPA
sudo add-apt-repository ppa:ondrej/php
If you get add-apt-repository: command not found run the following command first :
sudo apt-get install software-properties-common
Install your PHP Version
sudo apt-get update
sudo apt-get install php5.6
You can install php5.6 modules too for example
sudo apt-get install php5.6-mbstring php5.6-mcrypt php5.6-mysql php5.6-xml
Verify your version
If you have installed php5.6-cli
sudo php -v
If you don't have php5.6-cli, put this on a .php file
<?php 
      //outputs php configuration info
      phpinfo(); 
?>

restarting apache

dpkg-reconfigure phpmyadmin

x

Thursday, January 12, 2017


Good example of how to secure mongodb internally.  The server is secured from the internet in case any mischief tries to burrow in directly.  Also secures inside the house paths.

https://www.cyberciti.biz/faq/how-to-secure-mongodb-nosql-production-database/

Additional link in the article with other securing tips:

https://www.cyberciti.biz/tips/linux-security.html

Info copied here in case above link dies.

MongoDB ransom attacks are in Wild. I am using it for storing data on my public facing cloud server powered by Ubuntu Linux. How do I protect and secure my MongoDB nosql server on Linux or Unix operating system?

MongoDB is a free and open-source NoSQL document database server. It is used by web application for storing data on a public facing server. Securing MongoDB is critical. Crackers and hackers are accessing insecure MongoDB for stealing data and deleting data from unpatched or badly-configured databases. In this tutorial you will learn about how to secure a MongoDB instance or server running cloud server.

MongoDB config

  1. The default file is located at /etc/mongodb.conf
  2. The default port is TCP 27017
  3. MongoDB server version: 3.4.1

Limit network exposure

Edit the /etc/mongodb.conf or /usr/local/etc/mongodb.conf file, enter:
$ sudo vi /etc/mongodb.conf
If your web-app and MongoDB (mongod server) installed on the same machine, set the IP address of MongoDB to 127.0.0.1. This cuts communication directly from the internets:
# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1
However, it is possible that you have two or more servers as follows:
Fig.01: A sample modern web-app with MonoDB running inside your VLAN
Fig.01: A sample modern web-app with MonoDB running inside your VLAN

You need to bind mongod to 192.168.1.7 so that it can be only accessed over VLAN:
  bindIp: 192.168.1.7
The bind_ip directive Ensure that MongoDB runs in a trusted network environment and limit the interfaces on which MongoDB instances listen for incoming connections.

Change the default port

You can also change the default port if you want. In this example set it to 2727:
port: 2727
Save and close the file. You need to restart MongoDB, enter:
$ sudo systemctl restart mongod
OR if you are using FreeBSD Unix:
# service mongod restart
Verify open ports with netstat command:
$ netstat -tulpn
$ ss -tulpn
$ sockstat #freebsd unix command
$ ss -tulpn | grep 27017
$ netstat -tulpn | grep 27017

Sample outputs:
tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN      6818/mongod

Setup access control

You need to add a user administrator to a MongoDB instance running without access control and then enables access control. By default anyone can connect to the MongoDB and this is not a good idea. For example:
Animated gif 01:  Connect a mongo shell to the instance with any sort of authentication
Animated gif 01: Connect a mongo shell to the instance with any sort of authentication

Connect to the DB instance

$ mongo
## or ##
$ mongo --port 2727
MongoDB shell version: 2.6.10
connecting to: test

Create the user administrator

Warning: Create user with strong password. For demo purpose I am using ‘mySuperSecretePasswordHere’ but you should use strong password.
You need to use admin database. Type the following command at > prompt to create your superuser:
> use admin
switched to db admin

Next creates the user vivek in the admin database with the userAdminAnyDatabase role:
> db.createUser({user:"vivek",pwd:"mySuperSecretePasswordHere", roles:[{role:"userAdminAnyDatabase",db:"admin"}]})
Sample outputs:
Successfully added user: {
 "user" : "vivek",
 "roles" : [
  {
   "role" : "userAdminAnyDatabase",
   "db" : "admin"
  }
 ]
}
Disconnect the mongo shell by typing the following command:
> exit
bye
$

Re-start the MongoDB instance

Edit the /etc/mongodb.conf or /usr/local/etc/mongodb.conf file, enter:
$ sudo vi /etc/mongodb.conf
Turn on security:
security:
  authorization: enabled
Save and close the file. Re-start the MongoDB instance:
$ sudo systemctl restart mongodb
OR if you are using FreeBSD Unix:
# service mongod restart
To authenticate during connection using user vivek and password for the admin database:
$ mongo -u vivek -p mySuperSecretePasswordHere --authenticationDatabase admin
Add additional user to your DB. First create a new database called “nixcraft”:
> use nixcraft
switched to db nixcraft

Create a user named ‘nixdbuser’ with a password named ‘myKoolPassowrd’ for nixcraft db:
   db.createUser(
     {
       USER: "nixdbuser",
       pwd: "myKoolPassowrd",
       roles: [ { ROLE: "readWrite", db: "nixcraft" },
                { ROLE: "read", db: "reporting" } ]
     }
   )
Sample outputs:
Successfully added user: {
 "user" : "nixdbuser",
 "roles" : [
  {
   "role" : "readWrite",
   "db" : "nixcraft"
  },
  {
   "role" : "read",
   "db" : "reporting"
  }
 ]
}
You can now connect to nixcraft db as follows:
$ mongo --port 27017 -u "nixdbuser" -p "myKoolPassowrd" --authenticationDatabase "nixcraft"
This make sure only authorized admin user named ‘vivek’ can execute commands or nixdbuser can do read/write operation on nixcraft db. You can verify it as follows by inserting records:
> use nixcraft
> db
> db.names.insert({"title":"Mr", "last":"Gite", "First":"Vivek"})
> db.names.find()
> show dbs

Sample outputs:
Fig.02: Enabled access control and enforce authentication
Fig.02: Enabled access control and enforce authentication

Use firewall

Use firewalls to restrict which other entities are allowed to connect to your mongodb server. In this example only allow your application servers access to the database using ufw on Ubuntu or Debian Linux:
$ sudo ufw allow proto tcp from 192.168.1.5 to 192.168.1.7 port 27017
$ sudo ufw allow proto tcp from 192.168.1.6 to 192.168.1.7 port 27017

Enable SSL

Use SSL between your MongoDB client and server when connecting to your Mongodb server over the internet. Otherwise your session is open for the “man in the middle” attack. My setup is as follows:
  mongodb-server: 127.0.0.1
  mongodb-client: 127.0.0.1
  Common Name (e.g. server FQDN or YOUR name) []: 127.0.0.1
  The PEM pass phrase for server: mongodb_server_test_ssl
  The password/passphrase for client: mongodb_client_test_ssl

Type the following command the server certificate

$ sudo mkdir /etc/ssl/mongodb/
$ cd /etc/ssl/mongodb/
$ sudo openssl req -new -x509 -days 365 -out mongodb-server-cert.crt -keyout mongodb-server-cert.key

Sample outputs:
Fig.03: MongoDB SSL setup server certificate
Fig.03: MongoDB SSL setup server certificate

Create the server .pem file with both key and certificate:
$ cd /etc/ssl/mongodb/
$ sudo bash -c 'cat mongodb-server-cert.key mongodb-server-cert.crt > mongodb-server.pem'

Type the following command the client certificate

$ cd /etc/ssl/mongodb/
$ sudo openssl req -new -x509 -days 365 -out mongodb-client-cert.crt -keyout mongodb-client-cert.key

Sample outputs:
Fig.04: MongoDB SSL setup client certificate
Fig.04: MongoDB SSL setup client certificate

Create the client .pem file with both key and certificate:
$ cd /etc/ssl/mongodb/
$ sudo bash -c 'cat mongodb-client-cert.key mongodb-client-cert.crt > mongodb-client.pem'

Configure mongod and mongos for TLS/SSL server

Edit the /etc/mongodb.conf or /usr/local/etc/mongodb.conf file, enter:
$ sudo vi /etc/mongodb.conf
Update the config file as follows:
# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1
  ssl:
     mode: requireSSL
     PEMKeyFile: /etc/ssl/mongodb/mongodb-server.pem
     CAFile: /etc/ssl/mongodb/mongodb-client.pem
     PEMKeyPassword: mongodb_server_test_ssl
Save and close the file. Re-start the MongoDB instance:
$ sudo systemctl restart mongodb
OR if you are using FreeBSD Unix:
# service mongod restart

TLS/SSL Configuration for MongoDB clients

The syntax is as follows for mongo shell interface:
$ mongo --ssl --sslCAFile /etc/ssl/mongodb/mongodb-server.pem \
--sslPEMKeyFile /etc/ssl/mongodb/mongodb-client.pem \
--sslPEMKeyPassword mongodb_client_test_ssl \
--host 127.0.0.1 --port 27017 \
--u "nixdbuser" -p "myKoolPassowrd" --authenticationDatabase "nixcraft"

Sample outputs:
Fig.05: MongoDB SSL  client connection using SSL certificate
Fig.05: MongoDB SSL client connection using SSL certificate

And here is a Python client for connection to SSL enabled MongoDB:
client = pymongo.MongoClient('127.0.0.1', ssl=True)
OR
client = pymongo.MongoClient('127.0.0.1',
                              ssl=True,
                              ssl_certfile='/etc/ssl/mongodb/mongodb-client.pem',
                              ssl_keyfile='/etc/ssl/mongodb/mongodb-server.pem',
                              ssl_pem_passphrase=mongodb_client_test_ssl)

Patch and run updated version of your OS and MongoDB

Applying security patches is an important part of maintaining Linux or Unix server. Linux provides all necessary tools to keep your system updated, and also allows for easy upgrades between versions. See “20 Linux Server Hardening Security Tips” for more information.



Sunday, May 22, 2016

Transfering SQL database between two linux servers

Process for moving a database between two linux servers running mysql.

Target server may or may not have the database created.  example used uses phpmydmin create database to create the empty database.

Use mysqldump to create an ".sql" file with the data from the database.  Example here is for an RSS reader application, and keeps track of the rss feeds for doing deltas for the read presentation.

Note for sql the password and user id are for the mysql users and the password on the mysql server.  They are not linux account passwords.  The commands can be performed from any userid with access to the mysql commands, since the database is worked via the mysqldump command to the mysql socket.  Access to the actual files is not required, since the work is done on those files by the mysql server.

backup:

 mysqldump --password=<some-password> -u <userid> rss > 2016-0522-rss-mysqldump.sql

create database in phpmyadmin: 

Databases->Create new Database [enter rss in name field] (Create)

restore:

mysql -u <userid> --password=<password> rss < 2016-0522-rss-mysqldump.sql


Friday, March 27, 2015

Lamp server install link



Here is a nice LAMP server setup page.

Using and posting this from a 2" x 2" x 2" quad core cubox debian system.

https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-debian

Will copy edit inline later on update.

use sudo apt-get -y install apache2 mysql-server mysql-client php5-cli phpmyadmin 
to get that running

Install mysql
Install apache2 (if not by default)
install php

if php is installed prior to apache you may need to install

libapache2-mod-php7.0 (or whatever php if earlier or later install)