et record counts for all tables in MySQL database

show table status;

SELECT SUM(TABLE_ROWS)
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = ‘your_db_name’

SELECT
TABLE_NAME, SUM(TABLE_ROWS)
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = ‘your_db_name’
GROUP BY TABLE_NAME;

Laravel Gmail not working, “Username and Password not accepted. Learn more…”

If you got error while sending email by using gmail (as sender ) at live server.

error message” Username and Password not accepted. Lea$
535 5.7.8 https://support.google.com/mail/?p=BadCredentials w187sm24324471pfw.62 – gsmtp”

Go to this link and disable unlock Captcha

https://accounts.google.com/b/0/DisplayUnlockCaptcha

This is simply because Google blocked unsecure login to SMTP by default because for security

Configure Postfix to use Office365 SMTP Relay on Ubuntu 18.04

Configure Postfix to use Office365 SMTP Relay on Ubuntu 18.04

In this post I’ll show how to install and configure Postfix on Ubuntu 16.04 to use Office 365 services like smarthost/mail relay.

apt-get upgrade
apt-get update
apt-get install postfix sasl2-bin mailutils

sasl2-bin is an API thet implement Cyrus SASL API, and permit to integrate authentication mechanisms in Postfix
mailutils is a simple mail commands that will help testing our configuration.

During the Postfix configuration in request “General type of mail configuation” select “Internet Site”, and set your “System mail name” to use your FQDN (Fully Qualified Domain Name): in my case mailserver.infpressapochista.local
You can use the next command to obtain your FQDN.

hostname –fqdn
Now we need to define the credentials that will be used to establish the connection with Office 365 smtp server.
Create a file called sasl_passwd in /etc/postfix that contains the credentials: the username and password.

[smtp.office365.com]:587 usernameOffice365@domainOffice365.it:password
Att.: Replace usernameOffice365@domainOffice365.it and password with the appropriate credentials.
Postfix for some config files doesn’t use the flat ascii format, but uses a hash version of the same files that allows quicker lookup/retrieval.
This is one of them !

postmap hash:/etc/postfix/sasl_passwd
This command create an hash version of sasl_passwd plain ascii file: in /etc/postfix you should see sasl_passwd and sasl_passwd.db in the list.

Using Office 365 smtp we can only send mail (FROM field in email header) as the user we are connecting with, or an another account specified in office365 (Send As permission).

For this reason we need to configure postfix to modify the from field for all the outgoing mail.
Create a file called sender_canonical in /etc/postfix.

nano /etc/postfix/sender_canonical
Here you can add the next line.

/.+/ usernameOffice365@domainOffice365.it
Att.: Replace usernameOffice365@domainOffice365.it with the same account used in /etc/postfix/sasl_passwd or an another enabled account.
Create the hash version.

postmap hash:/etc/postfix/sender_canonical
For security purposes let’s make sure the owner of the files created above is the root user and the permissions are 644.

chown root:root /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
chmod 644 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
chown root:root /etc/postfix/sender_canonical /etc/postfix/sender_canonical.db
chmod 644 /etc/postfix/sender_canonical /etc/postfix/sender_canonical.db
I prefer to use TLS to transmit mail.

cp /etc/ssl/certs/thawte_Primary_Root_CA.pem /etc/postfix/cacert.pem
Now we can configure Postfix to use this files. Edit /etc/postfix/main.cf and add/modify the following lines to our main.cf

