Skip to content

Instantly share code, notes, and snippets.

@josanua
Last active November 29, 2024 14:02
Comenzi consola
===> Comenzi consola <===
// comenzi consola
https://ss64.com/osx/ //utils
// List of Command Line Commands
https://www.codecademy.com/article/command-line-commands
______________ work files ______________
-> Listarea Foldere-lor, files, work with files <-
$ ls "list current working directory"§
$ pwd "display the current directory you are in"
$ cd "change current working directory"
$ cd ~ "change to root dir"
$ cd / "change to HD root dir"
$ ls -lah "show files and directories with details"
$ mkdir "create new folder"
$ cp "Copying files"
$ mv "Moving files" (ex. rename dir - mv old-folder-name new-folder-name)
$ rm -rf "delete no needed directories"
Options Description
ls -a list all files including hidden file starting with '.'.
ls -d list directories - with ' */'.
ls -l list with long format - show permissions.
ls -F Append indicator (one of */=>@|) to entries.
ls -lh This command will show you the file sizes in human readable format.
ls -r list in reverse order.
ls -i list file's inode(index) number.
ls -ltr View Reverse Output Order by Date.
ls -t sort by time & date.
ls -n It is used to print group ID and owner ID instead of their names.
ls -m A list of entries separated by commas should fill the width.
ls -g This allows you to exclude the owner and group information columns.
ls -q Force printing of non-graphic characters in file names as the character `?';.
ls -Q Place double quotations around the entry names.
// short util ls command
ls -lah (list with long format - show permissions, list all files including hidden file starting with, )
sudo
-s to start a root shell and then simply
// find the process id to take (PID), find process
sudo lsof -i :8080
// Identify the process using port 80:
sudo lsof -i :80
// Then to kill the process
kill -9 00001 (PID)
// Kill ports, stop ports, stop using ports
// Something is already running on port 3000.
npx kill-port 3000 8080 4200
// npm port already in use
lsof -i tcp:3000
kill -9 PID
// detect port which it's in use
sudo lsof -i :80
// file permission
https://www.malcare.com/blog/wordpress-file-permissions/
https://ithemes.com/blog/wordpress-file-permissions/#:~:text=Correct%20File%20Permissions%20for%20the%20wp%2Dcontent%20Folder&text=Setting%20the%20permission%20of%20the,right%20protection%20against%20unauthorized%20access.
// Common File Permission Codes
755 - means that the owner can do anything while others can read and execute but may not alter the file. This is ideal for public files.
644 - means you can read and write while others can read only.
711 - means that the only can do anything with the file while others can only execute.
700 - means that you can do anything while others have no access. This is best used for private directories and items within the backend.
600 - means that you can read and write while other users have no access. This is ideal for private text files.
444 - means that everyone can read.
0 - for no permissions
1 - for execute
2 - for write
3 - for execute and write
4 - for read
5 - for execute and read
6 - for write and read
7 - for execute, write, and read
// download files from server
https://www.geeksforgeeks.org/how-to-download-a-file-from-a-server-with-ssh-scp/
scp yourRemoteUserName@remoteIP:/path/to/file1.txt /Users/me/
scp ec2-user@172.16.1.11:/var/www/html/1.php /users/josanu/downloads
rsync -P ec2-user@172.16.1.11:/var/www/html/wp-content.tar.gz /users/josanua/downloads
______________ work Vim ______________
// Vim Cheat Sheet
https://vim.rtorr.com/
Vim Command:
i - Enter "insert mode" to edit the text.
Esc - Exit "insert mode."
:wq - Save changes and quit Vim.
:q! - Quit without saving (if you want to cancel the changes).
// open file in text editor
cat ~/Library/Group\ Containers/group.com.docker/settings.json
open -a TextEdit ~/Library/Group\ Containers/group.com.docker/settings.json
-> Instalare in CLI <-
Edit the Commit Message in Vim:
When the commit message opens in Vim, you’ll be in "normal mode" by default. To edit the message:
- Enter Insert Mode: Press i to enter "insert mode," which allows you to edit the text.
- Edit the Message: Make the necessary changes to the commit message.
- Save and Exit:
After editing, follow these steps:
- Press Esc to exit "insert mode" and return to "normal mode."
Type :wq and press Enter to save your changes and exit Vim.
______________ work Node ______________
# uninstall and reinstall
$ brew update
$ brew uninstall node
$ brew install node
$ chown -R YourUserName /usr/local/lib/node_modules/
$ brew postinstall node #This what the important step
-> Update Node <-
https://bytearcher.com/articles/ways-to-get-the-latest-node.js-version-on-a-mac/
brew update
brew upgrade node
node -v (find node version)
-> install nvm (Node Version Manager) <-
https:/ /github.com/nvm-sh/nvm "Install & Update Script"
https://www.youtube.com/watch?v=IZfAZ7R0FQg
// installer link
https://github.com/nvm-sh/nvm#install--update-script
nvm -v
-> update node
nvm install node (update node)
-> install different versions
nvm install 16.20.0
-> use it
nvm use 16 (use needed node version)
-> just run it
nvm run node --version ()
--> use version 20 by default
nvm install 20
nvm alias default 20
nvm current
// 1. **Add NVM Configuration to Configuration Files:** Ensure that your shell's configuration files (like `.bashrc`, `.bash_profile`, or `.zshrc`, depending on your shell) include the necessary configuration for `nvm`. Usually, this line is added:
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
# ??? wp maybe
// sh: /node_modules/.bin/wp-scripts: Permission denied
chmod +x node_modules/.bin/wp-scripts
_____________ node packages ______________
// live server
globaly - sudo npm install live-server -g
run - live-server
______________ OpenSSL ______________
brew install openssl
_________________________________
______________ work ssh, work with terminal ______________
https://www.mrtechnique.com/how-to-set-up-ssh-keys-on-a-mac/
// find and vew keys on mac
cd ~/.ssh (go to ssh dir)
ls (list ssh dir)
cat (cat id_rsa.pub for example)
// add key which I wan to use, ask passphrase, ask password, gitlab ask password
ssh-add ~/.ssh/<private_key_file>
ssh-add ~/.ssh/id_rsa
// or use and connect with a generated key and passphrase, I used pem file
ssh username@yourserver.com -i ~/.ssh/dummy-key (can be any directory)
ssh-keygen // generate keygen
cat ~/.ssh/id_rsa.pub // copy public key
ssh -i .ssh/id_rsa root@134.122.81.108
// copy key in memory, get key from console
// pbcopy < ~/.ssh/id_rsa.pub
killall sshd // restart processes (le inchide nu le reseteaza!!!)
// Restart daemon:
sudo systemctl restart sshd
// add file and conect
ssh-add greystone.pub root@134.122.81.108
// copy key content
clip < ~/.ssh/id_rsa.pub
// Add an SSH key to your GitLab account. copy key
tr -d '\n' < ~/.ssh/id_rsa.pub | pbcopy
// add v
git remote add ssh-origin git@bitbucket.org:dynamittdev/industria-stack.git
// connect to project whith mentioned ssh key
ssh -i ~/.ssh/digitalocean dyno@industria-staging.webstaging.be
// Verbose mode is helpful in diagnosing SSH connectivity
ssh -v user@IP-Address
// view log files
If you have SSH access to your server, you can use command-line tools like cat, tail, or less to read the error log file.
cat /path/to/error_log
// work with Putty
https://www.ssh.com/academy/ssh/putty/mac
First needs to generate keys in cPanel and after download it in ppk format or pem if exists
# 1 - convert the .ppk format private key to a standard PEM format private key:
puttygen privatekey.ppk -O private-openssh -o privatekey.pem
# 2 - Make sure permissions on the private key file are set properly.
chmod go-rw privatekey.pem
# 3 connection
ssh -i privatekey.pem user@hostname
--> Digital Ocean add ssh key to droplet <--
// https://docs.digitalocean.com/products/droplets/how-to/add-ssh-keys/to-existing-droplet/
// Log in as root
// Edit ssh config:
sudo nano /etc/ssh/sshd_config
// Change this line:
PasswordAuthentication no
// to
PasswordAuthentication yes
// Restart daemon:
sudo systemctl restart sshd
Do ssh-copy-id on local machine:
ssh-copy-id someuser@<my-ip>
// check certificate, Check Certificate Expiration Date:
openssl x509 -enddate -noout -in certificate.pem
// check details
openssl x509 -text -noout -in certificate.pem
______________ work npm ______________
https://www.youtube.com/watch?v=P3aKRdUyr0s
# initializare package.json in folder necesar
npm init -y
npm list (packages list)
npm install -g package-name (install globally)
npm view package-name versions (list package versions)
npm install package-name@latest (install the last major version)
npm install package-name@5 (install version 5)
# update npm
npm install -g npm
# verificare module globale consola instalate <-
npm ls -g --depth=0
# create package.json
npm init (in project folder)
npm init -y (quick create a default .json file)
npm install node-sass gulp-sass --save-dev
npm install --save-dev gulp-watch
npm i -g npm (to update)
npm run start (execute start scripts)
# When installing a package that will be bundled into your production bundle, you should use
npm install --save
# If you're installing a package for development purposes (e.g. a linter, testing libraries, etc.) then you should use
npm install --save-dev
# regenerate package-json
npm install --package-lock
______________ Gulp (in ordine) ______________
# In CLI
$ npm i gulp-cli -g // fara sudo
# In directoriu de lucru
$ npm init
$ npm install --save-dev gulp ( npm install --save-dev gulp@3.9.1 )
$ npm init -y //initializare pentru gulp (mai ales daca sunt mentionate in package.json)
$ npm i gulp-concat -D //Instalare module (mai ales daca sunt mentionate in package.json)
# additonal inf
$ gulp --version (verions)
$ gulp --tasks (show tasks)
$ ncu (update gulpfile)
# -> Gulp modules
$ npm install --save-dev browser-sync
$ npm install --save-dev gulp-autoprefixer
$ npm install --save-dev gulp-changed (ceva cu imaginile ?)
$ npm install --save-dev gulp-clean-css (?)
$ npm install --save-dev gulp-concat (concat all css/js files)
$ npm install --save-dev gulp-sass (sass)
$ npm install --save-dev gulp-sourcemaps
$ npm install --save-dev gulp-uglify (minify js file)
______________ SASS (Ruby without Gulp) ______________
# install
$ sudo gem install sass
Ruby Sass is deprecated and will be unmaintained as of 26 March 2019.
* If you use Sass as a command-line tool, we recommend using Dart Sass, the new
primary implementation: https://sass-lang.com/install
* If you use Sass as a plug-in for a Ruby web framework, we recommend using the
sassc gem: https://github.com/sass/sassc-ruby#readme
* For more details, please refer to the Sass blog:
http://sass.logdown.com/posts/7081811
# if not work do
$ xcode-select --install
$ sass -v
sass sass/main.scss:css/main.css (in foldere)
# watch
$ sass --watch input.scss output.css
$ sass --watch app/sass:public/stylesheets (in foldere)
# Convert Sass to SCSS
$ sass-convert style.sass style.scss
# Convert SCSS to Sass
$ sass-convert style.scss style.sass
_________________________________
______________ SSH ______________
Connectare SSH:
$ shh username@IP;
Asculta log-urile:
$ tail -f /var/log/httpd/*
// change rights, schimba drepturi directorie, change map rights,
// https://help.ubuntu.com/community/FilePermissions
chmod -R 777 wp-admin
sudo -s chmod -R 777
// If you want to remove all the files in the current directory and leave the directory,
rm -rf *
// To delete a whole folder and its content recursively, you can use:
rm -rf foldername/
// Archives, work archive
https://www.siteground.com/tutorials/ssh/archives/
// To extract
unzip archive.zip
tar -xvf archive.tar
tar -zxvf archive.tar.gz
rar x archive.rar
// To create, create archive
tar -zcf archive-name.tar.gz foldername/
// Commands explanations
https://linuxhint.com/linux-tar-command/
-c: This creates an archive file.
-f: Specifies the filename of the archive file.
-z: Creates a tar file using gzip compression
_________________________________
-> Arhivare cu parola <-
https://www.imore.com/how-create-and-password-protect-zip-file-macos
https://www.youtube.com/watch?v=H-daEXrvwBk
zip -er FILENAME.zip FILESorFOLDERStoCOMPRESS.
______________ DNS ______________
Adaugare inregistrare in hosts
https://www.imore.com/how-edit-your-macs-hosts-file-and-why-you-would-want
// edit hosts file
$ sudo nano /etc/hosts (or sudo vim /etc/hosts)
$ sudo killall -HUP mDNSResponder ( flush your Mac's DNS cache - need to do )
-> DNS Windows <-
ipconfig
Flush DNS cache
in Run or CMD - ipconfig /flushdns
in powershell - Clear-DnsClientCache
// clear DNS from terminal
sudo killall -HUP mDNSResponder;say DNS cache has been flushed
_________________________________
Install Compass scss compilator in PHPStorm
if error ERROR: Failed to build gem native extension.
xcode-select --install
and then or in case of not error
sudo gem install sass
sass -v
// Setup in IDE (https://www.youtube.com/watch?v=xGhW01blIi4)
https://www.jetbrains.com/help/phpstorm/using-file-watchers.html#
Program: /usr/local/bin/scss
Arguments: --no-cache --update --sourcemap=none $ProjectFileDir$:$FileNameWithoutExtension$.css (exemplu meu, salveaza in fisierul proiectului) - lucreaza
Output path to refresh: $ProjectFileDir$/css/$FileNameWithoutExtension$.css
// work in WP project but save in sass directory
--no-cache --update --sourcemap=none $ProjectFileDir$/wp-content/themes/bio/sass/$FileNameWithoutExtension$.scss
$ProjectFileDir$/wp-content/themes/bio/css/$FileNameWithoutExtension$.css
$FileDir$
______________ FilleZilla backup ______________
js "/Applications/Visual Studio Code.app"
css "/Applications/Visual Studio Code.app"
scss "/Applications/Visual Studio Code.app"
sass "/Applications/Visual Studio Code.app"
php "/Applications/Visual Studio Code.app"
______________ work Git ______________
https://githowto.com/
Git are 3 stari:
1. Fisierul creat
2. Git urmareste fisierele
3. Git a creat un punct de control
// initirea, informatie despre
git init (initierea)
git config (https://githowto.com/setup)
git status
// adaugare schimbari/comit
git add -A (adauga fisierele, -A toate, sau numefisier.extensie)
git commit -a -m"first commit" (-a toate fisierele, -m message)
git push -u, ex. git push -u origin master (din ex. de mai sus
// lucrul cu fisierele
git remote add (adaugam un repozitoriu de la distanta) ex. git remote add origin
git clone "link" it folder name
git pull (sa tragi de pe repozitoriu)
*** probleme git, git issues ***
// versiuni diferite in terminal
// https://stackoverflow.com/questions/63985000/git-version-displays-wrong-version-on-terminal
brew link git
______________ Composer ______________
https://getcomposer.org/
https://packagist.org/ (packages)
// install composer
curl -sS https://getcomposer.org/installer | php
// install something in folder you are
composer require intervention/image
https://www.youtube.com/watch?v=pXV7XGiDvLs
test if work php composer.phar
php composer.phar dump-autoload
// After changes in composer.json need to do update in composer.lock (phpStorm propose to do it automatically)
https://getcomposer.org/doc/01-basic-usage.md
// main commands
composer install
// ignore requirements
composer install --ignore-platform-reqs
// Remove Composer Package, delete composer package
composer remove vendor/package-name
// main commands
composer show
composer show -l
composer show [package]
// To force the autoload file to regenerate just run the command below, clear cache
composer dumpautoload
// Composer WP, use composer with wordpress
// https://roots.io/docs/bedrock/master/composer/#plugins
// https://roots.io/screencasts/using-composer-with-wordpress/
composer install
composer update (after that I added needed dep. info in composer.json)
composer require wpackagist-plugin/wordpress-seo
// To add a plugin, add it under the require directive or use 'composer require <namespace>/<packagename>'
composer require "wpackagist-plugin/akismet" : "dev-trunk"
// Efficiently resolving composer.lock git merge conflicts
git checkout --theirs composer.lock
composer update php
// Fillezila setup
js "/Applications/Visual Studio Code.app"
css "/Applications/Visual Studio Code.app"
scss "/Applications/Visual Studio Code.app"
sass "/Applications/Visual Studio Code.app"
php "/Applications/Visual Studio Code.app"
_________________________________
______________ work with PHP ______________
-> general commands utility <-
php -i // information about installed php
php -v
-> php console, add mamp php to console <-
https://io.serendipityhq.com/experience/how-to-make-terminal-use-mamps-php-in-only-3-steps/
https://gist.github.com/oliveratgithub/73bb1add9df20b243807c4b0ab3da81b
$ which php
$ echo $PATH
// run in VSCode console
Code Runner App
-> work with php packages, work php <-
https://getgrav.org/blog/macos-ventura-apache-multiple-php-versions
https://getgrav.org/blog/macos-ventura-apache-upgrade-homebrew
// after installation only
// change php version
brew unlink php && brew link --overwrite --force php@7.3
______________ workstation setup ______________
install Git CLI https://cli.github.com/
install php from MAMP version
Change hosts file
Step 1: Launch Terminal, found in /Applications/Utilities/ or launched through Spotlight
Step 2: Type the following command at the prompt to backup hosts file to documents folder:
sudo cp /private/etc/hosts ~/Documents/hosts-backup
Step 3: Type the following command at the prompt to open hosts file:
sudo nano /private/etc/hosts
Step 4: Enter the administrator password when requested, you will not see it typed on screen as usual with the command line
Step 5: Once the hosts file is loaded within nano, use the arrow keys to navigate to the bottom of the hosts file to make your modifications
Step 6: When finished, hit Control+O followed by ENTER/RETURN to save changes to /private/etc/hosts, then hit Control+X to exit out of nano
Step 7: Verify your hosts modifications. You may need to clear DNS cache first.
// Clear DNS
sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder;say DNS cache has been flushed
_____________ work apache ______________
// linux
sudo service apache2 stop
// for Mac
sudo apachectl stop
sudo apachectl status
______________ Docker ______________
https://www.youtube.com/watch?v=QF4ZF857m44
// General info
Docker container defaul IP: 172.17.0.2:5000 (accesible in docker host)
In Docker, the host is a machine responsible for running one or more containers.
// docker images (de vazut ce imagini sunt)
docker ps (de vazut ce containere sunt pornite)
docker ps -a (istoria celor executate)
docker ps -a -q (returneaza doar id-urile)
//-> working containers
// list containers
docker ps (list runing containers)
docker ps -a (to see all containers history)
// general info, logs, images details
docker inspect 'Repository name' or 'Image ID'
docker logs 'ID or Name'
// download images and run it
docker pull 'image-name'
// start
docker up -d
// start a container
docker run 'container Images'
docker run nginx (will download and start a container, will start with new container creation)
docker run -d (detach mode - return to prompt)
// run container with specific opened port
docker run -p 80:5000 'CONTAINER TAG'
// docker run and connect Volumes
docker run -v /opt/datadir:/var/lib/mysql mysql
// example with execute bash in container with some OS Image
docker run -it 'os image name' bash
// stop a container, kill container
docker stop 'CONTAINER ID' or 'NAME'
// delete a container
docker rm 'CONTAINER ID' or 'NAME'
// remove a images (first need to remove container)
docker rmi -f 'name:tag or ID' (force remove container) https://docs.docker.com/engine/reference/commandline/rmi/
// porneste imagine docker
docker run hello-world (porneste docker-ul)
docker run --name hello -d hello-world (porneste cu numele de container 'hello' cu param -d in background )
docker run --name hello -d --rm hello-world (container se sterge dupa ce este oprit)
// opreste docker
docker stop 'name:tag or ID'
// Connect Volumes
// docker run and connect Volumes
docker run -v /opt/datadir:/var/lib/mysql mysql
// remove node modules from docker
rm -rf node_modules
-- creare imagine cu Dockerfile, exemplu cu php --
FROM php:7.4-cli
WORKDIR /Applications/MAMP/htdocs/docker-hello-world/
COPY . /Applications/MAMP/htdocs/docker-hello-world/
CMD [ "php", "./index.php" ]
// crearea imaginii
docker build -t hello-world . (creaza imaginea)
// get IP address
docker inspect <container_id>
______________ Docker compose, docker-compose ______________
https://docs.docker.com/compose/reference/
// Some main commands
docker-compose build
docker-compose run --rm wp ( wp from 'entrypoint: ['wp', '--allow-root']' from docker-compose file )
--> Docker proiecte <--
// porneste console pe server, docker shell
docker-compose exec app /bin/ash (app = name of container image, ex.:nginx - image:app)
// greystone
// update composer
/var/www $ composer update
// industria local
// mutare pe docker/ docker pe industria local
docker-compose exec app /bin/ash
/var/www/web/app/themes/industria-theme $
docker-compose exec app sh
--> docker npm issues <--
// Error: EACCESS permission denied
sudo chown -R $(whoami) ~/.npm
--> docker hub logingg, docker hub acces, use access token <--
docker login -u ajosanustaffcapital
use access token for password
______________ LARAVEL ______________
php artisan config:clear //it will help you, clear cached config, after .env changes
--> laravel temp/sail commands docker start, work with laravel sail command <--
// https://laravel.com/docs/8.x/sail#introduction
--> sail commands <--
configure Bash alias => alias sail='[ -f sail ] && bash sail || bash vendor/bin/sail'
// commands to do, work sail, work docker laravel
--> install sail <--
docker-composes
php artisan sail:install
options 0,7 (mysql+mailhog)
./vendor/bin/sail up -d (detach)
./vendor/bin/sail artisan migrate
// comenzi sail
sail up -d
--> migration commands <--
Migrations are like version control for your database
php artisan make:migration create_flights_table (Generate migrations)
sail artisan migrate (daca utilizezi sail)
php artisan make:migration create_posts_table --create="posts"
sail artisan migrate
sail artisan migrate:reset()
sail artisan migrate:refresh ()
_____________-> wp-cli, wp cli <-_____________
// general info
wp --info
// instal WP
wp core download
// serch and replace domains name
wp search-replace --url=industria-staging.webstaging.be industria-staging.webstaging.be localhost:8000 'wp_*options' wp_blogs
// change db and in multisite version
wp search-replace 'industria.be' 'localhost:8000' wp_blogs --url=industria.be
wp search-replace 'kd.localhost:8000' 'localhost:8001' --all-tables
wp search-replace 'https://industria.be' 'http://localhost:8000' --all-tables
wp search-replace 'https://kd.industria.be' 'http://localhost:8001' --all-tables
wp user update admin --user_pass=admin (if need to change user pass)
// udpate user inf
wp user update username --user_pass='root'
// search in db
wp db search kd.industria-staging.webstaging.be --network
_____________-> bedrock <-_____________
https://docs.roots.io/bedrock/master/installation/#requirements
composer create-project roots/bedrock
_____________Apache_____________
sudo nano /etc/apache2/httpd.conf
sudo apachectl stop
sudo apachectl restart
__________php homebrew, work with php __________
// update to php 7.4
// https://stackoverflow.com/questions/64684713/update-php-to-7-4-macos-catalina-with-brew
brew install php@7.4
brew link --force --overwrite php@7.4
brew services start php@7.4
export PATH="/usr/local/opt/php@7.4/bin:$PATH"
export PATH="/usr/local/opt/php@7.4/sbin:$PATH"
which php (show path)
// alte probleme
https://postsrc.com/posts/how-to-install-php-8-on-macos-big-sur-using-homebrew
brew install php
brew install php@7.4
/usr/local/etc/php/8.0/php.ini
// check if running, check php
brew services list
brew services start php@8.0
php -v
// fix php terminal issues (Could not open library 'sodium': on MacBook with M1 chip)
// https://github.com/Homebrew/homebrew-core/issues/120854
brew tap shivammathur/php
brew upgrade shivammathur/php/php@7.4
__________use deploy__________
// https://deployer.org/docs/7.x/installation
run - php vendor/bin/dep
dep self-update
// main commands
// execute dep file
php vendor/bin/dep
dep
// use in project (Industria)
php vendor/bin/dep -f="config/deploy/deploy.php" pull:files-no-bak staging
/var/www $ ./vendor/bin/dep -f="config/deploy/deploy.php"
// do deploy on staging
./vendor/bin/dep -f="config/deploy/deploy.php" deploy staging
__________rsync__________
// update to v3
rsync --version
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
brew install rsync
--> download WP in console <--
wget https://wordpress.org/latest.tar.gz
tar zxf latest.tar.gz (unarchive)
rm latest.tar.gz (remove archive)
_____________Linux_____________
log files
https://stackify.com/linux-logs/
logs
cd/var/log
// deployment in linux
/home/greystonebe30903/sites/staging.greystonerecruitment.be/checkout/releases
_____________Sage 9_____________
// check DB
$ wp db check
// Tacke Demo data
// before need to install and activate importer plugin
$ wp plugin install wordpress-importer
$ wp plugin activate wordpress-importer
$ curl -OL https://raw.githubusercontent.com/poststatus/wptest/master/wptest.xml
$ wp import wptest.xml --authors=create
_____________ work Webpack _____________
# https://webpack.js.org/guides/getting-started/#basic-setup
# install locally
mkdir webpack-demo
cd webpack-demo
npm init -y
npm install webpack webpack-cli --save-dev
# install only webpack-cli
npm install webpack-cli --save-dev
# When installing a package that will be bundled into your production bundle, you should use
npm install --save
# If you're installing a package for development purposes (e.g. a linter, testing libraries, etc.) then you should use
npm install --save-dev
______________ work mysql, work database, work sql, work db ______________
# SQL Tutorial for Beginners (work in console)
https://www.youtube.com/watch?v=xiUTqnI6xk8&list=WL&index=4
# general and using MySQL Workbench
https://www.youtube.com/watch?v=5OdVJbNCSso&list=WL&index=7&t=5678s
# install on mac, brew reinstall mysql
brew remove mysql
brew install mysql
brew services start mysql
### starter commands, work in mac terminal, start using mysql app
# first command
mysql
mysql -u root
mysql -u username -h serverName -P port -p password
example on localhost: mysql -u root -h 127.0.0.1 -P 8889 -p
# rights
SHOW GRANTS;
# connect on localhost for example
mysql --host=localhost -uroot
# To Close Your MySQL Connection
mysqld stop
### work with database
# create db
mysql> create database db_name;
// show db
mysql> show databases; (; is mandatory, means done)
// use database
mysql> use db_name;
mysql> show tables;
### work tables, mysql tables, work schemas
// create table
mysql> create table table_name (
-> id int,
-> name varchar(255),
-> region varchar(255),
-> roast varchar(255),
-> );
mysql> describe table_name; ( will show detailed table, show Schema - how db are organized )
// rename table name
rename table table_name to another_table_name;
// insert data in table
mysql> insert into table_name values (1, "default route", "ethiopia", "light");
// read data from table
select * from table_name; // select all columns
select name from table_name; // select row name
select * from table_name where column_name = "value";
// update data
update table_name set column_name = "value" where column_name = "value";
// order data
select * from table_name order by column_name asc; // or desc;
// drop table
drop table table_name;
// change table table_name (add one more column)
alter table table_name
add phone_number varchar(15);
// alter database (ex. add new column)
alter table marwell add beard boolean;
// delete data
delete from table_name where column_name = "value";
// alter table, change table
alter table table_name
modify column coumn_name varchar(100);
### my useful things, work experience
// database dump
mysqldump kickjobs_prod > /home/andrey/kickjobs_prod-latest-prod.sql-27092022 (path/filename)
for dump: mysqldump -h db_address -u root -p db_name > file_adress_to_save.sql
# upload database, pay attention to < or > sign direction
mysql kickjobs_prod < /home/andrey/kickjobs_prod.sql-27092022 (path/filename)
mysql kickjobs_prod < /home/andrey/kickjobs_prod-latest-prod.sql-21_april
// steps to do db changes
1. Do DB-s backup with mysqldump
2. Do upload of needed db
3. Select needed to DB to work with - mysql> use database_name;
4. Do updates.
## To restore a MySQL database from an SQL file using the MySQL command on a server console,
# restore db, restore database, migrate db
Open and work in terminal, may be necessary to work from server terminal
1. cd /path/to/directory
2. mysql -u username -p database_name < filename.sql ( example: mysql -u root -p mydatabase < backup.sql )
3. Verify the Restore SHOW DATABASES; and USE DATABASE.
// example (it works from server)
mysql -h rds_server -u your_user -p your_DB < your_backup.sql
_____________ ReactJS _____________
Update Create React App scripts
# If you use Create React App, upgrade react-scripts to v5
# For npm:
npm install react-scripts@5
# For Yarn:
yarn add react-scripts@5
# update webpack
npm install webpack@latest
_____________npx_____________
npx create-react-app react-tutorial
cd react-tutorial && npm start
// in case of npx error after global uninstall older version
npx clear-npx-cache
_____________ Install WP _____________
- Step 1 — Download WordPress
sudo wget https://wordpress.org/latest.tar.gz
- Step 2 — Extract WordPress
sudo tar -xzvf latest.tar.gz
- move the extracted WordPress directory to the /var/www/html
sudo mv wordpress /var/www/html/
// install on Amazon Linux 2
https://dev.to/mkabumattar/how-to-install-wordpress-on-amazon-linux-2-4kj3
https://cloudbytes.dev/aws-academy/how-to-install-and-run-wordpress-on-an-ec2-instance
_____________ Utilities _____________
// about bash https://www.youtube.com/watch?v=I4EWvMFj37g
-- command allows users to search the list of paths in the $PATH environment variable, show commands apps pathwhich
ex. which bash (result /bin/bash)
_____________ Linux _____________
// folder structure
bin - binaries (executable files)
sbin - system binaries
lib - shared code between binaries
etc - editable text configuration
home - home configuration for that user
dev - device files
opt - optional env software
var - variable system data (logs, cache)
tmp - temporary files which are persistent between reboots
proc - (virtual folder for OS)
usr - user directory ()
- bin
- sbin
- local (binaries which is manually compiled)
_____________ cronjob _____________
sudo -s
crontab -e
*/15 * * * * curl http://your-domain.com/wp-cron.php > /dev/null 2>&1
_____________ work with Redis _____________
Redis apps to reading Redis data te
- Another Redis Desktop Manager
- RedisInsight-v2
// start server
redis-server
quit
// redis-cli
SET foo value
GET foo
EXISTS foo
FLUSHALL (delete all data)
// set has (array or object)
HSET person1 name "Andrei"
HSET person1 age 38
HGET person1 age
HGETALL person1
HVALLS person1 (get all values)
_____________ work with server, view logs, nginx logs _____________
go to var/log/nginx/ and execute:
tail -f access.log
// read nginx logs in MAMP
1. cd /Applications/MAMP/logs
2. tail -f nginx_access.log
_____________ curl, API _____________
https://www.youtube.com/watch?v=V5vZWHP-RqU
// https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
1xx informational response – the request was received, continuing process
2xx successful – the request was successfully received, understood, and accepted
3xx redirection – further action needs to be taken in order to complete the request
4xx client error – the request contains bad syntax or cannot be fulfilled
5xx server error – the server failed to fulfil an apparently valid request
_____________ quarantine, mac security, java, JDK _____________
Run JDK, elastic search in mac
https://apple.stackexchange.com/questions/363728/how-to-run-an-app-that-require-java-sdk-on-macos-catalina-10-15
sudo xattr -d com.apple.quarantine /Library/Java/JavaVirtualMachines/jdk-22.jdk
// error with security
sudo xattr -d /Applications/elasticsearch/jdk.app
xattr -d -r com.apple.quarantine kibana (disable gate keeper)
_____________ elastic search _____________
https://localhost:9200
cd elasticsearch
bin/elasticsearch
config/elasticsearch.yml
// reset password (for superuser)
bin/elasticsearch-reset-password -u elastic
// restart for kibana_system
bin/elasticsearch-reset-password --username kibana_system
// use elastic with cURL
// for local machine use --insecure to avoid -> (60) SSL certificate problem: <-
curl --insecure -X GET https://localhost:9200
// apply cert if needed, best way
// elastic dir
1. curl --cacert config/certs/http_ca.crt -X GET https://localhost:9200
// apply cert with username and pass provided on first start
2. curl --cacert config/certs/http_ca.crt -u elastic -X GET https://localhost:9200
// or provide with pass
curl --cacert config/certs/http_ca.crt -u elastic:u8zD9QtBaylEsRW1S2el -X GET https://localhost:9200
// send with Header and json typed
curl --cacert config/certs/http_ca.crt -u elastic:u8zD9QtBaylEsRW1S2el -X GET -H "Content-Type:application/json" https://localhost:9200/products/_search -d '{ "query": {"match_all": {} } }'
//--> elastic docker
// official doc link
https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html
https://deepsil.medium.com/the-ultimate-guide-to-installing-elasticsearch-with-docker-2ec119b1b07f
// start
docker run --name es01 --net elastic -p 9200:9200 -it -m 1GB docker.elastic.co/elasticsearch/elasticsearch:8.13.4
// test, provide cer username and password ($ELASTIC_PASSWORD const)
curl --cacert http_ca.crt -u elastic:$ELASTIC_PASSWORD https://localhost:9200
// test with JSON query
curl --cacert http_ca.crt -u elastic:$ELASTIC_PASSWORD -X GET -H "Content-Type:application/json" https://localhost:9200/products/_search -d '{"query": { "match_all" : {} } }'
//--> kebana
http://localhost:5601
// generate a new Kibana enrollment token:
bin/elasticsearch-create-enrollment-token --scope kibana
bin/kibana
// acces credentials for testing user
kibana_system
Gi6qse_Af-eFr2m6s69f
// service commands
// stopping
https://www.elastic.co/guide/en/elasticsearch/reference/current/stopping-elasticsearch.html
$ jps | grep Elasticsearch
// find the process id
sudo lsof -i :9200
// some theoreticall moments
- Nodes store the data that we add to Elasticsearch
- A cluster is a collection of Nodes
- Data is stored as documents, which are JSON objects
- Documents are grouped together with indices
// kebana devtools console
GET /_cluster/health
// cat API
https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-nodes.html
PUT /pages - create index with pages name
GET /_cat/indices?v - number of shards
GET _cat/nodes?v - work with nodes
GET _cat/indices?v&expand_wildcards=all
_____________ rabbitmq _____________
// docker image
https://www.youtube.com/watch?v=-0g-1ckQgBo // docker
https://www.youtube.com/watch?v=4ESirwpvjzw // tutorial
docker run -it --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3.13-management
access on http://localhost:15672/#/
______________ Grunt file ______________
grunt - Runs the default task defined in the Gruntfile.js
grunt <task> - (grunt build)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment