Wednesday, October 16, 2019

php: Enable PHP7 yum installation on CentOS7

When I tried to use phpunit 8.4, I was required to use PHP7.
Since I am using CentOS7, I did needed to following method to install/setting up PHP7.

Found a really helpful site below:
How to Install PHP 7.3 in CentOS 7

# After installed phpunit 8.4, that says it requires PHP7.
[root@08-00-27-2C-51-D6 ~]# php phpunit-8.4.phar --version
PHPUnit 8.4.1 by Sebastian Bergmann and contributors.

This version of PHPUnit is supported on PHP 7.2, PHP 7.3, and PHP 7.4.
You are using PHP 5.4.16 (/usr/bin/php).


# Enable EPEL.
[root@08-00-27-2C-51-D6 ~]# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
Loaded plugins: fastestmirror
epel-release-latest-7.noarch.rpm                                                                 |  15 kB  00:00:00
Examining /var/tmp/yum-root-RVhXhS/epel-release-latest-7.noarch.rpm: epel-release-7-12.noarch
Marking /var/tmp/yum-root-RVhXhS/epel-release-latest-7.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-12 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================
 Package                    Arch                 Version              Repository                                   Size
========================================================================================================================
Installing:
 epel-release               noarch               7-12                 /epel-release-latest-7.noarch                24 k

Transaction Summary
========================================================================================================================
Install  1 Package

Total size: 24 k
Installed size: 24 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : epel-release-7-12.noarch                                                                             1/1
  Verifying  : epel-release-7-12.noarch                                                                             1/1

Installed:
  epel-release.noarch 0:7-12

Complete!
# Enable REMI as well.
[root@08-00-27-2C-51-D6 ~]# yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
Loaded plugins: fastestmirror
remi-release-7.rpm                                                                               |  17 kB  00:00:00
Examining /var/tmp/yum-root-RVhXhS/remi-release-7.rpm: remi-release-7.7-1.el7.remi.noarch
Marking /var/tmp/yum-root-RVhXhS/remi-release-7.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package remi-release.noarch 0:7.7-1.el7.remi will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================
 Package                     Arch                  Version                         Repository                      Size
========================================================================================================================
Installing:
 remi-release                noarch                7.7-1.el7.remi                  /remi-release-7                 23 k

Transaction Summary
========================================================================================================================
Install  1 Package

Total size: 23 k
Installed size: 23 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : remi-release-7.7-1.el7.remi.noarch                                                                   1/1
  Verifying  : remi-release-7.7-1.el7.remi.noarch                                                                   1/1

Installed:
  remi-release.noarch 0:7.7-1.el7.remi

Complete!



# Install yum-utils.
[root@08-00-27-2C-51-D6 ~]# yum install yum-utils
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
epel/x86_64/metalink                                                                             | 6.0 kB  00:00:00
 * base: ftp.jaist.ac.jp
 * epel: ftp.jaist.ac.jp
 * extras: ftp.jaist.ac.jp
 * remi-safe: ftp.riken.jp
 * updates: ftp.jaist.ac.jp
epel                                                                                             | 5.3 kB  00:00:00
remi-safe                                                                                        | 3.0 kB  00:00:00
(1/4): epel/x86_64/group_gz                                                                      |  88 kB  00:00:00
(2/4): epel/x86_64/updateinfo                                                                    | 1.0 MB  00:00:03
(3/4): epel/x86_64/primary_db                                                                    | 6.9 MB  00:00:03
(4/4): remi-safe/primary_db                                                                      | 1.6 MB  00:00:09
Resolving Dependencies
--> Running transaction check
---> Package yum-utils.noarch 0:1.1.31-52.el7 will be installed
--> Processing Dependency: python-kitchen for package: yum-utils-1.1.31-52.el7.noarch
--> Processing Dependency: libxml2-python for package: yum-utils-1.1.31-52.el7.noarch
--> Running transaction check
---> Package libxml2-python.x86_64 0:2.9.1-6.el7_2.3 will be installed
---> Package python-kitchen.noarch 0:1.1.1-5.el7 will be installed
--> Processing Dependency: python-chardet for package: python-kitchen-1.1.1-5.el7.noarch
--> Running transaction check
---> Package python-chardet.noarch 0:2.2.1-3.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================
 Package                         Arch                    Version                            Repository             Size
========================================================================================================================
Installing:
 yum-utils                       noarch                  1.1.31-52.el7                      base                  121 k
Installing for dependencies:
 libxml2-python                  x86_64                  2.9.1-6.el7_2.3                    base                  247 k
 python-chardet                  noarch                  2.2.1-3.el7                        base                  227 k
 python-kitchen                  noarch                  1.1.1-5.el7                        base                  267 k

Transaction Summary
========================================================================================================================
Install  1 Package (+3 Dependent packages)

Total download size: 862 k
Installed size: 4.3 M
Is this ok [y/d/N]: y
Downloading packages:
(1/4): yum-utils-1.1.31-52.el7.noarch.rpm                                                        | 121 kB  00:00:00
(2/4): python-kitchen-1.1.1-5.el7.noarch.rpm                                                     | 267 kB  00:00:00
(3/4): python-chardet-2.2.1-3.el7.noarch.rpm                                                     | 227 kB  00:00:00
(4/4): libxml2-python-2.9.1-6.el7_2.3.x86_64.rpm                                                 | 247 kB  00:00:01
------------------------------------------------------------------------------------------------------------------------
Total                                                                                   565 kB/s | 862 kB  00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : python-chardet-2.2.1-3.el7.noarch                                                                    1/4
  Installing : python-kitchen-1.1.1-5.el7.noarch                                                                    2/4
  Installing : libxml2-python-2.9.1-6.el7_2.3.x86_64                                                                3/4
  Installing : yum-utils-1.1.31-52.el7.noarch                                                                       4/4
  Verifying  : python-kitchen-1.1.1-5.el7.noarch                                                                    1/4
  Verifying  : yum-utils-1.1.31-52.el7.noarch                                                                       2/4
  Verifying  : libxml2-python-2.9.1-6.el7_2.3.x86_64                                                                3/4
  Verifying  : python-chardet-2.2.1-3.el7.noarch                                                                    4/4

Installed:
  yum-utils.noarch 0:1.1.31-52.el7

Dependency Installed:
  libxml2-python.x86_64 0:2.9.1-6.el7_2.3   python-chardet.noarch 0:2.2.1-3.el7   python-kitchen.noarch 0:1.1.1-5.el7

Complete!


# Enable PHP7 installation with yum-config-manager.
[root@08-00-27-2C-51-D6 ~]# yum-config-manager --enable remi-php70
Loaded plugins: fastestmirror
=================================================== repo: remi-php70 ===================================================
[remi-php70]
async = True
bandwidth = 0
base_persistdir = /var/lib/yum/repos/x86_64/7
baseurl =
cache = 0
cachedir = /var/cache/yum/x86_64/7/remi-php70
check_config_file_age = True
compare_providers_priority = 80
cost = 1000
deltarpm_metadata_percentage = 100
deltarpm_percentage =
enabled = 1
enablegroups = True
exclude =
failovermethod = priority
ftp_disable_epsv = False
gpgcadir = /var/lib/yum/repos/x86_64/7/remi-php70/gpgcadir
gpgcakey =
gpgcheck = True
gpgdir = /var/lib/yum/repos/x86_64/7/remi-php70/gpgdir
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
hdrdir = /var/cache/yum/x86_64/7/remi-php70/headers
http_caching = all
includepkgs =
ip_resolve =
keepalive = True
keepcache = False
mddownloadpolicy = sqlite
mdpolicy = group:small
mediaid =
metadata_expire = 21600
metadata_expire_filter = read-only:present
metalink =
minrate = 0
mirrorlist = http://cdn.remirepo.net/enterprise/7/php70/mirror
mirrorlist_expire = 86400
name = Remi's PHP 7.0 RPM repository for Enterprise Linux 7 - x86_64
old_base_cache_dir =
password =
persistdir = /var/lib/yum/repos/x86_64/7/remi-php70
pkgdir = /var/cache/yum/x86_64/7/remi-php70/packages
proxy = False
proxy_dict =
proxy_password =
proxy_username =
repo_gpgcheck = False
retries = 10
skip_if_unavailable = False
ssl_check_cert_permissions = True
sslcacert =
sslclientcert =
sslclientkey =
sslverify = True
throttle = 0
timeout = 30.0
ui_id = remi-php70
ui_repoid_vars = releasever,
   basearch
username =



[root@08-00-27-2C-51-D6 ~]# yum-config-manager --enable remi-php71

[root@08-00-27-2C-51-D6 ~]# yum-config-manager --enable remi-php72

[root@08-00-27-2C-51-D6 ~]# yum-config-manager --enable remi-php73


# Install php.
[root@08-00-27-2C-51-D6 ~]# yum install php php-mcrypt php-cli php-gd php-curl php-mysql php-ldap php-zip php-fileinfo
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.jaist.ac.jp
 * epel: ftp.jaist.ac.jp
 * extras: ftp.jaist.ac.jp
 * remi-php70: ftp.riken.jp
 * remi-php71: ftp.riken.jp
 * remi-php72: ftp.riken.jp
 * remi-php73: ftp.riken.jp
 * remi-safe: ftp.riken.jp
 * updates: ftp.jaist.ac.jp
remi-php70                                                                                       | 3.0 kB  00:00:00
remi-php71                                                                                       | 3.0 kB  00:00:00
remi-php72                                                                                       | 3.0 kB  00:00:00
remi-php73                                                                                       | 3.0 kB  00:00:00
(1/4): remi-php73/primary_db                                                                     | 206 kB  00:00:02
(2/4): remi-php72/primary_db                                                                     | 228 kB  00:00:02
(3/4): remi-php70/primary_db                                                                     | 231 kB  00:00:02
(4/4): remi-php71/primary_db                                                                     | 242 kB  00:00:02
Package php-mcrypt is obsoleted by php-pecl-mcrypt, trying to install php-pecl-mcrypt-1.0.3-1.el7.remi.7.3.x86_64 instead
Package php-mysql is obsoleted by php-mysqlnd, trying to install php-mysqlnd-7.3.10-1.el7.remi.x86_64 instead
Resolving Dependencies
--> Running transaction check
---> Package php.x86_64 0:5.4.16-46.el7 will be updated
---> Package php.x86_64 0:7.3.10-1.el7.remi will be an update
--> Processing Dependency: libargon2.so.0()(64bit) for package: php-7.3.10-1.el7.remi.x86_64
---> Package php-cli.x86_64 0:5.4.16-46.el7 will be updated
---> Package php-cli.x86_64 0:7.3.10-1.el7.remi will be an update
---> Package php-common.x86_64 0:5.4.16-46.el7 will be updated
--> Processing Dependency: php-json(x86-64) = 7.3.10-1.el7.remi for package: php-common-7.3.10-1.el7.remi.x86_64
---> Package php-common.x86_64 0:7.3.10-1.el7.remi will be an update
---> Package php-gd.x86_64 0:7.3.10-1.el7.remi will be installed
--> Processing Dependency: gd-last(x86-64) >= 2.1.1 for package: php-gd-7.3.10-1.el7.remi.x86_64
--> Processing Dependency: libX11.so.6()(64bit) for package: php-gd-7.3.10-1.el7.remi.x86_64
--> Processing Dependency: libXpm.so.4()(64bit) for package: php-gd-7.3.10-1.el7.remi.x86_64
--> Processing Dependency: libgd.so.3()(64bit) for package: php-gd-7.3.10-1.el7.remi.x86_64
--> Processing Dependency: libjpeg.so.62()(64bit) for package: php-gd-7.3.10-1.el7.remi.x86_64
---> Package php-ldap.x86_64 0:7.3.10-1.el7.remi will be installed
---> Package php-mysqlnd.x86_64 0:7.3.10-1.el7.remi will be installed
--> Processing Dependency: php-pdo(x86-64) = 7.3.10-1.el7.remi for package: php-mysqlnd-7.3.10-1.el7.remi.x86_64
---> Package php-pecl-mcrypt.x86_64 0:1.0.3-1.el7.remi.7.3 will be installed
--> Processing Dependency: libmcrypt.so.4()(64bit) for package: php-pecl-mcrypt-1.0.3-1.el7.remi.7.3.x86_64
---> Package php-pecl-zip.x86_64 0:1.15.5-1.el7.remi.7.3 will be installed
--> Processing Dependency: libzip5(x86-64) >= 1.5.2 for package: php-pecl-zip-1.15.5-1.el7.remi.7.3.x86_64
--> Processing Dependency: libzip.so.5()(64bit) for package: php-pecl-zip-1.15.5-1.el7.remi.7.3.x86_64
--> Running transaction check
---> Package gd-last.x86_64 0:2.2.5-8.el7.remi will be installed
--> Processing Dependency: libtiff.so.5(LIBTIFF_4.0)(64bit) for package: gd-last-2.2.5-8.el7.remi.x86_64
--> Processing Dependency: libfontconfig.so.1()(64bit) for package: gd-last-2.2.5-8.el7.remi.x86_64
--> Processing Dependency: libtiff.so.5()(64bit) for package: gd-last-2.2.5-8.el7.remi.x86_64
--> Processing Dependency: libwebp.so.7()(64bit) for package: gd-last-2.2.5-8.el7.remi.x86_64
---> Package libX11.x86_64 0:1.6.7-2.el7 will be installed
--> Processing Dependency: libX11-common >= 1.6.7-2.el7 for package: libX11-1.6.7-2.el7.x86_64
--> Processing Dependency: libxcb.so.1()(64bit) for package: libX11-1.6.7-2.el7.x86_64
---> Package libXpm.x86_64 0:3.5.12-1.el7 will be installed
---> Package libargon2.x86_64 0:20161029-3.el7 will be installed
---> Package libjpeg-turbo.x86_64 0:1.2.90-8.el7 will be installed
---> Package libmcrypt.x86_64 0:2.5.8-13.el7 will be installed
---> Package libzip5.x86_64 0:1.5.2-1.el7.remi will be installed
---> Package php-json.x86_64 0:7.3.10-1.el7.remi will be installed
---> Package php-pdo.x86_64 0:7.3.10-1.el7.remi will be installed
--> Running transaction check
---> Package fontconfig.x86_64 0:2.13.0-4.3.el7 will be installed
--> Processing Dependency: fontpackages-filesystem for package: fontconfig-2.13.0-4.3.el7.x86_64
--> Processing Dependency: dejavu-sans-fonts for package: fontconfig-2.13.0-4.3.el7.x86_64
---> Package libX11-common.noarch 0:1.6.7-2.el7 will be installed
---> Package libtiff.x86_64 0:4.0.3-32.el7 will be installed
--> Processing Dependency: libjbig.so.2.0()(64bit) for package: libtiff-4.0.3-32.el7.x86_64
---> Package libwebp7.x86_64 0:1.0.2-1.el7.remi will be installed
---> Package libxcb.x86_64 0:1.13-1.el7 will be installed
--> Processing Dependency: libXau.so.6()(64bit) for package: libxcb-1.13-1.el7.x86_64
--> Running transaction check
---> Package dejavu-sans-fonts.noarch 0:2.33-6.el7 will be installed
--> Processing Dependency: dejavu-fonts-common = 2.33-6.el7 for package: dejavu-sans-fonts-2.33-6.el7.noarch
---> Package fontpackages-filesystem.noarch 0:1.44-8.el7 will be installed
---> Package jbigkit-libs.x86_64 0:2.0-11.el7 will be installed
---> Package libXau.x86_64 0:1.0.8-2.1.el7 will be installed
--> Running transaction check
---> Package dejavu-fonts-common.noarch 0:2.33-6.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================
 Package                             Arch               Version                            Repository              Size
========================================================================================================================
Installing:
 php-gd                              x86_64             7.3.10-1.el7.remi                  remi-php73              80 k
 php-ldap                            x86_64             7.3.10-1.el7.remi                  remi-php73              83 k
 php-mysqlnd                         x86_64             7.3.10-1.el7.remi                  remi-php73             234 k
 php-pecl-mcrypt                     x86_64             1.0.3-1.el7.remi.7.3               remi-php73              30 k
 php-pecl-zip                        x86_64             1.15.5-1.el7.remi.7.3              remi-php73              51 k
Updating:
 php                                 x86_64             7.3.10-1.el7.remi                  remi-php73             3.2 M
 php-cli                             x86_64             7.3.10-1.el7.remi                  remi-php73             4.9 M
 php-common                          x86_64             7.3.10-1.el7.remi                  remi-php73             1.1 M
Installing for dependencies:
 dejavu-fonts-common                 noarch             2.33-6.el7                         base                    64 k
 dejavu-sans-fonts                   noarch             2.33-6.el7                         base                   1.4 M
 fontconfig                          x86_64             2.13.0-4.3.el7                     base                   254 k
 fontpackages-filesystem             noarch             1.44-8.el7                         base                   9.9 k
 gd-last                             x86_64             2.2.5-8.el7.remi                   remi-safe              134 k
 jbigkit-libs                        x86_64             2.0-11.el7                         base                    46 k
 libX11                              x86_64             1.6.7-2.el7                        base                   607 k
 libX11-common                       noarch             1.6.7-2.el7                        base                   164 k
 libXau                              x86_64             1.0.8-2.1.el7                      base                    29 k
 libXpm                              x86_64             3.5.12-1.el7                       base                    55 k
 libargon2                           x86_64             20161029-3.el7                     epel                    23 k
 libjpeg-turbo                       x86_64             1.2.90-8.el7                       base                   135 k
 libmcrypt                           x86_64             2.5.8-13.el7                       epel                    99 k
 libtiff                             x86_64             4.0.3-32.el7                       base                   171 k
 libwebp7                            x86_64             1.0.2-1.el7.remi                   remi-safe              265 k
 libxcb                              x86_64             1.13-1.el7                         base                   214 k
 libzip5                             x86_64             1.5.2-1.el7.remi                   remi-safe               56 k
 php-json                            x86_64             7.3.10-1.el7.remi                  remi-php73              66 k
 php-pdo                             x86_64             7.3.10-1.el7.remi                  remi-php73             127 k

Transaction Summary
========================================================================================================================
Install  5 Packages (+19 Dependent packages)
Upgrade  3 Packages

Total download size: 14 M
Is this ok [y/d/N]: y
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/27): fontpackages-filesystem-1.44-8.el7.noarch.rpm                                            | 9.9 kB  00:00:00
(2/27): dejavu-fonts-common-2.33-6.el7.noarch.rpm                                                |  64 kB  00:00:00
(3/27): jbigkit-libs-2.0-11.el7.x86_64.rpm                                                       |  46 kB  00:00:00
(4/27): fontconfig-2.13.0-4.3.el7.x86_64.rpm                                                     | 254 kB  00:00:00
(5/27): libXau-1.0.8-2.1.el7.x86_64.rpm                                                          |  29 kB  00:00:00
(6/27): dejavu-sans-fonts-2.33-6.el7.noarch.rpm                                                  | 1.4 MB  00:00:01
(7/27): libXpm-3.5.12-1.el7.x86_64.rpm                                                           |  55 kB  00:00:00
(8/27): libjpeg-turbo-1.2.90-8.el7.x86_64.rpm                                                    | 135 kB  00:00:00
(9/27): libX11-common-1.6.7-2.el7.noarch.rpm                                                     | 164 kB  00:00:00
warning: /var/cache/yum/x86_64/7/epel/packages/libargon2-20161029-3.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY
Public key for libargon2-20161029-3.el7.x86_64.rpm is not installed
(10/27): libargon2-20161029-3.el7.x86_64.rpm                                                     |  23 kB  00:00:00
warning: /var/cache/yum/x86_64/7/remi-safe/packages/gd-last-2.2.5-8.el7.remi.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 00f97f56: NOKEY
Public key for gd-last-2.2.5-8.el7.remi.x86_64.rpm is not installed
(11/27): gd-last-2.2.5-8.el7.remi.x86_64.rpm                                                     | 134 kB  00:00:01
(12/27): libtiff-4.0.3-32.el7.x86_64.rpm                                                         | 171 kB  00:00:00
(13/27): libxcb-1.13-1.el7.x86_64.rpm                                                            | 214 kB  00:00:00
(14/27): libmcrypt-2.5.8-13.el7.x86_64.rpm                                                       |  99 kB  00:00:00
(15/27): libzip5-1.5.2-1.el7.remi.x86_64.rpm                                                     |  56 kB  00:00:00
(16/27): libX11-1.6.7-2.el7.x86_64.rpm                                                           | 607 kB  00:00:02
(17/27): libwebp7-1.0.2-1.el7.remi.x86_64.rpm                                                    | 265 kB  00:00:01
Public key for php-gd-7.3.10-1.el7.remi.x86_64.rpm is not installed                   ] 1.2 MB/s | 4.9 MB  00:00:07 ETA
(18/27): php-gd-7.3.10-1.el7.remi.x86_64.rpm                                                     |  80 kB  00:00:01
(19/27): php-ldap-7.3.10-1.el7.remi.x86_64.rpm                                                   |  83 kB  00:00:01
(20/27): php-cli-7.3.10-1.el7.remi.x86_64.rpm                                                    | 4.9 MB  00:00:03
(21/27): php-pdo-7.3.10-1.el7.remi.x86_64.rpm                                                    | 127 kB  00:00:00
(22/27): php-pecl-mcrypt-1.0.3-1.el7.remi.7.3.x86_64.rpm                                         |  30 kB  00:00:00
(23/27): php-json-7.3.10-1.el7.remi.x86_64.rpm                                                   |  66 kB  00:00:02
(24/27): php-mysqlnd-7.3.10-1.el7.remi.x86_64.rpm                                                | 234 kB  00:00:01
(25/27): php-common-7.3.10-1.el7.remi.x86_64.rpm                                                 | 1.1 MB  00:00:04
(26/27): php-pecl-zip-1.15.5-1.el7.remi.7.3.x86_64.rpm                                           |  51 kB  00:00:00
(27/27): php-7.3.10-1.el7.remi.x86_64.rpm                                                        | 3.2 MB  00:00:10
------------------------------------------------------------------------------------------------------------------------
Total                                                                                   1.1 MB/s |  14 MB  00:00:12
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
Importing GPG key 0x00F97F56:
 Userid     : "Remi Collet "
 Fingerprint: 1ee0 4cce 88a4 ae4a a29a 5df5 004e 6f47 00f9 7f56
 Package    : remi-release-7.7-1.el7.remi.noarch (@/remi-release-7)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-remi
Is this ok [y/N]: y
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
Importing GPG key 0x352C64E5:
 Userid     : "Fedora EPEL (7) "
 Fingerprint: 91e9 7d7c 4a5e 96f1 7f3e 888f 6a2f aea2 352c 64e5
 Package    : epel-release-7-12.noarch (@/epel-release-latest-7.noarch)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : libjpeg-turbo-1.2.90-8.el7.x86_64                                                                   1/30
  Installing : fontpackages-filesystem-1.44-8.el7.noarch                                                           2/30
  Installing : libargon2-20161029-3.el7.x86_64                                                                     3/30
  Installing : dejavu-fonts-common-2.33-6.el7.noarch                                                               4/30
  Installing : dejavu-sans-fonts-2.33-6.el7.noarch                                                                 5/30
  Installing : fontconfig-2.13.0-4.3.el7.x86_64                                                                    6/30
  Updating   : php-common-7.3.10-1.el7.remi.x86_64                                                                 7/30
  Installing : php-json-7.3.10-1.el7.remi.x86_64                                                                   8/30
  Installing : php-pdo-7.3.10-1.el7.remi.x86_64                                                                    9/30
  Updating   : php-cli-7.3.10-1.el7.remi.x86_64                                                                   10/30
  Installing : libXau-1.0.8-2.1.el7.x86_64                                                                        11/30
  Installing : libxcb-1.13-1.el7.x86_64                                                                           12/30
  Installing : libwebp7-1.0.2-1.el7.remi.x86_64                                                                   13/30
  Installing : libX11-common-1.6.7-2.el7.noarch                                                                   14/30
  Installing : libX11-1.6.7-2.el7.x86_64                                                                          15/30
  Installing : libXpm-3.5.12-1.el7.x86_64                                                                         16/30
  Installing : libzip5-1.5.2-1.el7.remi.x86_64                                                                    17/30
  Installing : jbigkit-libs-2.0-11.el7.x86_64                                                                     18/30
  Installing : libtiff-4.0.3-32.el7.x86_64                                                                        19/30
  Installing : gd-last-2.2.5-8.el7.remi.x86_64                                                                    20/30
  Installing : libmcrypt-2.5.8-13.el7.x86_64                                                                      21/30
  Installing : php-pecl-mcrypt-1.0.3-1.el7.remi.7.3.x86_64                                                        22/30
  Installing : php-gd-7.3.10-1.el7.remi.x86_64                                                                    23/30
  Installing : php-pecl-zip-1.15.5-1.el7.remi.7.3.x86_64                                                          24/30
  Updating   : php-7.3.10-1.el7.remi.x86_64                                                                       25/30
  Installing : php-mysqlnd-7.3.10-1.el7.remi.x86_64                                                               26/30
  Installing : php-ldap-7.3.10-1.el7.remi.x86_64                                                                  27/30
  Cleanup    : php-5.4.16-46.el7.x86_64                                                                           28/30
  Cleanup    : php-cli-5.4.16-46.el7.x86_64                                                                       29/30
  Cleanup    : php-common-5.4.16-46.el7.x86_64                                                                    30/30
  Verifying  : fontconfig-2.13.0-4.3.el7.x86_64                                                                    1/30
  Verifying  : php-pecl-mcrypt-1.0.3-1.el7.remi.7.3.x86_64                                                         2/30
  Verifying  : php-ldap-7.3.10-1.el7.remi.x86_64                                                                   3/30
  Verifying  : php-pdo-7.3.10-1.el7.remi.x86_64                                                                    4/30
  Verifying  : php-7.3.10-1.el7.remi.x86_64                                                                        5/30
  Verifying  : libargon2-20161029-3.el7.x86_64                                                                     6/30
  Verifying  : php-cli-7.3.10-1.el7.remi.x86_64                                                                    7/30
  Verifying  : libmcrypt-2.5.8-13.el7.x86_64                                                                       8/30
  Verifying  : fontpackages-filesystem-1.44-8.el7.noarch                                                           9/30
  Verifying  : jbigkit-libs-2.0-11.el7.x86_64                                                                     10/30
  Verifying  : dejavu-fonts-common-2.33-6.el7.noarch                                                              11/30
  Verifying  : php-json-7.3.10-1.el7.remi.x86_64                                                                  12/30
  Verifying  : php-common-7.3.10-1.el7.remi.x86_64                                                                13/30
  Verifying  : libzip5-1.5.2-1.el7.remi.x86_64                                                                    14/30
  Verifying  : libX11-common-1.6.7-2.el7.noarch                                                                   15/30
  Verifying  : libxcb-1.13-1.el7.x86_64                                                                           16/30
  Verifying  : libX11-1.6.7-2.el7.x86_64                                                                          17/30
  Verifying  : libXpm-3.5.12-1.el7.x86_64                                                                         18/30
  Verifying  : libjpeg-turbo-1.2.90-8.el7.x86_64                                                                  19/30
  Verifying  : dejavu-sans-fonts-2.33-6.el7.noarch                                                                20/30
  Verifying  : gd-last-2.2.5-8.el7.remi.x86_64                                                                    21/30
  Verifying  : libwebp7-1.0.2-1.el7.remi.x86_64                                                                   22/30
  Verifying  : php-gd-7.3.10-1.el7.remi.x86_64                                                                    23/30
  Verifying  : php-mysqlnd-7.3.10-1.el7.remi.x86_64                                                               24/30
  Verifying  : libXau-1.0.8-2.1.el7.x86_64                                                                        25/30
  Verifying  : libtiff-4.0.3-32.el7.x86_64                                                                        26/30
  Verifying  : php-pecl-zip-1.15.5-1.el7.remi.7.3.x86_64                                                          27/30
  Verifying  : php-cli-5.4.16-46.el7.x86_64                                                                       28/30
  Verifying  : php-5.4.16-46.el7.x86_64                                                                           29/30
  Verifying  : php-common-5.4.16-46.el7.x86_64                                                                    30/30