…..
inet_protocols = ipv4
relayhost = [smtp.office365.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_security_level = may
sender_canonical_maps = regexp:/etc/postfix/sender_canonical
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_use_tls = yes
…..
Att.: The line inet_protocols = ipv4 force postfix to use only ipv4.

Restart Posfix.

service postfix restart
Now we can send a test message to see if everything worked. Create a file like /etc/postfix/mailtest.txt

to: emailto@domain.it
subject:Subject Test
Att.: Replace emailto@domain.it with the address you want to send your test to.

sendmail -v emailto@domanin.it < /etc/postfix/mailtest.txt Att.: Replace emailto@domain.it with the address you want to send your test to. If your test fails you can check the mail.log file to try and determine why.

tail – f /var/log/mail.log
Att.: After making changes be sure to restart Postfix before testing.
service postfix restart

Ref::

Configure Postfix to use Office365 SMTP Relay on Ubuntu 16.04

Enable MySQL Server Remote Connection in Ubuntu

Enable MySQL Server Remote Connection in Ubuntu

By default MySQL Server on Ubuntu run on the local interface, This means remote access to the MySQL Server is not Allowed. To enable remote connections to the MySQL Server we need to change value of the bind-address in the MySQL Configuration File.

First, Open the /etc/mysql/mysql.conf.d/mysqld.cnf file (/etc/mysql/my.cnf in Ubuntu 14.04 and earlier versions).

vim /etc/mysql/mysql.conf.d/mysqld.cnf

Under the [mysqld] Locate the Line,

bind-address = 127.0.0.1

And change it to,

bind-address = 0.0.0.0

systemctl restart mysql.service

Now Ubuntu Server will allow remote access to the MySQL Server, But still you need to configure MySQL users to allow access from any host.

For example, when you create a MySQL user, you should allow access from any host.

CREATE USER ‘username’@’%’ IDENTIFIED BY ‘password’;

Or Allow from Specific IP Address,

CREATE USER ‘username’@’192.168.1.100’ IDENTIFIED BY ‘password’;

The output should show that MySQL Server running on the socket 0 0.0.0.0:3306 instead of 127.0.0.1:3306.

MySQL Server running on the socket 0 0.0.0.0:3306
You can also try to telnet to the MySQL port 3306 from a remote host. For example, if the IP Address of your Ubuntu Server is 192.168.1.10, Then from the remote host execute,

telnet 192.168.1.10 3306

You can also run the nmap command from a remote computer to check whether MySQL port 3306 is open to the remote host.

nmap 192.168.1.10

The output should list MySQL port 3306 and the STATe should be open. If the MySQL port 3306 not open, Then there is a firewall which blocks the port 3306.

Troubleshoot Ubuntu MySQL Remote Access
To make sure that, MySQL server listens on all interfaces, run the netstat command as follows.

netstat -tulnp | grep mysql

How to Create a New User

Log in to the MySQL server.
Log in to MySQL with the command mysql -u root -p
Type the MySQL root user password.

CREATE USER ‘newuser’@’localhost’ IDENTIFIED BY ‘password’;
GRANT ALL PRIVILEGES ON * . * TO ‘newuser’@’localhost’;
FLUSH PRIVILEGES;

How To Grant Different User Permissions

Issue the MySQL command:
To allow specific IP for specifi user
GRANT ALL ON wordpressdb.* TO ‘wpadmin’@’192.168.1.100’ IDENTIFIED BY ‘%u#098Tl3’ WITH GRANT OPTION;

To allow any IP for specifi user
GRANT ALL ON wordpressdb.* TO ‘wpadmin’@’%’ IDENTIFIED BY ‘%u#098Tl3’ WITH GRANT OPTION;

Flush the MySQL privileges with the command
FLUSH PRIVILEGES;

Exit out of the MySQL prompt with the command exit;

LAMP with Yii1

Installing PHP

    sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt

    Install php extensions

        sudo apt-get install php5-mysql
        sudo apt-get install php5-sqlite
        sudo apt-get install php5.6-mbstring
        sudo apt-get install libapache2-mod-php5.6

In most cases, we’ll want to modify the way that Apache serves files when a directory is requested. 
Currently, if a user requests a directory from the server, Apache will first look for a file called index.html. 
We want to tell our web server to prefer PHP files, so we’ll make Apache look for an index.php file first.

To do this, type this command to open the dir.conf file in a text editor with root privileges:

sudo nano /etc/apache2/mods-enabled/dir.conf
It will look like this:


    DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm

We want to move the PHP index file highlighted above to the first position after the DirectoryIndex specification, like this:


    DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm



----------------------------------------------------------------

Install Multiple PHP Versions on Ubuntu 16.04

Install PHP 5.6

Step 1: Update Apt-Get
apt-get update && apt-get upgrade
apt-get install -y software-properties-common
add-apt-repository ppa:ondrej/php
apt-get update

Step 2: Install PHP 5.6
apt-get install -y php5.6

Changing PHP Version for Apache (if your server have more than one php version)

a2dismod php7.0; a2enmod php5.6; service apache2 restart
a2dismod php5.6; a2enmod php7.0; service apache2 restart

Changing PHP Version for Ubuntu

update-alternatives --config php
and then choose one php version for command line ( Ubuntu )

----------------------------------------------------------------


Installing Apache Web Server

Step 1 — 
    sudo apt update
    sudo apt install apache2

Step 2 — Adjusting the Firewall

    sudo ufw app list
    sudo ufw allow 'Apache'
    sudo ufw status

    or custom port allow

    sudo ufw allow 8080
    sudo ufw reload

Step 3 — Checking your Web Server

    sudo systemctl status apache2

    hostname -I
    at command line : curl -4 testwebsite.com
    at browser : http://your_server_ip

Step 4 — Managing the Apache Process

    sudo systemctl stop apache2
    sudo systemctl start apache2
    sudo systemctl restart apache2
    sudo systemctl reload apache2
    sudo systemctl disable apache2
    sudo systemctl enable apache2

Step 5 — Setting Up Virtual Hosts (Recommended)

    sudo mkdir /var/www/your_domain
    sudo chown -R $USER:$USER /var/www/your_domain
    sudo chmod -R 755 /var/www/your_domain

    nano /var/www/your_domain/index.html
    and added some html code into index.html

    sudo nano /etc/apache2/sites-available/your_domain.conf

    /etc/apache2/sites-available/your_domain.conf
    
        ServerAdmin webmaster@localhost
        ServerName your_domain
        ServerAlias www.your_domain
        DocumentRoot /var/www/your_domain
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    

    Or 

    
        ServerName ipaddress
        DocumentRoot /var/www/html/testwebsite
        
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        
    	

Allowing Rewrite rules to Apache2 Web Server at Ubuntu

    a2enmod rewrite
    systemctl restart apache2

Let’s enable the file with the a2ensite tool:

    sudo a2ensite your_domain.conf

Disable the default site defined in 000-default.conf:

    sudo a2dissite 000-default.conf

Next, let’s test for configuration errors:

    sudo apache2ctl configtest

You should see the following output:

Output
Syntax OK

Restart Apache to implement your changes:

    sudo systemctl restart apache2

Checking Errors log at Apache Server

/var/log/apache2/access.log

----------------------------------------------------------------

Installing MySQL to Manage Site Data

    sudo apt install mysql-server php5-mysql
    sudo mysql_secure_installation

Allow MySql without 'sudo' at command line
    sudo mysql
    mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;
    mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
    mysql> FLUSH PRIVILEGES;
    mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;
    mysql> exit
and then, you can access mysql without sudo 'mysql -u root -p'

Adding new user and grant databases / only one database

    // Creating new database user
    CREATE USER 'YourUserName'@'localhost' IDENTIFIED BY 'YourPassword';
    CREATE USER 'YourUserName'@'%' IDENTIFIED BY 'YourPassword';

    // Granting the one user to all database
    GRANT ALL ON *.* TO 'YourUserName'@'localhost';
    GRANT ALL ON *.* TO 'YourUserName'@'%';

    // Granting the one user to one database
    GRANT ALL ON YourDatabaseName.* TO 'YourUserName'@'localhost';
    GRANT ALL ON YourDatabaseName.* TO 'YourUserName'@'%';

----------------------------------------------------------------    


Ubuntu OS မွာ Apache ၿဖင္႔ PHP ကို Multiple Versions ေၿပာင္းလဲ အသံုးၿပဳၿခင္း

Ubuntu OS မွာ Apache ၿဖင္႔ PHP ကို Multiple Versions ေၿပာင္းလဲ အသံုးၿပဳၿခင္း
အကယ္၍ မိမိ development လုပ္ေနေသာ Environment မွာ PHP ကို Version တစ္မ်ဴိးထက္ပိုၿပီး Install လုပ္ထားရတယ္ ( eg. 5.6 and 7.3 )။ မိမိရဲ႕ Project ရဲ႕လုိအပ္ခ်က္အရ PHP ကို Version 5.6 နဲ႕ 7.3 Version ၂ မ်ဴိးလံုးအသံုးၿပဳဖုိ႕လိုအပ္ခဲ႕လွ်င္
——————————————————-
ဥပမာ အေနနဲ႕
Project1 – Yii Framework Version 1 – PHP 5.6
Project2 – Laravel Framework Version 5.7 – PHP 7.3
——————————————————-
user_name@ubuntu1804:~$ sudo update-alternatives –config php

There are 3 choices for the alternative php (providing /usr/bin/php).

Selection Path Priority Status
————————————————————

First Way 

user_name@ubuntu1804:~$ sudo update-alternatives –config php

0 /usr/bin/php7.3 73 auto mode
1 /usr/bin/php5.6 56 manual mode
2 /usr/bin/php7.2 72 manual mode
* 3 /usr/bin/php7.3 73 manual mode

Press <enter> to keep the current choice[*], or type selection number: 3

user_name@ubuntu1804:~$ php -v
PHP 7.3.12-1+ubuntu18.04.1+deb.sury.org+1 (cli) (built: Nov 28 2019 07:37:16) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.12, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.12-1+ubuntu18.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies

user_name@ubuntu1804:~$ sudo systemctl restart nginx
user_name@ubuntu1804:~$

———————————————————————————————————–

Another Way
How to change PHP Version for Apache
Enable php 5.6  and disable php 7.3
sudo a2dismod php7.3
sudo a2enmod php5.6
sudo service apache2 restart
Enable php 7.3  and Disable php 5.6
sudo a2dismod php5.6
sudo a2enmod php7.3
sudo service apache2 restart
/var/www/html folder ထဲတြင္ info.php ဆိုၿပီး PHP Script File တစ္ခုတည္ေဆာက္ၿပီး
<?php
phpinfo();
?>
ဆုိၿပီး သိမ္းဆည္းလိုက္ပါ။ ၿပီးလွ်င္ Browser မွ http://localhost/info.php ဆိုၿပီးေခၚၿကည္႔လုိက္ပါ။
မိမိရဲ႕ Apache Web Server ရဲ႕ လက္ရွိ PHP Version ကို ၿမင္ရပါလိမ္႔မယ္။
———————————————-
How to change PHP Version for Ubuntu ( command line usage )
Terminal ( Command Line ) တြင္
sudo update-alternatives –config php
PHP Version selection Questions ေပၚလာပါလိမ္႔မယ္။ မိမိ အလုိရွိေသာ PHP Version ကိုေရြးခ်ယ္ ေၿပာင္းလဲလုိ႕ရပါသည္။ ေၿပာင္းလဲၿပီးစီးသည္႔အခါ Teminal တြင္
php -v
ၿဖင္႔ PHP current version ကို ေခၚၿကည္ႏုိင္ပါသည္။
————————————————–
OS – Ubuntu – 16.04 / 18.04
Web Server – Apache
PHP – 5.6 & 7.3
—————————————————
Wai Yan Aung
20190921

JHipster

HOw to install JHipster ( Latest Version )

Quick setup

  1. Install Java 11. We recommend you use AdoptOpenJDK builds, as they are open source and free.
  2. Install Node.js from the Node.js website (please use an LTS 64-bit version, non-LTS versions are not supported)
  3. Install JHipster: npm install -g generator-jhipster
  4. (optional) If you want to use a module or a blueprint (for instance from the JHipster Marketplace), install Yeomannpm install -g yo

Ref :: https://www.jhipster.tech/installation/

 

How to install JHipster Old Version
npm install -g generator-jhipster@5.2.1

 

Uninstall JHipster 
whereis jhipster
sudo rm -rf /opt/node-v10.16.0-linux-x64/bin/jhipster