basic cwp with jenkins and nodejs

hostname srv1.example.com
yum -y install wget
yum -y update
reboot


cd /usr/local/src
wget http://centos-webpanel.com/cwp-el7-latest
sh cwp-el7-latest -r no --phpfpm 7.3 --softaculous no



reboot



sudo wget -O /etc/yum.repos.d/jenkins.repo \
    https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
sudo yum upgrade
sudo yum install epel-release java-11-openjdk-devel
sudo yum install jenkins
sudo systemctl daemon-reload
curl -sL https://rpm.nodesource.com/setup_12.x | bash -
sudo yum install nodejs npm -y
sudo npm install pm2@latest -g

Installing a testing instance for Magento CLI only

Prerequisite:

  • Magento repo access keys
  • Mysql Database, username and password
  • a domain name pointing to a server

if you dont have access key, get a pair here :

https://marketplace.magento.com/customer/accessKeys/

php -d memory_limit=-1 /bin/composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=2.2.11 ./

In the above command, you can change version/subversion of magento repo. You can also change the install directory

After the successful run of above command:

bin/magento setup:install \
--base-url=https://testmagento.domain.com \
--db-host=localhost \
--db-name=testmage_x1 \
--db-user=testmage_x1 \
--db-password=WEux3dxxxxw \
--admin-firstname=xxx \
--admin-lastname=yyy \
[email protected] \
--admin-user=admin \
--admin-password=WwKhxxxxxxEK \
--language=en_US \
--currency=USD \
--timezone=America/Chicago \
--use-rewrites=1



YOu will see Magento Admin URI: /admin_10lf7y after successful run

Next is installing sample data: totally optional

php -d memory_limit=-1 bin/magento sampledata:deploy

OPtional: install or update composer version

composer self-update --2

https://blog.packagist.com/composer-2-0-is-now-available/
https://getcomposer.org/

Basic Authentication with Nginx with proxy port (react/node app etc)

Reference: https://docs.nginx.com/nginx/admin-guide/security-controls/configuring-http-basic-authentication/

Requirements: apache2-utils or httpd-tools

Use htpasswd utility and create a .htpasswd file, see reference

htpasswd -c  /etc/nginx/.htpasswd usernamethatyouwant
chmod 644 /etc/nginx/.htpasswd

After that, just add lines in nginx conf

location / {
	auth_basic "Backend Area";
    auth_basic_user_file /etc/nginx/.htpasswd; ## path to your passwd file
	## ...
	## xyz code
	##... 
	proxy_pass http://127.0.0.1:4000; ## Proxy port for your app
	proxy_set_header Authorization ""; ## DONT FORGET THIS. reset the auth header
	include proxy.inc;
}

Restart nginx now or test first using “nginx -t”

Jenkins auto deploying flask in test env with last build process kill and pipenv

#!/bin/sh
cd $WORKSPACE
export PY=/usr/local/bin/python3
export FLASK_RUN_PORT=4005
$PY -m pip install pipenv
$PY -m pipenv install --dev
export VENV_HOME_DIR=$($PY -m pipenv --venv)
source $VENV_HOME_DIR/bin/activate
flask db upgrade
flask populate-initial-data
export BUILD_ID=XYZapi
$WORKSPACE/killlastbuild.sh
flask run &
deactivate

killlastbuild.sh can have anything inside it depending upon your project requirements. I put 2 process killers to kill background-ed daemon processes from previous build command

ps -Af | grep "xyzapi" | grep -v grep | awk '{print$2}' | head -1 | xargs kill -9
ps -Af | grep "xyzapi" | grep -v grep | awk '{print$2}' | head -1 | xargs kill -9

Total inode count for a particular user in linux

Inode usage for current working directory

echo "Detailed Inode usage for: $(pwd)" ; for d in `find -maxdepth 1 -type d |cut -d\/ -f2 |grep -xv . |sort`; do c=$(find $d |wc -l) ; printf "$c\t\t- $d\n" ; done ; printf "Total: \t\t$(find $(pwd) | wc -l)\n"

Use cd ~ to change pwd to current user home

cd ~

Reference:

Magesh from 2daygeek : https://www.2daygeek.com/linux-check-count-inode-usage/

How to solve MySQL server gone away error Maria Db update on cPanel and WHM?

This is related to new MariaDb upgrade from 10.1.41 to 10.1.42 and also for servers which were updated from 10.2.27 to 10.2.28

