Ubuntu

Nesse artigo será exibido detalhadamente os processos feito via terminal para a instalação dos programas

Ubuntu 18.04

After Install

### PPA (Personal Package Archives)

sudo apt install \
build-essential \
curl \
gdebi-core \
git \
gnome-tweaks \
gufw \
indicator-cpufreq \
jq \
lame \
libavcodec-extra \
lynx \
linux-tools-generic \
meld \
net-tools \
openssh-server \
p7zip-full \
preload \
python-pip \
python3-pip\
ubuntu-restricted-extras

sudo service ssh start

#

mysql -h '127.0.0.1' -P '3306' -u 'root' -p'12345' -e "SHOW GLOBAL VARIABLES LIKE 'innodb_buffer_pool_size';"

mysql --help

sudo echo "innodb_buffer_pool_size = 8M" >> /etc/mysql/mysql.conf.d/mysqld.cnf

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

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

sudo systemctl status mysql
sudo systemctl restart mysql

mysql -h '127.0.0.1' -P '3306' -u 'root' -p'12345' -e "SHOW GLOBAL VARIABLES LIKE 'innodb_buffer_pool_size';"

#

sudo add-apt-repository ppa:linrunner/tlp
sudo apt update && sudo apt install tlp tlp-rdw smartmontools && sudo tlp start
# sudo tlp-stat

#

wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo gdebi google-chrome-stable_current_amd64.deb

#

git config --global credential.helper cache
git config --global user.email "[email protected]"
git config --global user.name "USR"
git config --global http.postBuffer 157286400 # FIX: Error: fatal: The remote end hung up unexpectedly, https://confluence.atlassian.com/stashkb/git-push-fails-fatal-the-remote-end-hung-up-unexpectedly-282988530.html
git config --global --list

ssh -T [email protected]

# FIX: [email protected]: Permission denied (publickey)
# Obter a SSH Key 'cat ~/.ssh/id_rsa.pub' e adicionar em https://github.com/settings/keys

# https://pypi.org/

pip3 install awscli --upgrade --user
pip3 install awsebcli --upgrade --user

pip install localstack
pip install beautysh

# https://docs.brew.sh/Homebrew-on-Linux

sh -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)"
test -d ~/.linuxbrew && eval $(~/.linuxbrew/bin/brew shellenv)
test -d /home/linuxbrew/.linuxbrew && eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)
test -r ~/.bash_profile && echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.bash_profile
echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.profile

# https://formulae.brew.sh/

brew install openshift-cli

### https://snapcraft.io/store

snap list
snap version
sudo snap install gitkraken
sudo snap install chromium
sudo snap install circleci
sudo snap install docker
sudo snap install ffmpeg
sudo snap install keepassxc
sudo snap install nmap
sudo snap install obs-studio
sudo snap install okular
sudo snap install opera
sudo snap install screencloud
sudo snap install sftpclient
sudo snap install vlc
sudo snap install atom –classic sudo snap install node –channel=10/stable –classic
sudo snap install brackets --classic
sudo snap install google-cloud-sdk --classic
sudo snap install heroku --classic
sudo snap install ruby --classic

# Plugins - https://atom.io/packages

#composer global require friendsofphp/php-cs-fixer
#export PATH="$PATH:$HOME/.composer/vendor/bin"

apm install \
    atom-beautify \
    atom-clock \
    atom-html-preview \
    autoclose-html \
    busy-signal \
    color-picker \
    editorconfig \
    file-icons pigments \
    highlight-selected \
    intentions \
    linter \
    linter-csslint \
    linter-php \
    linter-ui-default \
    markdown-preview-plus \
    markdown-writer \
    open-recent \
    pretty-json \
    script \
    sort-lines \
    turbo-javascript

# https://www.npmjs.com/

# https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally
# Global Node Modules without sudo
wget https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh
bash ./install.sh
command -v nvm # To verify that nvm has been installed
nvm install node

npm config list
npm list -g --depth 0
npm install -g clever-tools

# Docker setup

# By default the docker daemon always runs as the root user, therefore you need to prepend sudo to your Docker command(s).
# 1. Create the docker group.
sudo groupadd docker
# 2. Add your user to the docker group.
sudo usermod -aG docker $USER
# 3. Log out and log back in so that your group membership is re-evaluated.
# 4. Verify that you can run docker commands without sudo.
docker run hello-world
# more ...
docker info
docker search ubuntu
docker container ls

# Version(s)

aws --version
docker version
docker-compose version
docker-machine version
eb --version
gem --version
heroku --version
node --version
npm --version
nvm --version
pip -V
python -V
ruby --version

Jekyll

sudo gem install jekyll
sudo gem install github-pages
sudo gem install rouge
jekyll -v

phive

# https://phar.io/

wget -O phive.phar https://phar.io/releases/phive.phar
wget -O phive.phar.asc https://phar.io/releases/phive.phar.asc
gpg --keyserver pool.sks-keyservers.net --recv-keys 0x9D8A98B29B2D5D79
gpg --verify phive.phar.asc phive.phar
chmod +x phive.phar
sudo mv phive.phar /usr/local/bin/phive

sudo phive install php-cs-fixer --global

Dica:

# Após criar uma pasta e compartilhar pelo Nautilus só deve funcionar a autenticação após ser criado o devido usuário no Samba
sudo smbpasswd -a $USER

Devilbox

cd ~/dados/containers_docker
git clone https://github.com/cytopia/devilbox
cd devilbox
cp env-example .env
touch touch.txt
echo "commit - $(date '+%d/%m/%Y %H:%M:%S')" > touch.txt

diff --brief --recursive tmp/devilbox-2019-03-07 devilbox
meld tmp/devilbox-2019-03-07 devilbox

cd devilbox
docker-compose up

run devilbox

cd ~/dados/containers_docker/devilbox
docker-compose down --remove-orphans && docker-compose up

./shell.sh
cd /shared/httpd/localhost/htdocs/mozgbrasil/magento2

Virtual Hosts

mkdir -p ~/dados/mount/www/localhost/htdocs/

sudo nano /etc/hosts
    127.0.0.1 localhost.loc

cd ~/dados/mount/www/localhost/htdocs/

ln -s /home/marcio/dados/mozgbrasil

echo "<?php phpinfo(); ?>" > phpinfo.php

cat > .htaccess <<- _EOF_
# enable directory browsing
Options +Indexes
_EOF_

Fix: tail: recursos esgotados do inotify, tail: inotify não pôde ser usado; revertendo para sondagem (polling)

cat /proc/sys/fs/inotify/max_user_instances cat /proc/sys/fs/inotify/max_user_watches sudo sysctl -w fs.inotify.max_user_instances=10000 sudo sysctl -w fs.inotify.max_user_watches=640000

Sobre o Ubuntu

Para começar a atualização do Ubuntu do sistema, primeiro precisamos atualizar a lista de índice de pacotes. Abra o terminal e digite:

sudo apt update

Podemos instalar a atualização para todos os pacotes de uma só vez: A forma a seguir vai atualizar todas as versões dos pacotes instalados, sem remover pacotes.

sudo apt upgrade

Tudo feito. Seu sistema Ubuntu agora está totalmente atualizado.

Durante a atualização inicial do sistema, alguns dos pacotes podem se tornar obsoletos e, portanto, não são mais necessários. Para remover todos os pacotes desnecessários, execute:

sudo apt autoremove

Para analise do Kernel

dmesg

Para analise da Bios

sudo dmidecode -t bios

UFW ( Uncomplicated Firewall ) é um firewall padrão no Ubuntu 18.04 Bionic Beaver Linux.

Por padrão, o UFW está desativado. Você pode verificar o status do seu firewall executando o seguinte comando:

sudo ufw status

Para habilitar a execução do firewall:

sudo ufw enable

Sincronia entre maquinas locais

rsync --archive --compress --verbose --progress /home/marcio/dados/downloads/ [email protected]:/home/marcio/dados/downloads/

Conectar ao SSH “Secure SHell”

Download via SCP “Secure Copy”

scp -r [email protected]:/home/marcio/Imagens/ /home/marcio/Imagens/

Upload via SCP “Secure Copy”

scp -r /home/marcio/Imagens/ [email protected]:/home/marcio/Imagens/

Como criar a SSH Key

ssh-keygen -t rsa

Como obter a SSH Key

cat ~/.ssh/id_rsa.pub

Efetuar login no SSH com chave ppk

https://askubuntu.com/questions/818929/login-ssh-with-ppk-file-on-ubuntu-terminal

sudo apt-get install putty-tools

puttygen yourkey.ppk -O private-openssh -o yourkey.pem

chmod 400 yourkey.pem

ssh -i yourkey.pem [email protected]

Conectar via SFTP pelo nautilus

Conectar via Samba pelo nautilus

smb://192.168.0.4

Conectar via ssh pelo terminal

Obter a versão do PHP via terminal

php -r \@phpinfo\(\)\; | grep 'PHP Version' -m 1

php -i | grep 'PHP Version' -m 1

Execução comando condicional em linha

sh -c 'if [ "$TRAVIS_PHP_VERSION" = "5.4" ] || [ "$TRAVIS_PHP_VERSION" = "5.5" ]; then echo '0'; else echo '1'; fi;'

Webserver

  # https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-on-ubuntu-18-04-lamp/
  # https://hostadvice.com/how-to/how-to-setup-varnish-http-cache-on-an-ubuntu-18-04-vps-or-dedicated-server/
  # https://e-tinet.com/linux/servidor-apache/
  # https://serverfault.com/questions/904065/switch-apache-from-prefork-to-event-in-ubuntu-16-get-php-7-working

