Ubuntu point all .test domains to 127.0.0.1
Install dnsmasq on Ubuntu
Category: Linux
-
Ubuntu point all .test domains to 127.0.0.1
Until recently .dev was popular TLD used by developers for local web development. Recently google acquired the rights to use .DEV domain name extension and forced SSL for this LTD in google chrome.
Web developers are looking for alternate home for their local development web sites. Some suggested .localhost as development LTD, but it is too large. Another option is .test, this is a reserved LTD, so you won’t be forced to leave and is short. So many opted for .test as local development domain extension.
DNSMasq allow you to point *.test domains to 127.0.01, so you don’t have to edit /etc/hosts and add each domain you need for local development.
To do this, create file
vi /etc/NetworkManager/dnsmasq.d/test
Add following
address=/.test/127.0.0.1
Restart network-manager.
service network-manager restart
We restarted network-manager as dnsmasq is started by Network Manager.
root@hon-pc-01:~# pstree -sp $(pidof dnsmasq)
systemd(1)───NetworkManager(11557)───dnsmasq(11594)
root@hon-pc-01:~# -
certbot certificates
To list all letsencrypt SSL certificates, run
certbot certificates
Example
root@ok:~# certbot certificates Saving debug log to /var/log/letsencrypt/letsencrypt.log Revocation status for /etc/letsencrypt/live/boby.hosthat.com/cert.pem is unknown ------------------------------------------------------------------------------- Found the following certs: Certificate Name: boby.hosthat.com Domains: boby.hosthat.com Expiry Date: 2017-06-11 15:10:00+00:00 (INVALID: EXPIRED) Certificate Path: /etc/letsencrypt/live/boby.hosthat.com/fullchain.pem Private Key Path: /etc/letsencrypt/live/boby.hosthat.com/privkey.pem Certificate Name: img.serverok.in Domains: img.serverok.in Expiry Date: 2018-05-02 16:06:53+00:00 (VALID: 66 days) Certificate Path: /etc/letsencrypt/live/img.serverok.in/fullchain.pem Private Key Path: /etc/letsencrypt/live/img.serverok.in/privkey.pem Certificate Name: lab.hostonnet.com Domains: lab.hostonnet.com Expiry Date: 2018-04-25 03:34:37+00:00 (VALID: 59 days) Certificate Path: /etc/letsencrypt/live/lab.hostonnet.com/fullchain.pem Private Key Path: /etc/letsencrypt/live/lab.hostonnet.com/privkey.pem Certificate Name: yboby.cf Domains: yboby.cf www.yboby.cf Expiry Date: 2018-03-21 19:43:49+00:00 (VALID: 25 days) Certificate Path: /etc/letsencrypt/live/yboby.cf/fullchain.pem Private Key Path: /etc/letsencrypt/live/yboby.cf/privkey.pem ------------------------------------------------------------------------------- root@ok:~#
-
Syntax error or access violation: 1071 Specified key was too long
When running database migration in a new larvel project, i get following error
boby@hon-pc-01:~/www/proxy (master)$ php artisan migrate
In Connection.php line 664:
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table `users` add unique `users_email_unique`(`email`))
In Connection.php line 458:
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
boby@hon-pc-01:~/www/proxy (master)$
This is due to recent change in Lavral, that changed default charset to utf8mb4.
To fix this error, open file
vi app/Providers/AppServiceProvider.php
Find
use Illuminate\Support\ServiceProvider;
Add below
use Illuminate\Support\Facades\Schema;
Find
public function boot() { // }
Replace with
public function boot() { Schema::defaultStringlength(191); }
-
iptables
- How to list iptables rules
- Block an IP using iptables
- Open MySQL Port 3306 in CentOS 7
- Saving iptables firewall rules
- Port forward using iptables
- iptables -F lock me out
- How to redirect traffic to another IP using iptables
To list current rules, run
iptables -S
Or
iptables -L
To list rules in numeric format, run
iptables -nvL
Or
iptables -L -n
To view nat rules
iptables -t nat -L -n --line-number
To see rules with counter, use
iptables -L -n -v
Open port 80
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
To open port 8080 in iptables firewall, run
iptables -A INPUT -m state --state NEW -p tcp --dport 8080 -j ACCEPT
Open Port Range
iptables -A INPUT -p tcp --match multiport --dports 50000:60000 -j ACCEPT
Whitelist an IP
iptables --append INPUT --protocol tcp --source 64.57.102.34 --jump ACCEPT
Forward a Port to Another
All request on port 80 will get forwarded to port 7080
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to-destination :7080
Saving IP tables
Above IP table commands take effect immediatly, but they get lost when you reboot the PC. To make it permanent, run
service save iptables
You can also use
iptables-save > /etc/sysconfig/iptables
Related config are saved in
/etc/sysconfig/iptables /etc/iptables/iptables.rules
Before Flush
Make sure all Chains are set to ACCEPT, if DROP, run
iptables -P INPUT ACCEPT iptables -P OUTPUT ACCEPT iptables -P FORWARD ACCEPT iptables -F
-
mosquitto
mosquitto is an Open Source MQTT server. MQTT is a machine to machine or IOT (Internet of Things) protocol.
To install run
apt-get install mosquitto mosquitto-clients
To test, run
mosquitto_sub -h localhost -t test
To create a user, run
mosquitto_passwd -c /etc/mosquitto/passwd USER_NAME
Config file available at
/etc/mosquitto/conf.d/default.conf
To restart, use
systemctl restart mosquitto
To connect with user and password, use
mosquitto_sub -h localhost -t test -u "USER_NAME" -P "PASSWORD"
-
Installing nvm (Node.js Version Manager)
nvm is a node version manager, which allows you to run multiple versions of node.js
To install nvm, run
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
To list all available node versions, run
nvm ls-remote
To install a particular node.js version, run
nvm install 22
To activate/select a node.js version, use
nvm use 22
To set default node,.js version, run
nvm alias default 22
to list all installed node.js versions
nvm ls
The versions with N/A are not installed.
-
Magento
https://vuestorefront.io – store front for magento.
Magento 2
- Magento 2 Enable SSL
- Magento 2 CLI
- Install Elasticsearch on Debian for Magento
- Enable memcached on Magento 2 in Plesk Server
- Magento 2 Unable to proceed: the maintenance mode is enabled
- How to Enable Magento 2 Cronjob
- Magento Disable CDN
- Magento 2 admin too many redirects error
- Magento 2 Password reset
- ionos Magento Internal Server Error
- Magento 2 htaccess
- Magento 2 static resources missing after server change
- Validate class not found from basename Magento\Framework\Validator\EmailAddress
- Magento 2 Disable Two-Factor Authorization
Magento 2 Login Errors
Magento version
To find the version, go to
https://URL/magento_version
Magento 1.9
- Magento 1 Command Line Tool
- Cronjob for Magento 1.9
- Magento 1.9 Nginx Configuration
- Clean Magento session folder
- Magento 1.9 store login not working in Chrome
- Change Magento 1.9 admin URL
- Enable SSL in Magento 1.9
- Magento Change URL
- Magento 1 Password Reset
- Magento 1 Invalid Form Key
- Magento catalog_product_relation MySQL Error
- How to clean Magento 1.x database
-
CakePHP
After moving CakePHP application from one server to another with different DocumentRoot, site still try to load file from OLD directory. To fix this, delete the file
rm tmp/cache/persistent/myapp_cake_core_file_map
Once deleted, this file get auto created with new paths.
-
Backup Webite to Amazon S3
Create file
mkdir /usr/serverok/ vi /usr/serverok/backup-daily.sh
Add
#!/bin/bash BACKUP_FILE="backup-`date +%Y-%m-%d`.tgz" /bin/tar --exclude-tag-under=no-backup -zcvhf /backup/$BACKUP_FILE /var/www/html/ aws s3 cp /backup/$BACKUP_FILE s3://S3_BUCKET_NAME/ rm -f /backup/$BACKUP_FILE
Make the file executable
chmod 755 /usr/serverok/backup-daily.sh
Set it run everyday with cronjob
@daily /usr/serverok/backup-daily.sh > /var/log/backup-daily.log 2>&1
To backup MySQL database, use
https://serverok.in/mysqldump-backup
See Backup
-
logrotate
logrotate is a program to rotates logs. This is run daily using cronjob
/etc/cron.daily/logrotate
Logrotate config files are stored in
/etc/logrotate.d/
To rotate logs daily, add daily to the logrotate configuration. To keep logs for 5 days, add “rotate 5”.
Rotating a log
To rotate a log
/var/log/sync-servers.log
Create file
vi /etc/logrotate.d/sync-servers
with content
/var/log/sync-servers.log { create 640 root adm missingok notifempty rotate 4 weekly }