Go to solution ( Special Thanks to @Valetia )

You will see errors in following formats/messages:

  • No file or input found
  • MySQL Server has gone away
  • Connection to MySQL Server failed
  • sqlstate[hy000]: general error: 2013 lost connection to mysql server during query
  • General error: 2006 MySQL server has gone away
  • ERROR 2006 (HY000): MySQL server has gone away
  • ERROR 2013 (HY000): Lost connection to MySQL server during query

Log files (/var/lib/mysql/$hostname.err) will have or can have any of these errors:

  • assertion fail /home/buildbot/buildbot/padding_for_CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX/mariadb-10.2.28/storage/innobase/dict/dict0dict.cc line 1467
  • the resulting row size is greater than maximum allowed size (8126) for a record on index leaf page
  • stack_bottom = 0x0 thread_stack 0x49000 mysys/stacktrace.c:268(my_print_stacktrace)[0x5564e62807bb] sql/signal_handler.cc:209(handle_fatal_signal)[0x5564e5d4b4f5]

Other Symptoms:

/etc/init.d/mysql start
Starting MySQL/etc/init.d/mysql: line 159: kill: (10704) – No such process
[FAILED]


Solution:

yum downgrade MariaDB-* -y
whmapi1 update_updateconf RPMUP=manual UPDATES=manual

