A collection of my gists, quick guides, and snippets curated over time.
March 5, 2020
First, unlink the default configuration which shows Nginx Welcome page on port 80 using the command
path /etc/nginx/sites-enabled
$ sudo unlink default
Create a new .conf file with reverse proxy configuration
path /etc/nginx/conf.d
$ sudo nano sites.conf
Use the following config for each reverse proxy that you want to apply
server {
listen 80 default_server;
server_name yourdomain.com www.yourdomain.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://localhost:3000;
}
}
server {
listen 80;
server_name yourdomain.in www.yourdomain.in;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://localhost:5000;
}
}
Now, test your configurations using:
$ sudo nginx -t
Check nginx status to verify that everything is working properly
$ sud...
February 3, 2020
In /etc/apache2/sites-available/ directory create a new file named phpmyadmin.conf
$ sudo nano phpmyadmin.conf
The content of the file should be:
Listen 2222
<VirtualHost *:2222>
ServerName localhost
<Directory /usr/share/phpmyadmin>
AllowOverride None
Require all granted
</Directory>
DocumentRoot /usr/share/phpmyadmin
Include /etc/phpmyadmin/apache.conf
ErrorLog ${APACHE_LOG_DIR}/phpmyadmin.error.log
CustomLog ${APACHE_LOG_DIR}/phpmyadmin.access.log combined
</VirtualHost>
Disable the /etc/apache2/conf-enabled/phpmyadmin.conf file due to which phpmyadmin is accessible from any domain on apache using the command:
sudo a2disconf phpmyadmin
Now, enable the new config that we create at `/etc/apache2/sites-available/phpmyadmin.c...
January 28, 2020
To import a sql database using terminal, use this command:
$ mysql -u username -p -h localhost DATABASE_NAME < file_name.sql
To export a database, use the following command:
$ mysqldump -u username -p DATABASE_NAME > file_name.sql
September 11, 2019
SSH into instance using private key or shell provided by the cloud service provider.
If you want to create a new user than run
$ sudo adduser username
$ sudo addpasswd username
Go to etc/ssh/ and edit sshd_config file.
$ cd /etc/ssh
$ sudo vi sshd_config
Set Following as:
PasswordAuthentication yes
If you also want root user to login with password (without private key) set:
PermitRootLogin yes
Restart SSH service:
sudo service ssh restart
Exit your current session and login using your new credentials.
Protip: If you cant remember your private key use NoIP to get a domain name that you can use to SSH.
June 17, 2019
Step by step guide to install MongoDB on Ubuntu.
First update the packages
$ sudo apt-get update
install the MongoDB package
$ sudo apt install -y mongodb
$ sudo systemctl status mongodb
You should see something like this:
● mongodb.service - An object/document-oriented database
Loaded: loaded (/lib/systemd/system/mongodb.service; disabled; vendor preset:
Active: active (running) since Mon 2019-06-17 20:20:39 IST; 6s ago
Docs: man:mongod(1)
Main PID: 28176 (mongod)
Tasks: 23 (limit: 4915)
CGroup: /system.slice/mongodb.service
└─28176 /usr/bin/mongod --unixSocketPrefix=/run/mongodb --config /etc
To know the status of the MongoDB, use:
$ sudo systemctl status mongodb
To stop the MongoDB server, use:
$ sudo systemctl stop mongodb
To start...
June 13, 2019
Step by step guide to install LAMP server on Linux.
Use the terminal to execute these commands
sudo apt install apache2
sudo apt install mysql-server
After installation run this command to remove some dangerous defaults and lock down access to your database system.
sudo mysql_secure_installation
This will ask if you want to configure the VALIDATE PASSWORD PLUGIN.
Answer Y for yes, or anything else to continue without enabling.
Remove anonymous users? : Y
Disallow root login remotely? : Y
Remove test database and access to it? : Y
Reload privilege tables now? : Y
Now enter mysql
sudo mysql
View all user accounts using
mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;
Now, to set a new password for root user, replace 'password' with your own password.