Installed:
  php-gd.x86_64 0:7.3.10-1.el7.remi                         php-ldap.x86_64 0:7.3.10-1.el7.remi
  php-mysqlnd.x86_64 0:7.3.10-1.el7.remi                    php-pecl-mcrypt.x86_64 0:1.0.3-1.el7.remi.7.3
  php-pecl-zip.x86_64 0:1.15.5-1.el7.remi.7.3

Dependency Installed:
  dejavu-fonts-common.noarch 0:2.33-6.el7     dejavu-sans-fonts.noarch 0:2.33-6.el7 fontconfig.x86_64 0:2.13.0-4.3.el7
  fontpackages-filesystem.noarch 0:1.44-8.el7 gd-last.x86_64 0:2.2.5-8.el7.remi     jbigkit-libs.x86_64 0:2.0-11.el7
  libX11.x86_64 0:1.6.7-2.el7                 libX11-common.noarch 0:1.6.7-2.el7    libXau.x86_64 0:1.0.8-2.1.el7
  libXpm.x86_64 0:3.5.12-1.el7                libargon2.x86_64 0:20161029-3.el7     libjpeg-turbo.x86_64 0:1.2.90-8.el7
  libmcrypt.x86_64 0:2.5.8-13.el7             libtiff.x86_64 0:4.0.3-32.el7         libwebp7.x86_64 0:1.0.2-1.el7.remi
  libxcb.x86_64 0:1.13-1.el7                  libzip5.x86_64 0:1.5.2-1.el7.remi     php-json.x86_64 0:7.3.10-1.el7.remi
  php-pdo.x86_64 0:7.3.10-1.el7.remi

Updated:
  php.x86_64 0:7.3.10-1.el7.remi      php-cli.x86_64 0:7.3.10-1.el7.remi      php-common.x86_64 0:7.3.10-1.el7.remi

Complete!


# Check installed PHP version.
[root@08-00-27-2C-51-D6 ~]# php -v
PHP 7.3.10 (cli) (built: Sep 24 2019 09:20:18) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.10, Copyright (c) 1998-2018 Zend Technologies


Now all done and ready to use PHPUnit!

Tuesday, October 1, 2019

docker: Setup Wordpress site with linode/lamp container

This time I tried to setup Wordpress website with deploying linode/lamp container. Here's how I did it.
# Start docker service, and retrieve linode/lamp image.
service docker start

docker pull linode/lamp
# Create docker volume for Wordpress contents.
docker volume create my-vol
# Primarily download Wordpress contents.
curl https://wordpress.org/wordpress-5.0.6.zip -o wordpress-5.0.6.zip
unzip wordpress-5.0.6.zip
mv wordpress/* /var/lib/docker/volumes/my-vol/_data
# Run pulled linode/lamp image with mounting created docker volume.
docker run --name linode-dev -it -v my-vol:/var/www/html -p 80:80  linode/lamp /bin/bash
# Update softwares on linode/lamp.
apt-get update
apt-get install  php5-mysqlnd-ms
# Reconfigure MySQL root password
dpkg-reconfigure mysql-server-5.5
# Setup Wordpress database
mysql -uroot -p
CREATE DATABASE awswp;
GRANT ALL PRIVILEGES ON awswp.* TO "wpdbuser"@"localhost" IDENTIFIED BY "xxxxxx";
# Edit apache2 config file to point Wordpress contents.
vi /etc/apache2/sites-available/example.com.conf
 # domain: example.com
 # public: /var/www/example.com/public_html/

 
  # Admin email, Server Name (domain name), and any aliases
  ServerAdmin webmaster@example.com
  ServerName  www.example.com
  ServerAlias example.com

  # Index file and Document Root (where the public files are located)
  DirectoryIndex index.html index.php
  #DocumentRoot /var/www/example.com/public_html
  DocumentRoot /var/www/html
  # Log file locations
  LogLevel warn
  ErrorLog  /var/www/wp/log/error.log
  CustomLog /var/www/wp/log/access.log combined
  #ErrorLog  /var/www/example.com/log/error.log
  #CustomLog /var/www/example.com/log/access.log combined
 
# Start MySQL and Apache daemon
service mysql start
service apache2 start

Now you will see Wordpress page and ready for configuration!

Monday, September 23, 2019

Powershell: Generating random password

Here's method for generating random password by using Powershell.

# Add the System.Web assembly
PS C:\Users\drago> Add-Type -AssemblyName System.Web # Let's get random password by following method
# First parameter is length for the password, and second is the number of non-alphabetical characters.
PS C:\Users\drago> [System.Web.Security.Membership]::GeneratePassword(10,4)
.Ra45;)WQ}

Monday, September 16, 2019

docker: [RESOLVED] Expose dockerised mongodb listenport, and connection failed :(

I created dockerised mongodb, but encountered login failure via mongo shell.
An investigation found that my depreciated mongo shell version caused issue.
After that, I updated the software version, and remote connection got successful!

#prepare persistent data location with docker volume
docker volume create my-vol
docker volume inspect my-vol
[
    {
        "CreatedAt": "2019-09-15T01:24:25+09:00",
        "Driver": "local",
        "Labels": {},
        "Mountpoint": "/var/lib/docker/volumes/my-vol/_data",
        "Name": "my-vol",
        "Options": {},
        "Scope": "local"
    }
]
# Copy dumped database file for restoration
cp -R ./testCol /var/lib/docker/volumes/my-vol/_data


# Run mongo container mounting created volume, and specify mongodb data directory as /data/db
docker run --name mongo-dev -d -v my-vol:/data/db  -e DATA_DIR=/data/db -p 27017 mongo
d2b759805a018d1a71b835c7d6dffdda68cbbfa20f7f891fb381a53fd7b49ed0


# Restore database from dumpfile
docker exec -it mongo-dev mongorestore --db articles /data/db/articles


# Check local port
docker ps 
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                      NAMES
d2b759805a01        mongo               "docker-entrypoint.s…"   23 seconds ago      Up 21 seconds       0.0.0.0:32768->27017/tcp   mongo-dev


# Try to connect mongo console, but it fails
mongo --host 127.0.0.1:32768
MongoDB shell version v3.4.21
connecting to: mongodb://127.0.0.1:32768/
2019-09-15T23:47:20.861+0900 E QUERY    [thread1] Error: network error while attempting to run command 'whatsmyuri' on host '127.0.0.1:32768'  :
connect@src/mongo/shell/mongo.js:240:13
@(connect):1:6
exception: connect failed


# Check listen status, dockerised mongo is bound to ipv6 port 32768
netstat -ltn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
tcp6       0      0 ::1:25                  :::*                    LISTEN
tcp6       0      0 :::32768                :::*                    LISTEN
tcp6       0      0 :::22                   :::*                    LISTEN


# Check container with interactive console
docker run -it --link=mongo-dev:mongo mongo bash


# I can see mongodb collections via console
mongo --host 172.17.0.2:27017
> show databases;
admin          0.000GB
articles       0.000GB
config         0.000GB
local          0.000GB
sepfourteenth  0.000GB
> use articles;
switched to db articles
> db.testCol.find({});
{ "_id" : ObjectId("5d6682061f2af8077f940255"), "name" : "大丈夫", "query" : "%E5%A4%A7%E4%B8%88%E5%A4%AB", "tweet_volume" : 490680, "date" : "8/28/2019, 10:30:45 PM" }
{ "_id" : ObjectId("5d6682061f2af8077f940256"), "name" : "テレビ", "query" : "%E3%83%86%E3%83%AC%E3%83%93", "tweet_volume" : 337330, "date" : "8/28/2019, 10:30:45 PM" }


# Let me specify source IP and port
docker run --name mongo-dev -d -v my-vol:/data/db  -e DATA_DIR=/data/db -p 127.0.0.1:32768:27017  mongo --bind_ip_all
a3f9ab22beaed1b13e73f3ab0d4ccd452a8f1b4c33688c7d0906acd0d2f264ed


# Now I can see the listen port bind to ipv4
netstat -ltn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:32768         0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
tcp6       0      0 ::1:25                  :::*                    LISTEN
tcp6       0      0 :::22                   :::*                    LISTEN

docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                        NAMES
a3f9ab22beae        mongo               "docker-entrypoint.s…"   42 seconds ago      Up 41 seconds       127.0.0.1:32768->27017/tcp   mongo-dev


# Unfortunately another issue was found when I tried to connect dockerised mongo.
mongo --host 127.0.0.1:32768
MongoDB shell version v3.4.21
connecting to: mongodb://127.0.0.1:32768/
2019-09-16T20:15:42.149+0900 E QUERY    [thread1] Error: network error while attempting to run command 'whatsmyuri' on host '127.0.0.1:32768'  :
connect@src/mongo/shell/mongo.js:240:13
@(connect):1:6
exception: connect failed


# bind_ip_all was specified.
docker container inspect mongo-dev | grep -n -A10 bind
7:            "--bind_ip_all"
8-        ],
9-        "State": {
10-            "Status": "running",
11-            "Running": true,
12-            "Paused": false,
13-            "Restarting": false,
14-            "OOMKilled": false,
15-            "Dead": false,
16-            "Pid": 1635,
17-            "ExitCode": 0,
--
193:                "--bind_ip_all"
194-            ],


# Unfamiliar error was written on log file.
I realized the problem sits on host side.

{"log":"2019-09-16T15:19:20.315+0000 E  -        [conn2] Assertion: Location34348: cannot translate opcode 2010 src/mongo/rpc/message.h 120\n","stream":"stdout","time":"2019-09-16T15:19:20.315419954Z"}



# Checked mongo shell version on host.
mongo --version


# Update yum repository file for fetching newer version of mongo shell.
yum remove mongodb-org-shell
vi /etc/yum.repos.d/mongodb-org.repo

name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc


# Reintall mongo shell.
yum remove mongodb-org-shell
yum install mongodb-org-shell


# Now everything alright! :)
The trouble shooting was really tough though...(ToT)

mongo 127.0.0.1:32768                                 MongoDB shell version v4.0.12
connecting to: mongodb://127.0.0.1:32768/test?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("6e2290f5-c297-4c81-8c25-c1197311c8d9") }
MongoDB server version: 4.2.0

> show databases;
admin          0.000GB
articles       0.000GB
config         0.000GB
local          0.000GB
sepfourteenth  0.000GB
> exit
bye

Sunday, September 8, 2019

docker: Pull mongo image and restore backuped database to container

Let's see how I tried to restore local mongo database to mongo docker container.
'docker cp' command didn't work for host -> container file copy.
I created docker volume and used it to achieve this.

Retrieve mongo image from docker repository
[root@localhost ~]# docker pull mongo

Backup existing database with 'mongodump'
[root@localhost ~]# mongodump --collection testCol --db articles --out ./testCol

Let's create docker volume for passing backup files to docker container
[root@localhost ~]# docker volume create my-vol

Check the full path of created volume
[root@localhost ~]# docker volume inspect my-vol
[
    {
        "CreatedAt": "2019-09-05T00:20:34+09:00",
        "Driver": "local",
        "Labels": {},
        "Mountpoint": "/var/lib/docker/volumes/my-vol/_data",
        "Name": "my-vol",
        "Options": {},
        "Scope": "local"
    }
]

Copy back up files to the volume, so that we can access them from container later
[root@localhost ~]# cp -R ./testCol/* /var/lib/docker/volumes/my-vol/_data/

Run container with mounting created volume
[root@localhost ~]# docker run -itd --mount source=my-vol,target=/app mongo

Identify the container name
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d70f1c3f0101 mongo "docker-entrypoint.s…" 5 seconds ago Up 3 seconds 27017/tcp admiring_bell

Verify if the volume is being mounted properly
[root@localhost ~]# docker inspect admiring_bell | grep -A10 -i mount
            "Mounts": [
                {
                    "Type": "volume",
                    "Source": "my-vol",
                    "Target": "/app"
                }
            ],
            "MaskedPaths": [
                "/proc/asound",
                "/proc/acpi",
                "/proc/kcore",
--
        "Mounts": [
            {
                "Type": "volume",
                "Name": "my-vol",
                "Source": "/var/lib/docker/volumes/my-vol/_data",
                "Destination": "/app",
                "Driver": "local",
                "Mode": "z",
                "RW": true,
                "Propagation": ""
            },


Now we can see copied directory from the container
[root@localhost ~]# docker exec -it admiring_bell ls -l /app
total 0
drwxr-xr-x. 2 root root 55 Sep 4 15:20 articles

Restore back up files to database inside the container
[root@localhost ~]# docker exec -it admiring_bell mongorestore --db articles /app/articles
2019-09-08T05:51:16.952+0000 the --db and --collection args should only be used when restoring from a BSON file. Other uses are deprecated and will not exist in the future; use --nsInclude instead
2019-09-08T05:51:16.953+0000 building a list of collections to restore from /app/articles dir
2019-09-08T05:51:16.956+0000 reading metadata for articles.testCol from /app/articles/testCol.metadata.json
2019-09-08T05:51:17.005+0000 restoring articles.testCol from /app/articles/testCol.bson
2019-09-08T05:51:17.022+0000 no indexes to restore
2019-09-08T05:51:17.023+0000 finished restoring articles.testCol (38 documents, 0 failures)
2019-09-08T05:51:17.023+0000 38 document(s) restored successfully. 0 document(s) failed to restore.


Let's check the restored database with interactive console of the container
[root@localhost ~]# docker run -it --link=admiring_bell:mongo mongo /bin/sh

# env
HOSTNAME=d74d7531ee8c
~~~~~~~
MONGO_PORT_27017_TCP=tcp://172.17.0.2:27017
~~~~~~~

# mongo --host 172.17.0.2:27017
MongoDB shell version v4.2.0
connecting to: mongodb://172.17.0.2:27017/?compressors=disabled&gssapiServiceName=mongodb

> show databases
admin 0.000GB
articles 0.000GB
config 0.000GB
local 0.000GB

> use articles

switched to db articles

> show collections
testCol

> db.testCol.find({})
{ "_id" : ObjectId("5d6682061f2af8077f940255"), "name" : "大丈夫", "query" : "%E5%A4%A7%E4%B8%88%E5%A4%AB", "tweet_volume" : 490680, "date" : "8/28/2019, 10:30:45 PM" }
{ "_id" : ObjectId("5d6683097633bc07a7b6f03d"), "name" : "大丈夫", "query" : "%E5%A4%A7%E4%B8%88%E5%A4%AB", "tweet_volume" : 493621, "date" : "8/28/2019, 10:35:04 PM" }
Type "it" for more

> exit


Everything works fine, now we can stop the container
[root@localhost ~]# docker container stop admiring_bell
admiring_bell

Clean it up
[root@localhost ~]# docker system prune

Saturday, August 31, 2019

docker: Build own docker image file

Let's create/build docker image based on 'node' template image.
Following sample uses node script file that I created on here.

create package.json file for 'tweet.js'.
[root@localhost express]# vi package.json
{
"name": "twitter_api_docker",
"version": "1.0.0",
"description": "",
"main": "tweet.js",
"scripts": {
"start": "node tweet.js",
"test": "echo \"error: no test specified\" && exit 1"
},
"author": "Yosuke",
"license": "ISC",
"dependencies": {
"express": "^4.16.3",
"twitter": "^1.7.1"
}
}


Check created package.json file with npm command.
[root@localhost express]# npm start
> twitter_api_docker@1.0.0 start /root/express
> node tweet.js

[ { name: 'ラピュタ',
query: '%E3%83%A9%E3%83%94%E3%83%A5%E3%82%BF',
tweet_volume: 1015481,
date: '8/31/2019, 9:04:00 PM' },
{ name: '#VakaTuberは誰だ',
query: '%23VakaTuber%E3%81%AF%E8%AA%B0%E3%81%A0',
tweet_volume: 13462,
date: '8/31/2019, 9:04:00 PM' },
{ name: '国語の教科書',
query: '%E5%9B%BD%E8%AA%9E%E3%81%AE%E6%95%99%E7%A7%91%E6%9B%B8',
tweet_volume: 39878,
date: '8/31/2019, 9:04:00 PM' }
]


Here we create 'Docker' file for image build.
It is based on 'node' template image.

[root@localhost express]# vi Dockerfile
FROM node
WORKDIR /opt/tweetjs
COPY . .
RUN npm install
CMD ["npm", "start"]


Let's run 'docker build' command.
The command read 'Docker' file.

[root@localhost express]# docker build -t node-docker-tut .
Removing intermediate container cc70f978f4e7
Successfully built 1ff3ca634e76


Check built image. You can see necessary files were copied to the image.
[root@localhost express]# docker run -it node-docker-tut bash
root@785a50241c04:/opt/tweetjs# ls
Dockerfile insert.js_bk node_modules package.json server.js2 tweet.js
insert.js lib package-lock.json server.js server.js_
root@785a50241c04:/opt/tweetjs# exit
exit


Solely run the image, and it will be executed 'npm start' as we specified in Docker file.
[root@localhost express]# docker run -it node-docker-tut
> twitter_api_docker@1.0.0 start /root/express
> node tweet.js

[ { name: 'ラピュタ',
query: '%E3%83%A9%E3%83%94%E3%83%A5%E3%82%BF',
tweet_volume: 1015481,
date: '8/31/2019, 9:04:00 PM' },
{ name: '#VakaTuberは誰だ',
query: '%23VakaTuber%E3%81%AF%E8%AA%B0%E3%81%A0',
tweet_volume: 13462,
date: '8/31/2019, 9:04:00 PM' },
{ name: '国語の教科書',
query: '%E5%9B%BD%E8%AA%9E%E3%81%AE%E6%95%99%E7%A7%91%E6%9B%B8',
tweet_volume: 39878,
date: '8/31/2019, 9:04:00 PM' }
]

Thursday, August 29, 2019

docker: Installing docker on CentOS7

Here is how I installed docker on CentOS7 via yum repository, and run retrieved node.js image.

Install docker via yum repository
# yum -y update
# yum -y install docker

Check docker version
# docker -v
# Docker version 1.13.1, build 7f2769b/1.13.1

Start docker service
# service docker start
Redirecting to /bin/systemctl start docker.service


Retrieve node.js image from official docker repository
# docker pull node
Using default tag: latest
Trying to pull repository docker.io/library/node ...
latest: Pulling from docker.io/library/node
9cc2ad81d40d: Pull complete
e6cb98e32a52: Pull complete
ae1b8d879bad: Pull complete
42cfa3699b05: Pull complete
053cac798c4e: Pull complete
e11ff976ff71: Pull complete
6e754155fada: Pull complete
32d7c2fdf415: Pull complete
7acfea3f0d48: Pull complete
Digest: sha256:b524cc1b5a7f5626fc8196886b81e29b1879051471a5a4a9e8101f3132c22a09
Status: Downloaded newer image for docker.io/node:latest


Check if the image was retrieved
# docker images
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
docker.io/node          latest              b18afbdfc458        6 days ago          908 MB
docker.io/hello-world   latest              fce289e99eb9        7 months ago        1.84 kB


Run the image interactively
# docker run -it node
Welcome to Node.js v12.9.0.
Type ".help" for more information.
> console.log("hello docker");
hello docker
undefined
>


Sunday, August 25, 2019

node.js: Installing and using Twitter module

Installing Twitter module
> npm install --save twitter

Check what you installed
> ls -l node_modules/twitter/
total 20
-rw-r--r--. 1 root root   16 Jun 13  2017 CNAME
drwxr-xr-x. 2 root root   41 Jul 21 17:59 lib
-rw-r--r--. 1 root root 1071 Dec  2  2016 LICENSE.md
drwxr-xr-x. 4 root root   40 Jul 21 17:59 node_modules
-rw-r--r--. 1 root root 1708 Jul 21 17:59 package.json
-rw-r--r--. 1 root root 6121 Jun 13  2017 README.md


Create config.js for twitter authentication
> vi lib/config.js
module.exports = {
  consumer_key: 'xxxxxx',
  consumer_secret: 'xxxxxx',
  access_token_key: 'xxx-xxxxx',
  access_token_secret: 'xxxxxxx'
}


Create tweet.js which retrieves trend words
> vi tweet.js

var Twitter = require('twitter');
var config = require('./lib/config.js');

var T = new Twitter(config);

var params = {
  id: 1117099
}

dt = new Date();
dt_format = dt.toLocaleString();

T.get('trends/place', params, function(err, data, response) {
    var tweets = data[0].trends;
    var j = 0;

    for ( i=0; i < tweets.length; i++ ) {
        if ( tweets[i].tweet_volume ) {
            trendData[j] = {"name": tweets[i].name,
                            "query" : tweets[i].query,
                            "tweet_volume" : tweets[i].tweet_volume,
                            "date" : dt_format
                            };
            j++;
        }
    }

    console.log(trendData);

});


Run the script file
> /opt/node/bin/node tweet.js
[ { name: 'テレビ',
    query: '%E3%83%86%E3%83%AC%E3%83%93',
    tweet_volume: 595528,
    date: '8/25/2019, 8:57:15 PM' },
  { name: 'ライブ',
    query: '%E3%83%A9%E3%82%A4%E3%83%96',
    tweet_volume: 529983,
    date: '8/25/2019, 8:57:15 PM' },
  { name: '誕生日',
    query: '%E8%AA%95%E7%94%9F%E6%97%A5',
    tweet_volume: 202457,
    date: '8/25/2019, 8:57:15 PM' },
  { name: '#sbhawks',
    query: '%23sbhawks',
    tweet_volume: 11577,
    date: '8/25/2019, 8:57:15 PM' },
  { name: '久しぶり',
    query: '%E4%B9%85%E3%81%97%E3%81%B6%E3%82%8A',
    tweet_volume: 199483,
    date: '8/25/2019, 8:57:15 PM' } ]

Sunday, July 21, 2019

mongoDB: CRUD operation

Here I tried to setup database, create collection and manipulate document on mongoDB.

Show databases in your environment
> show dbs


Create new database, or switch to existing database
> use articledb


Drop existing database
> use articledb
> db.dropDatabase()


Create collection and insert a document
> db.myNewCollection1.insert( {title:"Super cell appeared in western Japan", body: "People in western region were forced to evacuated blurblur", author:"YangJie", createdOn:"2019/07/20"} )
WriteResult({ "nInserted" : 1 })

> show collections
myNewCollection1


Delete collection
> db.myNewCollection1.drop()
WriteResult({ "nInserted" : 1 })

> show collections



Find inserted document(s) in collection
> db.myNewCollection1.find({})
{ "_id" : ObjectId("5d327a03d192820723ed0f66"), "title" : "Super cell appeared in western Japan", "body" : "People in western region were forced to evacuated blurblur", "author" : "YangJie", "createdOn" : "2019/07/20" }


Find inserted document(s) only with required fields
> fields={"title":1,"author":1,_id:0}
{ "title" : 1, "author" : 1, "_id" : 0 }
> db.myNewCollection1.find({},fields)
{ }
{ "title" : "Super cell appeared in western Japan", "author" : "YangJie" }
> criteria={author:"YangJie"} db.myNewCollection1.find(criteria)


update document(s)
> criteria={author:"YangJie"}
{ "author" : "YangJie" }

> db.myNewCollection1.find(criteria)
{ "_id" : ObjectId("5d33e7fd4d8060b895217fb7"), "title" : "Super cell appeared in western Japan", "body" : "People in western region were forced to evacuated blurblur", "author" : "YangJie", "createdOn" : "2019/07/20" }

> update={$set:{title:"Super cell struck in western Japan region"}}
{ "$set" : { "title" : "Super cell struck in western Japan region" } }

> db.myNewCollection1.update(criteria,update)
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })

> db.myNewCollection1.find(criteria)
{ "_id" : ObjectId("5d33e7fd4d8060b895217fb7"), "title" : "Super cell struck in western Japan region", "body" : "People in western region were forced to evacuated blurblur", "author" : "YangJie", "createdOn" : "2019/07/20" }


remove specific document(s)
> criteria
{ "author" : "YangJie" }

> db.myNewCollection1.find({})
{ "_id" : ObjectId("5d33e7fd4d8060b895217fb7"), "title" : "Super cell struck in western Japan region", "body" : "People in western region were forced to evacuated blurblur", "author" : "YangJie", "createdOn" : "2019/07/20" }
{ "_id" : ObjectId("5d33e9394d8060b895217fb8"), "title" : "More heavy rain is expected in western Japan", "body" : "People in western region is expected to have torrential rain blurblur,,", "author" : "Denish", "createdOn" : "2019/07/21" }

> db.myNewCollection1.remove(criteria)
WriteResult({ "nRemoved" : 1 })

> db.myNewCollection1.find({})
{ "_id" : ObjectId("5d33e9394d8060b895217fb8"), "title" : "More heavy rain is expected in western Japan", "body" : "People in western region is expected to have torrential rain blurblur,,", "author" : "Denish", "createdOn" : "2019/07/21" }

Wednesday, July 17, 2019

mongoDB: Installing mongoDB on CentOS7

When I tried to install mongoDB by 'yum' command on CentOS7, but it failed due to no entry found on default repository.
So, I created repository file and retry installation.

[root@localhost ~]# vi /etc/yum.repos.d/mongodb-org.repo
[mongodb-org-3.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc


[root@localhost ~]# yum install -y mongodb-org



Now the attempt was successful, and I was able to run mongo!

[root@localhost ~]# mongo
MongoDB shell version v3.4.21
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.21
Server has startup warnings:
2019-07-17T22:57:35.959+0900 I CONTROL [initandlisten]
2019-07-17T22:57:35.960+0900 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-07-17T22:57:35.960+0900 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2019-07-17T22:57:35.960+0900 I CONTROL [initandlisten]
2019-07-17T22:57:35.960+0900 I CONTROL [initandlisten]
2019-07-17T22:57:35.960+0900 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2019-07-17T22:57:35.960+0900 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2019-07-17T22:57:35.961+0900 I CONTROL [initandlisten]
2019-07-17T22:57:35.961+0900 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2019-07-17T22:57:35.961+0900 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2019-07-17T22:57:35.961+0900 I CONTROL [initandlisten]


Wednesday, June 12, 2019

Powershell: Invoke-RestMethod retrieve garbled data

When I tried to retrieve CSV data from Japan Meteorological Agency, the data totally get garbled.
So I swithed to use Invoke-WebRequest with [System.Text.Encoding]::Default.GetString method to resolve the issue.

# Retrieve CSV data with following Invoke-RestMethod get garbled data.
PS > $jma = Invoke-RestMethod -Uri "https://www.data.jma.go.jp/obd/stats/data/mdrr/tem_rct/alltable/mxtemsadext00_rct.csv" -Method get


PS > $jma | more
?I?a???O??,?s?1?{?§,?n?_,???U?n?_?O??,?≫?Y????(?N),?≫?Y????(??),?≫?Y????(?u),?≫?Y????(??),?≫?Y????(?a),?!?u?I?A???C?・(??),?!?u?I?A???C?・?I?i???i?n,?!?u?I?A???C?・?N???i???j,?!?u?I?A???C?・?N???i?a?j,?!?u?I?A???C?・?N???I?i???i?n,???N?・?i???j,?O?u?・?i???j,?Y???{?i???j,?Y???{?i?{?j,?E?l?X?V,10?N?¢???A?I?E?l?X?V,?!?N?A??,?!?N?I?A???C?・?i??)?i?d?u?U?A?j,?!?N?I?A???C?・?i?d?u?U?A?j?I?i???i?n,?!?N?I?A???C?・?i?d?u?U?A?j?d?I?a?μ???N?u?i?N?j,?!?N?11001,?k?C?1?@?J?n?u,?@?J?|?i?\?E???~?T?L?j,,2019,06,12,20,00,11.7,5,11,33,5,-2.8,-2.9,5,2,,,0,25.4,4,2019,05,20,31.9,8,



# Invoke-WebRequest with [system.Text.Encoding]::Default.GetString combination works fine!
PS > $jma = [system.Text.Encoding]::Default.GetString((Invoke-WebRequest "https://www.data.jma.go.jp/obd/stats/data/mdrr/tem_rct/alltable/mxtemsadext00_rct.csv").RawContentStream.ToArray())

PS > $jma | more
観測所番号,都道府県,地点,国際地点番号,現在時刻(年),現在時刻(月),現在時刻(日),現在時刻(時),現在時刻(分),今日の最高気温(℃),今日の最高気温の品質情報,今日の最高気温起時(時),今日の最高気温起時(分),今日の最高気温起時の品質情報,平年差(℃), 前日差(℃),該当旬(月),該当旬(旬),極値更新,10年未満での極値更新,今年最高,今年の最高気温(℃)(昨日まで),今年の最高気温(昨日まで)の品質情報,今年の最高気温(昨日まで)を観測した起日(年),今年の最高気温(昨日まで)を観測した起日(月),今年の最高気温(昨日まで)を観測した起日(日),昨日までの観測史上1位の値(℃),昨日までの観測史上1位の値の品質情報,昨日までの観測史上1位の値を観測した起日(年),昨日までの観測史上1位の値を観測した起日(月),昨日までの観測史上1位の値を観測 した起日(日),昨日までの6月の1位の値,昨日までの6月の1位の値の品質情報,昨日までの6月の1位の値の起日(年),昨日までの6月 の1位の値の起日(月),昨日までの6月の1位の値の起日(日),統計開始年
11001,北海道宗谷地方,宗谷岬(ソウヤミサキ),,2019,06,12,21,00,11.7,5,11,33,5,-2.8,-2.9,5,2,,,0,25.4,4,2019,05,20,31.9,8,2000,08,01,26.4,8,2005,06,22,1978
11016,北海道宗谷地方,稚内(ワッカナイ),47401,2019,06,12,21,00,12.5,5,10,53,5,-2.9,-5.5,5,2,,,0,23.4,4,2019,05,31,31.3,8,1946,08,22,26.8,8,1977,06,30,1938


Sunday, June 9, 2019

Powershell: Get JST from Unix epoch time

Let's see how to convert UTC to JST by using System.Timespan object, with sample data retrieved from OpenWeatherMap.

Also refer FromSeconds method.


# Retrieve JSON formatted weather data
PS > $ow = Invoke-RestMethod -Uri "api.openweathermap.org/data/2.5/weather?id=1863967&units=metric&appid=xxxx" -Method Get

PS > $ow

coord : @{lon=130.42; lat=33.61}
weather : {@{id=803; main=Clouds; description=broken clouds; icon=04n}}
base : stations
main : @{temp=19.68; pressure=1004; humidity=77; temp_min=18.89; temp_max=20}
visibility : 10000
wind : @{speed=1.5; deg=270}
clouds : @{all=75}
dt : 1560090033
sys : @{type=1; id=7998; message=0.0064; country=JP; sunrise=1560024473; sunset=1560076033}
timezone : 32400
id : 1863967
name : Fukuoka-shi
cod : 200


# Let's get JST sunrise time from Unix timestamp.
PS > ((Get-Date 01.01.1970)+([System.TimeSpan]::fromseconds($ow.sys.sunrise))).AddHours(9)

2019年6月9日 5:07:53

Friday, May 31, 2019

Powershell: Compare-Object to analyze two files

Displaying differences between two files like Linux 'diff' command, you can use Powershell Compare-Object cmdlet.

# You do not find any identical differences with just giving file names.
PS > Compare-Object .\sample01.txt .\sample02.txt

InputObject SideIndicator
----------- -------------
.\sample02.txt =>
.\sample01.txt <=


# You can identify differences between two files with following method.
PS > Compare-Object (Get-Content .\sample01.txt) (Get-Content .\sample02.txt)

InputObject SideIndicator
----------- -------------
efg =>
hijkl =>
efgh <=
ijkl <=

Thursday, May 30, 2019

Powershell: Get-Command / Get-Module

Get-Command allows you to check whether the specific cmdlet is available on your Powershell environment.
Each cmdlets are provided by Powershell module, and it belongs to the module.


Invoke-RestMethod is provided by Microsoft.PowerShell.Utility module
PS Env:\> Get-Command Invoke-RestMethod

CommandType Name Version Source
----------- ---- ------- ------
Cmdlet Invoke-RestMethod 3.1.0.0 Microsoft.PowerShell.Utility


You can see a number of cmdlets are provided by Microsoft.PowerShell.Utility with 'Get-Module' cmdlet.
PS Env:\> (Get-Module Microsoft.PowerShell.Utility).ExportedCmdlets

Key Value
--- -----
Add-Member Add-Member
Add-Type Add-Type
Clear-Variable Clear-Variable
Compare-Object Compare-Object
Convert-String Convert-String
ConvertFrom-Csv ConvertFrom-Csv
ConvertFrom-Json ConvertFrom-Json
ConvertFrom-String ConvertFrom-String
ConvertFrom-StringData ConvertFrom-StringData
ConvertTo-Csv ConvertTo-Csv
ConvertTo-Html ConvertTo-Html
ConvertTo-Json ConvertTo-Json
ConvertTo-Xml ConvertTo-Xml
Debug-Runspace Debug-Runspace
Disable-PSBreakpoint Disable-PSBreakpoint
Disable-RunspaceDebug Disable-RunspaceDebug
Enable-PSBreakpoint Enable-PSBreakpoint
Enable-RunspaceDebug Enable-RunspaceDebug
Export-Alias Export-Alias

Saturday, May 18, 2019

Powershell: Import-CSV

# -Delimeter option allows you to set separator value other than comma.
# Use -Encoding option to specify imported csv character set. The default is UTF8 without BOM.
> $test=Import-Csv .\KEN_ALL.CSV -Encoding Default

# Once you imported, you can manipulate the variable as array object.
> $test.Count
124267


> $test[112200]

a : 40133
b : 810
c : 8100001
d : フクオカケン
e : フクオカシチュウオウク
f : テンジン
g : 福岡県
h : 福岡市中央区
i : 天神
j : 0
k : 0
l : 1
m : 0
n : 0
o : 0


> $test | where { $_.b -match "^818" } | Format-Table -Property c ,g,h,i

c g h i
- - - -
8180000 福岡県 筑紫野市 以下に掲載がない場合
8180011 福岡県 筑紫野市 阿志岐
8180012 福岡県 筑紫野市 天山
8180068 福岡県 筑紫野市 石崎
8180014 福岡県 筑紫野市 牛島
8180034 福岡県 筑紫野市 美しが丘南


# Now you want to clear the variable!

> $test.Clear()

Wednesday, May 15, 2019

Powershell: Securely pass credentials to script

Embedding user credential on the Powershell script is sometimes regarded as security breach, and severely punished when it was revealed.
It would be better solution to use ConvertFrom-SecureString to encrypt secure string, and ConvertTo-SecureString to decrypt.

Overall steps would be like following:
1. Create password with 'Secure string object'.
2. Create encrypted password file with [1] by 'ConvertFrom-SecureString' cmdlet.
3. Decrypt [2] file to get password as 'Secure string object' by runnning 'ConvertTo-SecureString' cmdlet.


#Create password as 'Secure string object'
> $password=Read-Host -AsSecureString "Enter Password"
Enter Password: ***********

#You can see the password you typed became 'Secure string object'
> $password
System.Security.SecureString

#Save 'Secure string object' with encryption
> $password | ConvertFrom-SecureString | Out-File password-file.txt

#You can see the password was encrypted and sotred in file
> cat .\password-file.txt
01000000d08c9ddf0115d1118c7a00c04fc297eb0100000052be3e1d12e24643a99e5adca0fccae300000000020000000000106

#Now you can decrypt the password-file and can be used for credential.
> $User = "somedomain\yangjie"
> $PWord = Get-Content .\password-file.txt | ConvertTo-SecureString
> $Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord

Monday, May 13, 2019

Powershell: Start-Job

Like put an ampersand sign on the end of Linux command statement, Powershell 'Start-Job' cmdlet allows you to run command that you specified as background job.

If you pass it to 'Wait-Job', prompt rather waits until the job done.


#-ScriptBlock to specify command/script to run
#-Name to specify friendly name of the job
> Start-Job -ScriptBlock { systeminfo.exe } -Name JobSysInfo

Id Name PSJobTypeName State HasMoreData Location Command
-- ---- ------------- ----- ----------- -------- -------
1 JobSysInfo BackgroundJob Completed True localhost systeminfo.exe

# Get Detailed property list
> (Get-Job -id 1) | Format-List -Property *

State : Completed
HasMoreData : False
StatusMessage :
Location : localhost
Command : systeminfo.exe
JobStateInfo : Completed
Finished : System.Threading.ManualResetEvent
InstanceId : 57241598-0879-41eb-93c6-58e65f4b09e2
Id : 1
Name : JobSysInfo
ChildJobs : {Job2}
PSBeginTime : 2019/05/14 12:01:20
PSEndTime : 2019/05/14 12:01:24
PSJobTypeName : BackgroundJob
Output : {}
Error : {}
Progress : {}
Verbose : {}
Debug : {}
Warning : {}
Information : {}



#Job result can be shown by Receive-Job cmdlet
> Receive-Job (Get-Job -id 1) ホスト名: DESKTOP-0TV9VQT
OS 名: Microsoft Windows 10 Home
OS バージョン: 10.0.17134 N/A ビルド 17134
OS 製造元: Microsoft Corporation
OS 構成: スタンドアロン ワークステーション


#Long running job can be stopped by StopJob method.
> (Get-Job -id 1).StopJob()

Sunday, May 12, 2019

Powershell: Start-Transcript

Due to security reason or audit purpose, operators are required to record an activity on the terminal.
Powershell provides session record/logging command, defined as 'Start-Transcript'.

> Start-Transcript -Path "pshell.log" -NoClobber
トランスクリプトが開始されました。出力ファイル: pshell.log

> ls

ディレクトリ: C:\Users\drago\

Mode LastWriteTime Length Name
---- ------------- ------ ----
------ 2018/12/11 10:51 4289310 IMG_20181211_194816.jpg
------ 2018/12/11 10:51 2320769 IMG_20181211_194840.jpg
------ 2018/12/11 10:51 3137062 IMG_20181211_194852.jpg
------ 2018/12/11 10:51 3223160 IMG_20181211_194856.jpg
------ 2018/12/11 10:51 3470993 IMG_20181211_194902.jpg
------ 2018/12/11 10:51 3977489 IMG_20181211_195032.jpg
-a---- 2018/06/15 14:23 52193 portrait-2.zip
-a---- 2019/05/12 23:12 759 pshell.log


>
>
> Stop-Transcript
**********************
Windows PowerShell トランスクリプト終了
終了時刻: 20190512231418
**********************



Add '-NoClobber' option for preventing the log be overwritten.

You can check the log file that you specified on '-Path' parameter of the command.
You can terminate the session, or just gently type 'Stop-Transcript' to end it.

Saturday, May 11, 2019

PowerShell: Measure-Command


This is how we can measure a command or script block run on PowerShell like Linux time command.



PS C:\Users\drago> $i=0; Measure-Command { for ($i=1; $i -le 10; $i++) { Write-Progress -Activity "measure running time

" -Status "$i% completed" -PercentComplete $i; sleep 1;

>> }} | Select-Object Seconds




Seconds

-------

10

Powershell: Get-EventLog

Using Get-EventLog cmdlet is sometimes more efficient way to check event log than open Event Viewer.


PS C:\Users\drago> Get-EventLog -LogName System -Newest 5

Index Time EntryType Source InstanceID Message
----- ---- --------- ------ ---------- -------

12650 5 10 19:02 Information Microsoft-Windows... 1 システムは低電力状態から再開しました。...

12649 5 10 19:02 Information Microsoft-Windows... 1 CVE の検出の可能性: 2019-05-10T10:02:30.5000000..

12648 5 10 19:02 Information EventLog 2147489661 システムの稼働時間は 10367070 秒です。

12647 5 09 23:57 Information Microsoft-Windows... 107 ソース 'Microsoft-Windows-Kernel-Power' のイベ...

12646 5 09 23:57 Information Microsoft-Windows... 42 ソース 'Microsoft-Windows-Kernel-Power' のイベ..



It also can filter logs with '-EntryType' or '-Source'.
I tried to retrieve System Error log other than "DCOM" source type as follow.


PS C:\Users\drago> Get-EventLog -LogName System -EntryType Error | where {$_.Source -notlike "dcom"} | Select-Object -First 5


Index Time EntryType Source InstanceID Message

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

12355 5 01 14:16 Error Microsoft-Windows... 20 インストールの失敗: エラー 0x80073d02 で次の更...

11835 4 17 13:50 Error VBoxNetLwf 3221487628 ドライバーは \Device\VBoxNetLwf で内部ドライバ...

11834 4 17 13:48 Error VBoxNetLwf 3221487628 ドライバーは \Device\VBoxNetLwf で内部ドライバ...

11833 4 17 13:48 Error VBoxNetLwf 3221487628 ドライバーは \Device\VBoxNetLwf で内部ドライバ...

11765 4 14 20:49 Error Microsoft-Windows... 20 インストールの失敗: エラー 0x80073d02 で次の更...





Here is how we can monitor system event log with retrieving it every 5 seconds.

PS C:\Users\drago> while(1){
>> Get-EventLog -LogName System -Newest 10 ;
>> sleep 5;
>> cls;
>> }

Powershell: Display progress indicater

Implementing progress bar sometimes would be efficient as we can identify if the task is still ongoing or unexpectedly hunged.

Let's try 'Write-Progress' cmdlet.


for ($i = 1; $i -le 50; $i++ )
{
    Write-Progress -Activity "Title of progress bar" -Status "$i% Complete:" -PercentComplete $i;

# Do something, such as file copy or time consuming tasks etc..
    Sleep 2;

}


Powershell: [System.Version]$_

Use version class for comparing dotted numbers, such as IP address.

PS C:\Users\drago> $IPAddresses = @(
>> '10.10.12.13',
>> '10.11.102.3',
>> '10.12.10.26',
>> '10.13.10.252'
>> );


PS C:\Users\drago> $IPAddresses | Sort { [System.Version]$_ }

10.10.12.13
10.11.102.3
10.12.10.26
10.13.10.252


#powershell, #dotnetframework, #windows

Powershell: curl equivalent command

If your Powershell version is higher than 3, 'Invoke-RestMethod' command is available as alternative method of Unix/Linux curl command.

>> Check the version of your powershell.


PS C:\Users\drago> $PSVersionTable.PSVersion | Select-Object major

Major
-----
5


>> And just type URI whatever you want to retrieve
PS C:\Users\drago> Invoke-RestMethod -Uri https://www.msn.com -Method Get




I tried to process the result with piped 'Select-String', though couldn't filter the result.


The command is not so easy as curl, further study is still needed for it.