(run as root #)

This will downgrade MariaDb installation to previous version
Line 2 will cancel automatic update on WHM/CPanel installations

If you are not using WHM, use line 1 only OR you can downgrade the repository individually too

yum downgrade MariaDB-server MariaDB-common MariaDB-shared MariaDB-client MariaDB-compat MariaDB-devel

References:

How to fix Composer should be invoked via the CLI version of PHP, not the cgi-fcgi SAPI error in SSH?

Put this in your bash profile and run source ~/.bashrc

alias composer="/opt/cpanel/ea-php71/root/usr/bin/php /opt/cpanel/composer/bin/composer"

As Composer is now available via WHM you can use this to find it:

which composer

This returned path “/opt/cpanel/composer/bin/composer” for me. If this returns nothing then disregard the rest of this answer, as Composer is not available to you at system level.

You can now use php-cli to call this with Composer’s absolute path:

php-cli /opt/cpanel/composer/bin/composer install
php-cli /opt/cpanel/composer/bin/composer update
php-cli /opt/cpanel/composer/bin/composer require whatever/example

You may however need to alias php-cli if your system claims this isn’t found. It very much depends how PHP has been deployed on the WHM server. Learn how to fix PHP CLI error. You can do this by adding a user alias to the end of your “.bashrc” or “.bash_profile” file as follows:

alias php-cli=/opt/cpanel/ea-php72/root/usr/bin/php

Replace ea-php72 with the release of PHP you want to use. Submit this as a command in the shell to make it available immediately, otherwise it’ll become available when you open your next Bash session.

If you want to make this available with just composer alone you could create this alias again in “.bashrc”:

alias composer=/opt/cpanel/ea-php72/root/usr/bin/php /opt/cpanel/composer/bin/composer

Reference: https://stackoverflow.com/a/53478183/2229148

How to edit default python version for a linux user?

Edit the bash profile and add an alias using the following code

$ nano ~/.bashrc

Put the following line of code in .bashrc file and alter the python3.6 path as per your new installation

alias python='/usr/local/bin/python3.6'

Use CTRL x to exit and save
After that you need to reload the source, so use the following command and you are good to go.

$ source ~/.bashrc

Windows v/s Linux. What’s your choice?

Hi Everyone.

Today we are going to talk about the two operating systems. Windows and Linux. Both of them have their own pros and cons.

Offcourse Windows have its monopoly with 88% plus market shares. Although slowly but Linux has started getting attention and getting more popular day by day.

Windows has dominated the market because it is way simpler to operate than any other operating system.

In this article, we will be focusing on understanding the two operating systems and their pros and cons.

So, let’s begin.

What is Windows operating system?

Windows is a series of operating systems, Each operating system comes with a graphical user interface (GUI) with a desktop which allows a user to view all files, videos etc. The first version of Windows OS was released in 1985 which was a simple GUI, an extension of the existing disk operating system (MS-DOS). windows OS comes with almost all company who made PC’s or laptops. Latest Windows OS version is Windows 10 which is currently ruling the market.

What is the Linux operating system?

Based on UNIX Linux is an open source operating system, created in 1991. Users can modify the existing code and create distributions from it as it is an open source operating system. Linux operating system also comes with a graphical user interface (GUI) with some necessary software’s which are used on a daily basis. Linux is mostly used as a server – as most of the web pages over the internet are generated from Linux servers and also used in desktop computers, mobile devices, gaming consoles, digital storing devices, eBook readers, cameras, video recorders have Linux running.

Comparison:

USES:

Linux is used by corporate, scientific, and academic organizations of every size. It’s used to power the development machines and servers at Google, Facebook, Twitter, NASA, and the New York Stock Exchange, just to name a few. On the desktop, it is used by technically proficient users who prioritize system security and reliability, and by enthusiasts who want to learn more about computers and how they work. Microsoft Windows is usually the operating system of choice for gamers, novice users, and business users who rely on Microsoft software. Many Windows users are thrilled with the changes that Microsoft has introduced with Windows 10, so if you’ve never used it, now is a great time to try it out.

SECURITY:

Linux is a highly secure operating system. Although attack vectors are still discovered, its source code is open and available for any user to review, which makes it easier to identify and repair vulnerabilities. Microsoft has made great security improvements over the years. But as the operating system with the largest user base, especially among novice computer users, it is the primary target for malicious coders. As a result, of all major operating systems, Microsoft Windows is the most likely to be the victim of viruses and malware.

USABILITY:

GNU/Linux operating systems have a steeper learning curve for the average user. They frequently require a deeper understanding of the underlying system to perform day-to-day functions. Additionally, troubleshooting technical issues can be a more intimidating and complicated process than on Window. Windows is one of the easiest desktop operating systems to use. One of its primary design characteristics is user-friendliness and simplicity of basic system tasks. Its ease lack of difficulty is considered positive by users who want their system to just work. However, more proficient users may be frustrated by the oversimplification of system tasks at the expense of fine-grained control over the system itself.

Conclusion:

So, ultimately it depends on the user.

If your use is just of a normal system which is dammed easy to use, go with Windows 10.

But if you are more of a geek, and would love to customize the system as per your needs, go with LINUX.

depends if i have to watch youtube or code

I had shifted to linux for 2-3 months but could not continue because windows have more gui software than any other known operating system. I like to keep things handy to me all the time, so windows.

I still encounter linux everyday because of ssh and servers

– Harshvardhan Malpani (tutes.in: Admin)

OK! everyone this is it for today. See you soon.

Thank You.

How to repair a MySQL database?

Hello! Good to see you.

This is going to be a very important article because we are about to discuss  “How to repair a MySQL database?”

Why repair MySQL Database?

Databases can become corrupted for any number of reasons, from software defects to hardware issues.

If this occurs, you can try to repair the database. Wondering how to do it? Just follow this article.

REPAIRING MYSQL DATABASES:

Let’s see how to repair MySQL database through Linux and Windows command line.

Repair MySQL Database through Windows command line.

 

  • Log in to your Windows VPS using Remote Desktop.
  • Go to Start and locate the Command Prompt. Right-click Command Prompt and select Run as Administrator option.
  • At windows command prompt navigate to MySQL bin directory as follows.
    cd C:\Program Files\MySQL\MySQL Server 5.5\bin  //  Replace your MySQL bin directory path here.
  • Run the following command to start the MySQL prompt.
    mysql -u root -p
  • Enter MySQL root password when you are being asked.
  • You will see MySQL prompt appearing. Now, to display all databases, type following command at MySQL prompt:
    show databases;
  • Enter the following command to repair MySQL database.
    mysqlcheck -r [database] // Replace database name with your database name.

Repair MySQL Database through Linux Terminal.

 

  • Login to your Linux VPS using Secure Shell (SSH) and connect to MySQL from the command line.
    mysql -uUsername -p // Replace Username with your username.
  • Enter MySQL user password and hit Enter. You will see MySQL prompt appearing. Now, in order to display all databases, type following command at MySQL prompt.
    show databases;
  • mysqlcheck enables you to check databases without stopping the entire MySQL service. -r argument is used to repair the corrupted tables. mysqlcheck utility efficiently works on both MyISAM and InnoDB database engines. Enter the following command to repair MySQL database.
    mysqlcheck -r [database] // Replace database name with your database name.

 

So, we covered this issue for both Windows and Linux.

Lastly please check our other articles on various topics, that we tried to address.

Thank You.