sudo apt install \
libmcrypt-dev \
mysql-client \
mysql-server \
php-apcu \
php-dev \
php-gettext \
php-imagick \
php-memcache \
php-pear \
php7.2 \
php7.2-bcmath \
php7.2-cgi \
php7.2-common \
php7.2-curl \
php7.2-fpm \
php7.2-gd \
php7.2-imap \
php7.2-intl \
php7.2-json \
php7.2-mbstring \
php7.2-mysql \
php7.2-opcache \
php7.2-pspell \
php7.2-recode \
php7.2-soap \
php7.2-sqlite3 \
php7.2-tidy \
php7.2-xmlrpc \
php7.2-xsl \
php7.2-zip \
phpmyadmin

sudo pecl channel-update pecl.php.net
pecl search mcrypt
sudo pecl install mcrypt-1.0.2

sudo nano /etc/php/7.2/fpm/php.ini
    extension=mcrypt.so
sudo nano /etc/php/7.2/cli/php.ini
    extension=mcrypt.so

sudo a2dismod mpm_prefork # This disables the prefork MPM. Only one MPM can run at a time.
sudo a2enmod mpm_event # Enable event MPM. You could also enable mpm_worker.
sudo a2enmod headers # FIX: Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration
sudo a2enmod proxy_fcgi setenvif actions rewrite ssl http2
sudo a2ensite default-ssl
sudo a2enconf php7.2-fpm

sudo nano /etc/apache2/sites-available/000-default.conf

<Directory "/var/www/html">
	AllowOverride All
</Directory>

sudo nano /etc/apache2/sites-enabled/000-default.conf

    # add into <VirtualHost> - </VirtualHost>

<FilesMatch "\.php$">
SetHandler "proxy:fcgi://127.0.0.1:9000/"
</FilesMatch>

sudo nano /etc/php/7.2/fpm/pool.d/www.conf

    # line 36: search "listen ="

    listen = 127.0.0.1:9000

Em seguida executei as instruções “Restart: apache & php-fpm”

sudo service apache2 restart
sudo service php7.2-fpm restart

FIX: Apache - Acesso aos arquivos de log

# 1. Add your user to the www-data group.
sudo usermod -aG www-data $USER

Symlink WWW

sudo ln -s ~/dados/mount/www/localhost/htdocs /var/www/html

URL

http://localhost/htdocs/

http://localhost/phpmyadmin/
phpmyadmin / senha

  #1698 - Access denied for user 'root'@'localhost'
  sudo mysql -u root
      SELECT User FROM mysql.user;
      ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'nova senha';

To activate the new configuration, you need to run:

sudo systemctl restart apache2

FIX: Apache

# No Magento2 no processo de instalação é exibido o retorno

# "$HTTP_RAW_POST_DATA is deprecated from PHP 7.2 onwards and will stop the installer from running. Please open your php.ini file and set always_populate_raw_post_data to -1.", pesquise por ";always_populate_raw_post_data = -1" e retire o comentário ";"

    sudo nano /etc/php/7.2/fpm/php.ini

# Atualize para

    display_errors = On
    max_input_vars = 2000
    memory_limit = 2048M
    zlib.output_compression = On
    max_execution_time = 90

# Algumas mudanças que que vai ajudar a fazer o seu servidor apache um pouco mais eficiente

    sudo nano /etc/apache2/apache2.conf

# Atualize "Timeout 300" para "Timeout 600"

# Atualize "KeepAliveTimeout 5" para "KeepAliveTimeout 2"

FIX: pdo_mysql extension is not installed

sudo phpenmod pdo_mysql

#sudo phpdismod pdo_mysql

Restart: apache & php-fpm

apache2 -v
sudo apache2ctl configtest
sudo apachectl fullstatus
sudo apachectl -M
sudo apachectl -V
sudo service mysql status
sudo service php7.2-fpm status
service --status-all
sudo service apache2 restart
sudo service php7.2-fpm restart

Versions

mysql --version
apache2 -v
php -v

Composer

https://getcomposer.org/download/

https://getcomposer.org/doc/00-intro.md#locally

    curl -sS https://getcomposer.org/installer | php

## FIX: https://getcomposer.org/doc/00-intro.md#globally

    sudo mv composer.phar /usr/local/bin/composer

## FIX: [RuntimeException] /home/???/.composer/cache/vcs does not exist and could not be created.
## Cannot create cache directory /home/???/.composer/cache/repo/https---packagist.org/, or directory is not writable. Proceeding without cache
##  [RuntimeException] Can not clone [email protected]:???/???.git to access package information. The "/home/???/.composer/cache/vcs " directory is not writable by the current user.
## FIX: https://github.com/thomaszbz/native-dockerfiles-typo3/issues/19

    sudo chown -R $USER $HOME/.composer

How to check if php-fpm is running

php-fpm --test
php-fpm

ps aux | grep php-fpm

netstat -lntp

Monitorando Apache

Visualizar erros do servidor

No terminal pode ser o comando para a visualização do log de erro do servidor

tail -f /var/log/apache2/error.log

to see which group the current user belongs to:

groups groups marcio

to list the group members along with their GIDs.

id $USER

Monitorando MySQL

Na necessidade de acessar o MySQL Client e ver os processos

mysql -h 'localhost' -u root -p

show processlist;

ou melhor ainda

mysqladmin -u root -p -i 1 processlist