Skip to content

Instantly share code, notes, and snippets.

@igoralves1
Last active September 8, 2016 17:31
Show Gist options
  • Save igoralves1/eda8e0f2692e04d633effa833ae36e32 to your computer and use it in GitHub Desktop.
Save igoralves1/eda8e0f2692e04d633effa833ae36e32 to your computer and use it in GitHub Desktop.
LEMP - Stack
***********************************************************************************************
{Linux + NginX + MariaDb + PHP7}
***********************************************************************************************
************************ # ####### ## ## ####### ************************
************************ # # # # # # # # ************************
************************ # ####### # # # # ####### ************************
************************ # # # # # # # ************************
************************ ####### ####### # # # # ************************
***********************************************************************************************
by igoralves1
***********************************************************************************************
How to configure a LEMP (Linux + NginX + MariaDB + PHP7) environment for developers.
Use UBUNTU 16.04. The 16.04.1 version trow error. http://releases.ubuntu.com/16.04/
IN THIS FILE:
1 - Some commands
2 - Install tree
3 - Install virtualbox-guest (If it is a virtual Machine)
4 - Sharing Folder (If it is a virtual Machine)
5 - Install google-chrome
6 - Install sublime-text-3
7 - Install Server - NginX
8 - Install PHP 7.0
9 - Install GIT
10 - Install NodeJS
11 - Install Bower/Gulp
12 - Install Composer
13 - Install Java
14 - Install NetBeans
15 - Install MySql Wworkbench
16 - Install MariaDB
17 - Install Xdebug
18 - Install Laravel
---------------------------------------------------------------------------------------------------------------------------
###########################################################################################################################
###################################### 1 - Update apt-get #####################################################
###########################################################################################################################
sudo su #MyPassword#
apt-get update
//Comands to work with apt-get
apt-get list => See all availiable softwares in apt-get
apt-get search php => Display all softwares related to "php", for example.
apt-get help
//Clear the screen
clear
//Switch between root and user
ctrl+d
//Running .sh file
//Give the .sh file permission to execute.
chmod +x file.sh
//then execute it with
./file.sh.
//Or right-click on the file, select Properties, then select Permissions and then select 'Allow executing file as program'.
//Then double-click the file and select 'Run in Terminal' or 'Run'.
//Move files from dir1 to dir2
mv dir1/ dir2/
//Or put yourself inside dir1
mv .* ../dir2/
//Copy files ====> http://askubuntu.com/questions/35779/what-does-cp-omitting-directory-mean
By default, cp copies only the direct files in, and not subdirectories in the directory. The message
"cp: omitting directory 'directory' " warns you that the mentioned directory is not copied.
sudo cp -R dir1 dir2 //That will copy content from dir1 to dir2
###########################################################################################################################
########################################### END Update apt-get #########################################################
###########################################################################################################################
---------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------
###########################################################################################################################
####################################### 2 - Install tree #####################################################
###########################################################################################################################
apt-get install tree =>http://mama.indstate.edu/users/ice/tree/
###########################################################################################################################
############################################ END Install tree ##########################################################
###########################################################################################################################
---------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------
###########################################################################################################################
##################################### 3 - virtualbox-guest ####################################################
###########################################################################################################################
apt-get install virtualbox-guest-dkms //Yes para todas opções
###########################################################################################################################
########################################## END virtualbox-guest ########################################################
###########################################################################################################################
---------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------
###########################################################################################################################
###################################### 4 - Sharing Folder #####################################################
###########################################################################################################################
1 - Install the virtualbox-guest-dkms is important to enable Linux (guest) to share folders with windows7/10 (host).
2 - Need to create and share a file inside the host Win7.
3 - Need to set (point) to the shared folder inside the VirtualMachine, VirtualBox tools - Shared Folders.
4 - At this poist, Linux (guest) is allowed to see the shared folder in Win7(host), but not aceess it.
When we try to get access to this page, we get a error: "You do not have permission necessary to view the content
of `yourSharedFolderName` ". So we need to make the user to have the permission. To do this we need to make the user
that will get access to the folder, part og the group "vboxsf".
5 - Check all groups the user is part of
groups username
6 - We will see that the user is not part of vboxsf group
7 - Make it part of this group
sudo usermod -aG vboxsf username
8 - Now check again
groups username
5 - Now the user is part of the group "vboxsf" that has permission to open any shared folder in Guest-Host VirtualBox
6 - Restart Linux
//Note: Not tested, but sharing folder between fisical machines and when there is no virtual machine associated.
//Use samba ?
apt-get update
apt-get install samba
###########################################################################################################################
###################################### End Sharing Folder #####################################################
###########################################################################################################################
---------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------
###########################################################################################################################
####################################### 5 - google-chrome #####################################################
###########################################################################################################################
//Fonte http://www.ubuntuupdates.org/ppa/google_chrome
//http://askubuntu.com/questions/79280/how-to-install-chrome-browser-properly-via-command-line
//Note: must insert line by line. Avoid copy and past all.
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
sh -c 'echo "deb https://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
apt-get update
apt-get install google-chrome-stable
###########################################################################################################################
######################################### END google-chrome #######################################################
###########################################################################################################################
---------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------
###########################################################################################################################
####################################### 6 - sublime-text-3 ####################################################
###########################################################################################################################
add-apt-repository ppa:webupd8team/sublime-text-3
apt-get update
apt-get install sublime-text-installer
##NOTE - IF NOT WORKS do not use "apt-get" USE "apt"
Install Themes: ****************
#To install themes follow this site -> https://scotch.io/bar-talk/best-sublime-text-3-themes-of-2015-and-2016
#To install themes, just use package control. So the process would be:
#The simplest method of installation is through the Sublime Text console. The console is accessed via the ctrl+` shortcut
#or the View > Show Console menu. Once open, paste the appropriate Python code for your version of Sublime Text into the
#console.
#To Sublime text 3:
#Put the follow text inside the console and hit ENTER
import urllib.request,os,hashlib; h = '2915d1851351e5ee549c20394736b442' + '8bc59f460fa1548d1514676163dafc88';
pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path();
urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) );
by = urllib.request.urlopen( 'http://packagecontrol.io/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest();
print('Error validating download (got %s instead of %s), please try manual install' % (dh, h)) if dh != h else open(os.path.join( ipp, pf), 'wb' ).write(by)
This code creates the Installed Packages folder for you (if necessary), and then downloads the Package Control.sublime-package into
it. The download will be done over HTTP instead of HTTPS due to Python standard library limitations, however the file will be
validated using SHA-256.
WARNING: Please do not redistribute the install code via another website. It will change with every release.
Instead, please link to this page. ==> https://packagecontrol.io/installation
#https://scotch.io/bar-talk/best-sublime-text-3-themes-of-2015-and-2016
1-ctrl + shift + p or cmd + shift + p
2-Look for Package Control: Install Package
3-Search for the theme and hit enter => See Material Theme on Package Control
4-Set the theme in Preferences -> Settings – User by editing the json property called theme
Material Theme
{
// Default theme
"theme": "Material-Theme.sublime-theme",
"color_scheme": "Packages/Material Theme/schemes/Material-Theme.tmTheme"
}
#More THEMES ===> https://scotch.io/bar-talk/best-sublime-text-3-themes-of-2015-and-2016
https://packagecontrol.io/installation#st3
https://packagecontrol.io/installation#st2
###########################################################################################################################
######################################### END sublime-text-3 ######################################################
###########################################################################################################################
---------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------
###########################################################################################################################
####################################### 7 - Server - NginX ####################################################
###########################################################################################################################
NginX + PHP ==> https://www.howtoforge.com/tutorial/installing-nginx-with-php-fpm-and-mariadb-lemp-on-debian-jessie/
NginX ==> https://help.dreamhost.com/hc/en-us/search?utf8=%E2%9C%93&query=nginx
==> https://help.dreamhost.com/hc/en-us/articles/216455077-Nginx-configuration-file-locations
==> https://help.dreamhost.com/hc/en-us/articles/214200688-php-ini-overview
==> https://help.dreamhost.com/hc/en-us/articles/215833158-PHP-with-Nginx-at-DreamHost
Why NginX? ==> https://help.dreamhost.com/hc/en-us/articles/215945987-Web-server-performance-comparison
==> https://help.dreamhost.com/hc/en-us/articles/216431827-Nginx-overview
==> https://www.linkedin.com/pulse/node-vs-apache-lighttpd-nginx-jeff-poyzner
lighttpd ==> https://www.lighttpd.net/
1 - Type URL: 127.0.0.1 //Note that there is no server that replies this request. So The systems has no server installed.
apt-get update
apt-get install nginx
2 - Test again, and note the "Welcome to nginx!" message.
3 - The server is installed
//Note to be cleaned
criar a pasta vhosts dentro de home e criar links dentro de www direcionando para vhosts em home/ig.
apt update
apt install nginx OU apt install apache2 => vai instalar nginx 1.10.0 OU apache 2.4.18 para XENIAL.
//Test in the browser: 127.0.0.1
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
Nota: Para o nginx seguir o tutorial de instalação do vedovelli. Apos terminar o tutorial e receber uma mensagem de erro 502 Bad
Gateway devemos checar o log do enginx no path /var/log/nginx/o_seu_site_name.com. Geralmente o nginx não está localizando o
php5-fpm.sock ou php7.0-fpm.sock.
Resolver provendo o path correto ate o -fpm.sock. Nesse caso o php7.0-fpm.sock que esta localizado em /var/run/php5-fpm.sock; Esse
caminho deve ser colocado no arquivo de configuracao do site dentro da pasta "/etc/nginx/sites-available/". Dentro dessa pasta, no
arquivo chm.com.conf edite fastcgi_pass unix:/var/run/php5-fpm.sock; ==> para fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
Seguir com o tutorial de vedovelli e
http://pt.stackoverflow.com/questions/139098/502-bad -gateway-linux-php7-nginx-como-resolver-esse-erro
Nota: O arquivo que o nGinx procura estará dentro da pasta de sistema var/www. Devemos criar uma pasta vhost dentro de home/ig sem
privilégios de sudo. Devemos ir dentro de www ("igoralves1@ig:/var/www$ sudo ln -s ~/vhosts") e criar um link simbolico para a pasta
vhost em /home/ig. Se após esses passos a pagina nao abrir, verificar as permissoes e usuários das pastas.
A abordagem correta seria mudar o proprietario da pasta vhost para o mesmo que usa o nginx. NADA DE MUDAR para chmod 777.
apt update
###########################################################################################################################
######################################### End Server - NginX ######################################################
###########################################################################################################################
---------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------
###########################################################################################################################
####################################### 7 - Server - Apache ####################################################
###########################################################################################################################
sudo apt-get update
sudo apt-get install apache2
###########################################################################################################################
######################################### End Server - NginX ######################################################
###########################################################################################################################
---------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------
###########################################################################################################################
########################################### 8 - PHP 7.0 #######################################################
###########################################################################################################################
#About the error - https://laracasts.com/discuss/channels/forge/error-while-updating-to-php-70-on-forge
# http://php.net/manual/en/mcrypt.installation.php
sudo apt-get update
sudo apt-get install mcrypt php7.0-mcrypt
sudo apt-get upgrade
sudo apt-get install php-mbstring
sudo apt-get install phpunit
apt install php //Vai instalar php7 para XENIAL
apt install php //Install php 7 and others dependencies, like php-fpm. testar php-all-dev php7.0-dev
apt install php7.0
apt install php7.0-cgi
apt install php7.0-fpm
apt install php7.0-mcrypt
apt install php7.0-mbstring
apt install php7.0-mysql
apt install php7.0-curl
apt install php7.0-json
apt install php7.0-xsl //To be used by Magento
apt install php7.0-intl //To be used by Magento
apt install php7.0 libapache2-mod-php7(if apache is the server)
Test your php version
root@ubuntu:~# php -v
PHP 7.0.3-3 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
NOTE: If you want to install all php modules at once, enter the command sudo apt-get install php* and restart the apache2 service. To
verify the modules, open web browser and navigate to http://server-ip-address/testphp.php. You will able to see all installed php
modules.
NOTE: IF SERVER IS NGINX ==> To make php enabled to work with nginx must to change 1 parameter inside the php.ini file.
Go to "etc/ph/ ..." (For some instalations the php.ini will be find here at "etc/php/...". But for this instalation of php7.0 trough
apt install in 2016, the php.ini is located in "etc/php/7.0/cgi/php.ini"), and search for "cgi.fix_pathinfo". The dafault value should
be ";cgi.fix_pathinfo=0". Note that it is commented. To allow php works properlly with NGINX we must uncomment and change the value to
1, like this "cgi.fix_pathinfo=1". Note that it is uncommented now. This is the only configuration to be done in php.
NOTE: there is a php.ini file inside cgi/php.ini AND fpm/php.ini.
To test the PHP working with NGINX must to create a phpinfo() inside the host. The hosts file lives inside "etc/" folder in 99% of the
instalations.
1-Go to the host using sudo su subl hosts.
2-Create a line to the new project. In this case the project name is "chm.com". Creates the follow line => "27.0.1.1 chm.com"
3-Navigate to home/username (in this case "/home/igoralves1/") and create a new folder, called "vhosts"
4-The folder "vhosts" will hold all sites project folder. So go inside "vhosts" and create a new folder. This folder will have the
same project's name. In this case "chm.com". Note: Inside this folder I will create a public folder. Because I will install Laravel
and the server should point to public folder within a Laravel project. So the final path we must to provide to NGINX should be:
"/home/igoralves1/vhosts/chm.com/public".
5-Navegate to nginx folder.
6-Dentro do folder nginx navegar ate "sites-available" folder.
7-Dentro de "sites-available" folder criar um arquivo com o nome do site: "subl chm.com.conf"
8-Dentro de "sites-available/chm.com" colar o seguinte codigo de configuracao do servidor nginx:
//https://gist.github.com/vedovelli/a50fdd9c9b745b61407a
server {
listen 80;
server_name chm.com;
root /var/www/vhosts/chm.com/public;
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/chm.com-error.log error;
error_page 404 /index.php;
sendfile off;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
}
location ~ /\.ht {
deny all;
}
}
9-Atention: Only the line 120, 121, 135 will be edited to the new project name.
9.1 - NOTE: the line 143 should point to the correct folder that stores the fpm sock. I this project I had to change fastcgi_pass
unix:/var/run/php5-fpm.sock; ==> to fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
10 - Ir dentro de "/etc/nginx/sites-enabled" e criar um link simbolico apontando para o arquivo do projeto "chm.com.conf" criado em
"sites-available". Usar o link sibolico: "ln -s ../sites-available/chm.com.conf". At the end, we will have a link inside
"/etc/nginx/sites-enabled" that points to "sites-available/chm.com.conf".
11 - In resume: when user type chm.com inside URL, the browser will send a call to the server nginx. The server will look to what it
has inside "/etc/nginx/sites-enabled" that call "chm.com". It will find a link "chm.com.conf" that points to
"/sites-available/chm.com.conf". Inside this file NGINX will see that the request should go to "root /var/www/vhosts/chm.com/public"
and return the index.php that lives there.
12-Because we applied chages in nginx server and inside the php.ini, we must restart the NGINX server and the php fast cgi. Use this
follow code to restart the service: "service nginx restart" and "service php7.0-fpm restart"
13-If is there some error, bad getway go to /var/log/nginx/chm.com-error.log.
14-Go to /var/www/ and create a link that point to ~/vhosts/. Use this code: "igoralves1@ig:/var/www$ sudo ln -s ~/vhosts". Notar que
o link dentro de www deve ser criado com sudo privilegios, e a pasta vhost dentro de home sem sudo.
15-At this point we should be abble to see the phpinfo(); that comes from "/home/igoralves1/vhosts/chm.com/public/index.php".
###########################################################################################################################
############################################# End PHP 7.0 #########################################################
###########################################################################################################################
---------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------
###########################################################################################################################
############################################# 9 - GIT #########################################################
###########################################################################################################################
apt install git
apt install gitk
apt install git-gui
Show your branch name on the Linux prompt. => https://www.leaseweb.com/labs/2013/08/git-tip-show-your-branch-name-on-the-linux-prompt/
1-Go to ~/ directory, or /home/"username";
2-type sudo subl .bashrc. So this will be the full command ila@ig:~$ sudo subl .bashrc. That will open the .bashrc file
3-After this Introductory sentence of the .bashrc:
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
4-Put this function declaration:
# Add git branch if its present to PS1
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
5-Find this portion of the code:
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt
6-And change for this:
if [ "$color_prompt" = yes ]; then
#PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' #Igor put in comment
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\]$(parse_git_branch)\[\033[00m\]\$ ' #Igor added this line
else
#PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' #Igor put in comment
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(parse_git_branch)\$ ' #Igor added this line
fi
unset color_prompt force_color_prompt
7-GO to the master directory, make a `$git add .` and `$git commit -m "The first commit"` IF IT WAS NOT DONE BEFORE.
THE SHELL WILL BE ABLE TO SEE THE BRANCH NAME JUST AFTER THE FIRST COMMIT WAS DONE.
At the end of this process you will have a colored shell with the git branch name.
###########################################################################################################################
############################################### End GIT ###########################################################
###########################################################################################################################
---------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------
###########################################################################################################################
########################################### 10 - NodeJS #######################################################
###########################################################################################################################
apt-get install nodejs
nodejs -v //check version today's version is v4.2.6
Nota: para chamarmos o programa nodejs precisamos chamar nodejs. POdemos criar uma laias "node" para chamar o "nodejs"
Para isso precismaos ir para o diretorio "usr/bin" ONDE ESTA INSTALADO TODOS OS PROGRAMAS EXECUTAVEIS DO LINUX e se
quiser criar uma alias para chamar o "nodejs" como "node" basta fazer "ln - snodejs node".
Agora ja podemos chamar o nodejs como node somente.
###########################################################################################################################
############################################## End NodeJS #########################################################
###########################################################################################################################
---------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------
###########################################################################################################################
######################################## 11 - Bower/Gulp ######################################################
###########################################################################################################################
//To install bower gulp grant we should use npm. So lets install npm...
apt install npm
npm -v //check version today's version is v3.5.2
npm install -g bower
npm install -g gulp
//Test
gulp -v //Display CLI version 3.9.1
bower -v //1.7.9
###########################################################################################################################
########################################### End Bower/Gulp ########################################################
###########################################################################################################################
---------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------
###########################################################################################################################
########################################## 12 - Composer ######################################################
###########################################################################################################################
//https://getcomposer.org/download/
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') ===
'e115a8dc7871f15d853148a7fbac7da27d6c0030b848d9b3dc09e2a0388afed865e6a3d6b3c0fad45c48e2b5fc1196ae') { echo 'Installer verified'; }
else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
NOTA: Ao final desse processo teremos um arquivo o composer.phar dentro da pasta onde estamos. No caso, na home.
POdemos rodar o arquivo com o seguinte comando: "./composer.phar".
Mas devemos colocar o arquivo numa pasta de acesso global para que o composer possa ser chamado de dentro de qualquer diretorio.
Para isso devemos digitar: "mv composer.phar /usr/bin/composer", que alem de moer o composer.phar para o diretorio usr/bin ira
renomea-lo para composer. Entao podereos chamar compose de quanquer diretorio somente com o cdigo "composer"
//Testando, de dentro de qualquer pasta digitar "composer". A tela do composer devera aparecer.
###########################################################################################################################
############################################ End Composer #########################################################
###########################################################################################################################
---------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------
###########################################################################################################################
############################################ 13 - Java ########################################################
###########################################################################################################################
add-apt-repository ppa:webupd8team/java ==> add webupd8team Java PPA repository in the system
apt-get update
apt install oracle-java8-installer
OR
//Install java sdk to ubuntu
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
sudo update-java-alternatives -s java-7-oracle
http://askubuntu.com/questions/183867/how-do-i-update-oracle-java-7-jdk-and-jre
###########################################################################################################################
############################################### End Java ##########################################################
###########################################################################################################################
---------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------
###########################################################################################################################
########################################## 14 - NetBeans ######################################################
###########################################################################################################################
//Install only java version. Must download the correct version from netbenas site and install it. Run sh. files
apt-get install netbeans
###########################################################################################################################
############################################ End NetBeans #########################################################
###########################################################################################################################
---------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------
###########################################################################################################################
##################################### 15 - MySql Wworkbench ###################################################
###########################################################################################################################
apt-get install mysql-workbench //(launch from command line mysql-workbench) no shortcut is added to the toolbar
###########################################################################################################################
######################################### End MySql Wworkbench #####################################################
###########################################################################################################################
---------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------
###########################################################################################################################
########################################### 16 - MariaDB ######################################################
###########################################################################################################################
#Install MariaDB
MariaDB is a drop in replacement for MySQL. It is a robust, scalable and reliable SQL server that comes rich set of enhancements.
First you have to remove existing MySQL packages if any. To completely uninstall MySQL along with its configuration files, enter the
following commands one by one:
systemctl stop mysql
apt-get remove --purge mysql-server mysql-client mysql-common
apt-get autoremove
apt-get autoclean
rm -rf /var/lib/mysql/
rm -rf /etc/mysql/
After removing MySQL, run the following command to install MariaDB.
sudo apt-get install mariadb-server
Alternatively, you can install it using MariaDB repository if you want to try most recent version of MariaDB. Run the following
commands to add PPA. As of writing this, MariaDB PPA is not yet updated to Ubuntu 16.04. However, we can use the repository of Ubuntu
15.10 instead.
sudo apt-get install software-properties-common
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
sudo add-apt-repository 'deb http://download.nus.edu.sg/mirror/mariadb/repo/10.1/ubuntu vivid main'
Update the software sources list and install MariaDB using following commands:
sudo apt-get update
sudo apt-get install mariadb-server
During installation you will be asked to set mysql ‘root’ user password. Enter the password twice, and complete the installation.
At this poin we can get access at MariaDB only typing mysql in the terminal, or sudo mysql if we are logged as no root.
Because MariaDB has a defaul user with root privileges, without password. This is why it is a good practice to create a root
user for ourelf.
Important Note: In Ubuntu 16.04/15.10/15.04, MariaDB won’t ask you to set root user password during installation.
//So it should be agood practice to create a new user inside MariaDB with root privileges.
//Give it the same name and password for admin user in Linus. In this example "ila".
//http://stackoverflow.com/questions/5016505/mysql-grant-all-privileges-on-database
FLUSH PRIVILEGES;
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';
//Set secure instalation to MariaDB->Same as MySql
//See vedovelli 7:23 https://www.youtube.com/watch?v=Q2N5blJ4VIo&list=PL1C87CCACA68A94A3&index=60
mysql_secure_installation
http://www.techonthenet.com/mariadb/users/create_user.php
https://mariadb.com/kb/en/mariadb/mysql_secure_installation/
http://dba.stackexchange.com/questions/51452/how-do-you-disable-anonymous-login-mysql
http://stackoverflow.com/questions/7179894/how-to-disable-mysql-root-logins-when-no-password-is-supplied
http://www.linuxveda.com/2015/06/17/install-mysql-mariadb-secure-configure/
https://github.com/wnmp/wnmp
https://www.google.ca/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=anonymous+user+mariadb
http://stackoverflow.com/questions/1135245/how-to-get-a-list-of-mysql-user-accounts
http://dba.stackexchange.com/questions/116937/cannot-connect-to-mariadb-mysql-in-manjaro-linux
https://www.google.ca/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=create+user+with+password+mariadb
https://mariadb.com/kb/en/mariadb/set-password/
https://www.google.ca/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=create+user+with+password+mariadb
NOTE:
//If want to Install MySql Server
apt install mysql-server
###########################################################################################################################
############################################# End MariaDB #########################################################
###########################################################################################################################
---------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------
###########################################################################################################################
########################################### 17 - Xdegub #######################################################
###########################################################################################################################
Follow the steps to install xdebug to php and make it running with xdebug
Note: Must run sudo phpizi
1 - Go to https://xdebug.org/wizard.php
2 - Copy and paste the contenct of phpinfo(); inside the correct place
3 - Wizzard will give some instructions and a file to download. The follow is an example
1 - Download xdebug-2.4.1.tgz
2 - Unpack the downloaded file with tar -xvzf xdebug-2.4.1.tgz
3 - Run: cd xdebug-2.4.1
4 - Run: phpize (See the FAQ if you don't have phpize.
As part of its output it should show:
Configuring for:
...
Zend Module Api No: 20151012
Zend Extension Api No: 320151012
If it does not, you are using the wrong phpize. Please follow this FAQ entry and skip the next step.
5 - Run: ./configure
6 - Run: make
7 - Run: cp modules/xdebug.so /usr/lib/php/20151012
8 - Update /etc/php/7.0/fpm/php.ini and change the line
9 - zend_extension = /usr/lib/php/20151012/xdebug.so
10 - Add the follow code to the php.ini file
;This part makes the connection between the php and Netbeans
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000
;This part is the debugger itself. That was a file for the linux instalation
zend_extension = /usr/lib/php/20151012/xdebug.so
4 - Restart the webserver ==> service nginx restart
5 - Restart the php-fpm ==> service php7.0-fpm restart
###########################################################################################################################
############################################## End Xdegub #########################################################
###########################################################################################################################
---------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------
###########################################################################################################################
########################################### 18 - Laravel ######################################################
###########################################################################################################################
Once Composer is installed, and the environment is ready, we have all that we need to run install and run Laravel
1 - Go to vhost/ directory
2 - type:
composer create-project laravel/laravel --prefer-dist theFileName
3 - If we try to run URL: http://theFileName.com we will have an error.
Note: Need to change the owner of theFileName folder. It is the root of the project.
Nginx runs under www-data group. So we need to change the theFileName ownership.
chown -R ila:www-data theFileName.
This code will set theFileName ownership to ila and the group www-data, same as NginX.
###########################################################################################################################
############################################# End Laravel #########################################################
###########################################################################################################################
---------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------
###########################################################################################################################
###########################################################################################################################
###########################################################################################################################
###########################################################################################################################
Some customization and alias... http://www.cyberciti.biz/tips/bash-aliases-mac-centos-linux-unix.html
Task: Define / create an alias (bash syntax)
To create the alias use the following syntax:
alias name=value
alias name='command'
alias name='command arg1 arg2'
alias name='/path/to/script'
alias name='/path/to/script.pl arg1'
In this example, create the alias c for the commonly used clear command, which clears the screen, by typing the following command and then pressing the ENTER key:
alias c='clear'
Then, to clear the screen, instead of typing clear, you would only have to type the letter ‘c’ and press the [ENTER] key:
c
Task: Disable an alias temporarily (bash syntax)
An alias can be disabled temporarily using the following syntax:
## path/to/full/command
/usr/bin/clear
## call alias with a backslash ##
\c
Task: Remove an alias (bash syntax)
You need to use the command called unalias to remove aliases. Its syntax is as follows:
unalias aliasname
In this example, remove the alias c which was created in an earlier example:
unalias c
You also need to delete the alias from the ~/.bashrc file using a text editor (see next section).
Task: Make aliases permanent (bash syntax)
The alias c remains in effect only during the current login session. Once you logs out or reboot the system the alias c will be gone. To avoid this problem, add alias to your ~/.bashrc file, enter:
vi ~/.bashrc
The alias c for the current user can be made permanent by entering the following line:
alias c='clear'
Save and close the file. System-wide aliases (i.e. aliases for all users) can be put in the /etc/bashrc file. Please note that the alias command is built into a various shells including ksh, tcsh/csh, ash, bash and others.
A note about privileged access
You can add code as follows in ~/.bashrc:
# if user is not root, pass all commands via sudo #
if [ $UID -ne 0 ]; then
alias reboot='sudo reboot'
alias update='sudo apt-get upgrade'
fi
A note about os specific aliases
You can add code as follows in ~/.bashrc using the case statement:
### Get os name via uname ###
_myos="$(uname)"
### add alias as per os using $_myos ###
case $_myos in
Linux) alias foo='/path/to/linux/bin/foo';;
FreeBSD|OpenBSD) alias foo='/path/to/bsd/bin/foo' ;;
SunOS) alias foo='/path/to/sunos/bin/foo' ;;
*) ;;
esac
30 uses for aliases
You can define various types aliases as follows to save time and increase productivity.
#1: Control ls command output
The ls command lists directory contents and you can colorize the output:
## Colorize the ls output ##
alias ls='ls --color=auto'
## Use a long listing format ##
alias ll='ls -la'
## Show hidden files ##
alias l.='ls -d .* --color=auto'
#2: Control cd command behavior
## get rid of command not found ##
alias cd..='cd ..'
## a quick way to get out of current directory ##
alias ..='cd ..'
alias ...='cd ../../../'
alias ....='cd ../../../../'
alias .....='cd ../../../../'
alias .4='cd ../../../../'
alias .5='cd ../../../../..'
#3: Control grep command output
grep command is a command-line utility for searching plain-text files for lines matching a regular expression:
## Colorize the grep command output for ease of use (good for log files)##
alias grep='grep --color=auto'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
#4: Start calculator with math support
alias bc='bc -l'
#4: Generate sha1 digest
alias sha1='openssl sha1'
#5: Create parent directories on demand
mkdir command is used to create a directory:
alias mkdir='mkdir -pv'
#6: Colorize diff output
You can compare files line by line using diff and use a tool called colordiff to colorize diff output:
# install colordiff package :)
alias diff='colordiff'
#7: Make mount command output pretty and human readable format
alias mount='mount |column -t'
#8: Command short cuts to save time
# handy short cuts #
alias h='history'
alias j='jobs -l'
#9: Create a new set of commands
alias path='echo -e ${PATH//:/\\n}'
alias now='date +"%T"'
alias nowtime=now
alias nowdate='date +"%d-%m-%Y"'
#10: Set vim as default
alias vi=vim
alias svi='sudo vi'
alias vis='vim "+set si"'
alias edit='vim'
#11: Control output of networking tool called ping
# Stop after sending count ECHO_REQUEST packets #
alias ping='ping -c 5'
# Do not wait interval 1 second, go fast #
alias fastping='ping -c 100 -s.2'
#12: Show open ports
Use netstat command to quickly list all TCP/UDP port on the server:
alias ports='netstat -tulanp'
#13: Wakeup sleeping servers
Wake-on-LAN (WOL) is an Ethernet networking standard that allows a server to be turned on by a network message. You can quickly wakeup nas devices and server using the following aliases:
## replace mac with your actual server mac address #
alias wakeupnas01='/usr/bin/wakeonlan 00:11:32:11:15:FC'
alias wakeupnas02='/usr/bin/wakeonlan 00:11:32:11:15:FD'
alias wakeupnas03='/usr/bin/wakeonlan 00:11:32:11:15:FE'
#14: Control firewall (iptables) output
Netfilter is a host-based firewall for Linux operating systems. It is included as part of the Linux distribution and it is activated by default. This post list most common iptables solutions required by a new Linux user to secure his or her Linux operating system from intruders.
## shortcut for iptables and pass it via sudo#
alias ipt='sudo /sbin/iptables'
# display all rules #
alias iptlist='sudo /sbin/iptables -L -n -v --line-numbers'
alias iptlistin='sudo /sbin/iptables -L INPUT -n -v --line-numbers'
alias iptlistout='sudo /sbin/iptables -L OUTPUT -n -v --line-numbers'
alias iptlistfw='sudo /sbin/iptables -L FORWARD -n -v --line-numbers'
alias firewall=iptlist
#15: Debug web server / cdn problems with curl
# get web server headers #
alias header='curl -I'
# find out if remote server supports gzip / mod_deflate or not #
alias headerc='curl -I --compress'
#16: Add safety nets
# do not delete / or prompt if deleting more than 3 files at a time #
alias rm='rm -I --preserve-root'
# confirmation #
alias mv='mv -i'
alias cp='cp -i'
alias ln='ln -i'
# Parenting changing perms on / #
alias chown='chown --preserve-root'
alias chmod='chmod --preserve-root'
alias chgrp='chgrp --preserve-root'
#17: Update Debian Linux server
apt-get command is used for installing packages over the internet (ftp or http). You can also upgrade all packages in a single operations:
# distro specific - Debian / Ubuntu and friends #
# install with apt-get
alias apt-get="sudo apt-get"
alias updatey="sudo apt-get --yes"
# update on one command
alias update='sudo apt-get update && sudo apt-get upgrade'
#18: Update RHEL / CentOS / Fedora Linux server
yum command is a package management tool for RHEL / CentOS / Fedora Linux and friends:
## distrp specifc RHEL/CentOS ##
alias update='yum update'
alias updatey='yum -y update'
#19: Tune sudo and su
# become root #
alias root='sudo -i'
alias su='sudo -i'
#20: Pass halt/reboot via sudo
shutdown command bring the Linux / Unix system down:
# reboot / halt / poweroff
alias reboot='sudo /sbin/reboot'
alias poweroff='sudo /sbin/poweroff'
alias halt='sudo /sbin/halt'
alias shutdown='sudo /sbin/shutdown'
#21: Control web servers
# also pass it via sudo so whoever is admin can reload it without calling you #
alias nginxreload='sudo /usr/local/nginx/sbin/nginx -s reload'
alias nginxtest='sudo /usr/local/nginx/sbin/nginx -t'
alias lightyload='sudo /etc/init.d/lighttpd reload'
alias lightytest='sudo /usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf -t'
alias httpdreload='sudo /usr/sbin/apachectl -k graceful'
alias httpdtest='sudo /usr/sbin/apachectl -t && /usr/sbin/apachectl -t -D DUMP_VHOSTS'
#22: Alias into our backup stuff
# if cron fails or if you want backup on demand just run these commands #
# again pass it via sudo so whoever is in admin group can start the job #
# Backup scripts #
alias backup='sudo /home/scripts/admin/scripts/backup/wrapper.backup.sh --type local --taget /raid1/backups'
alias nasbackup='sudo /home/scripts/admin/scripts/backup/wrapper.backup.sh --type nas --target nas01'
alias s3backup='sudo /home/scripts/admin/scripts/backup/wrapper.backup.sh --type nas --target nas01 --auth /home/scripts/admin/.authdata/amazon.keys'
alias rsnapshothourly='sudo /home/scripts/admin/scripts/backup/wrapper.rsnapshot.sh --type remote --target nas03 --auth /home/scripts/admin/.authdata/ssh.keys --config /home/scripts/admin/scripts/backup/config/adsl.conf'
alias rsnapshotdaily='sudo /home/scripts/admin/scripts/backup/wrapper.rsnapshot.sh --type remote --target nas03 --auth /home/scripts/admin/.authdata/ssh.keys --config /home/scripts/admin/scripts/backup/config/adsl.conf'
alias rsnapshotweekly='sudo /home/scripts/admin/scripts/backup/wrapper.rsnapshot.sh --type remote --target nas03 --auth /home/scripts/admin/.authdata/ssh.keys --config /home/scripts/admin/scripts/backup/config/adsl.conf'
alias rsnapshotmonthly='sudo /home/scripts/admin/scripts/backup/wrapper.rsnapshot.sh --type remote --target nas03 --auth /home/scripts/admin/.authdata/ssh.keys --config /home/scripts/admin/scripts/backup/config/adsl.conf'
alias amazonbackup=s3backup
#23: Desktop specific – play avi/mp3 files on demand
## play video files in a current directory ##
# cd ~/Download/movie-name
# playavi or vlc
alias playavi='mplayer *.avi'
alias vlc='vlc *.avi'
# play all music files from the current directory #
alias playwave='for i in *.wav; do mplayer "$i"; done'
alias playogg='for i in *.ogg; do mplayer "$i"; done'
alias playmp3='for i in *.mp3; do mplayer "$i"; done'
# play files from nas devices #
alias nplaywave='for i in /nas/multimedia/wave/*.wav; do mplayer "$i"; done'
alias nplayogg='for i in /nas/multimedia/ogg/*.ogg; do mplayer "$i"; done'
alias nplaymp3='for i in /nas/multimedia/mp3/*.mp3; do mplayer "$i"; done'
# shuffle mp3/ogg etc by default #
alias music='mplayer --shuffle *'
#24: Set default interfaces for sys admin related commands
vnstat is console-based network traffic monitor. dnstop is console tool to analyze DNS traffic. tcptrack and iftop commands displays information about TCP/UDP connections it sees on a network interface and display bandwidth usage on an interface by host respectively.
## All of our servers eth1 is connected to the Internets via vlan / router etc ##
alias dnstop='dnstop -l 5 eth1'
alias vnstat='vnstat -i eth1'
alias iftop='iftop -i eth1'
alias tcpdump='tcpdump -i eth1'
alias ethtool='ethtool eth1'
# work on wlan0 by default #
# Only useful for laptop as all servers are without wireless interface
alias iwconfig='iwconfig wlan0'
#25: Get system memory, cpu usage, and gpu memory info quickly
## pass options to free ##
alias meminfo='free -m -l -t'
## get top process eating memory
alias psmem='ps auxf | sort -nr -k 4'
alias psmem10='ps auxf | sort -nr -k 4 | head -10'
## get top process eating cpu ##
alias pscpu='ps auxf | sort -nr -k 3'
alias pscpu10='ps auxf | sort -nr -k 3 | head -10'
## Get server cpu info ##
alias cpuinfo='lscpu'
## older system use /proc/cpuinfo ##
##alias cpuinfo='less /proc/cpuinfo' ##
## get GPU ram on desktop / laptop##
alias gpumeminfo='grep -i --color memory /var/log/Xorg.0.log'
#26: Control Home Router
The curl command can be used to reboot Linksys routers.
# Reboot my home Linksys WAG160N / WAG54 / WAG320 / WAG120N Router / Gateway from *nix.
alias rebootlinksys="curl -u 'admin:my-super-password' 'http://192.168.1.2/setup.cgi?todo=reboot'"
# Reboot tomato based Asus NT16 wireless bridge
alias reboottomato="ssh admin@192.168.1.1 /sbin/reboot"
#27 Resume wget by default
The GNU Wget is a free utility for non-interactive download of files from the Web. It supports HTTP, HTTPS, and FTP protocols, and it can resume downloads too:
## this one saved by butt so many times ##
alias wget='wget -c'
#28 Use different browser for testing website
## this one saved by butt so many times ##
alias ff4='/opt/firefox4/firefox'
alias ff13='/opt/firefox13/firefox'
alias chrome='/opt/google/chrome/chrome'
alias opera='/opt/opera/opera'
#default ff
alias ff=ff13
#my default browser
alias browser=chrome
#29: A note about ssh alias
Do not create ssh alias, instead use ~/.ssh/config OpenSSH SSH client configuration files. It offers more option. An example:
Host server10
Hostname 1.2.3.4
IdentityFile ~/backups/.ssh/id_dsa
user foobar
Port 30000
ForwardX11Trusted yes
TCPKeepAlive yes
You can now connect to peer1 using the following syntax:
$ ssh server10
#30: It’s your turn to share…
## set some other defaults ##
alias df='df -H'
alias du='du -ch'
# top is atop, just like vi is vim
alias top='atop'
## nfsrestart - must be root ##
## refresh nfs mount / cache etc for Apache ##
alias nfsrestart='sync && sleep 2 && /etc/init.d/httpd stop && umount netapp2:/exports/http && sleep 2 && mount -o rw,sync,rsize=32768,wsize=32768,intr,hard,proto=tcp,fsc natapp2:/exports /http/var/www/html && /etc/init.d/httpd start'
## Memcached server status ##
alias mcdstats='/usr/bin/memcached-tool 10.10.27.11:11211 stats'
alias mcdshow='/usr/bin/memcached-tool 10.10.27.11:11211 display'
## quickly flush out memcached server ##
alias flushmcd='echo "flush_all" | nc 10.10.27.11 11211'
## Remove assets quickly from Akamai / Amazon cdn ##
alias cdndel='/home/scripts/admin/cdn/purge_cdn_cache --profile akamai'
alias amzcdndel='/home/scripts/admin/cdn/purge_cdn_cache --profile amazon'
## supply list of urls via file or stdin
alias cdnmdel='/home/scripts/admin/cdn/purge_cdn_cache --profile akamai --stdin'
alias amzcdnmdel='/home/scripts/admin/cdn/purge_cdn_cache --profile amazon --stdin'
Conclusion
This post summarizes several types of uses for *nix bash aliases:
Setting default options for a command (e.g. set eth0 as default option for ethtool command via alias ethtool='ethtool eth0' ).
Correcting typos (cd.. will act as cd .. via alias cd..='cd ..').
Reducing the amount of typing.
Setting the default path of a command that exists in several versions on a system (e.g. GNU/grep is located at /usr/local/bin/grep and Unix grep is located at /bin/grep. To use GNU grep use alias grep='/usr/local/bin/grep' ).
Adding the safety nets to Unix by making commands interactive by setting default options. (e.g. rm, mv, and other commands).
Compatibility by creating commands for older operating systems such as MS-DOS or other Unix like operating systems (e.g. alias del=rm ).
I’ve shared my aliases that I used over the years to reduce the need for repetitive command line typing. If you know and use any other bash/ksh/csh aliases that can reduce typing, share below in the comments.
###########################################################################################################################
###########################################################################################################################
###########################################################################################################################
###########################################################################################################################
BASH Programming - Introduction HOW-TO
by Mike G mikkey at dynamo.com.ar
http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html#toc3
Notes an trash.
/////////////////////////////////////////////////////////////////////////////////////////////////////
# Download and Install the Latest Updates for the OS
apt-get update && apt-get upgrade -y
# Set the Server Timezone to CST
echo "America/Chicago" > /etc/timezone
dpkg-reconfigure -f noninteractive tzdata
# Enable Ubuntu Firewall and allow SSH & MySQL Ports
ufw enable
ufw allow 22
ufw allow 3306
# Install essential packages
apt-get -y install zsh htop
# Install MySQL Server in a Non-Interactive mode. Default root password will be "root"
echo "mysql-server-5.6 mysql-server/root_password password root" | sudo debconf-set-selections
echo "mysql-server-5.6 mysql-server/root_password_again password root" | sudo debconf-set-selections
apt-get -y install mysql-server-5.6
# Run the MySQL Secure Installation wizard
mysql_secure_installation
sed -i 's/127\.0\.0\.1/0\.0\.0\.0/g' /etc/mysql/my.cnf
mysql -uroot -p -e 'USE mysql; UPDATE `user` SET `Host`="%" WHERE `User`="root" AND `Host`="localhost"; DELETE FROM `user` WHERE `Host` != "%" AND `User`="root"; FLUSH PRIVILEGES;'
service mysql restart
###########################################################################################################################
#apt-get install mysql-server mysql-client
apt install mysql-server => vai instalar mysql 5.7.12 para XENIAL
apt install mysql-server
#sudo systemctl status mysql => VAI verify the MySQL server status
//It is a mysql command, not a linux or apt command
mysql_secure_installation //Tornar o mysql mais seguro ==>https://dev.mysql.com/doc/refman/5.7/en/mysql-secure-installation.html
https://www.digitalocean.com/community/tutorials/how-to-manage-packages-in-ubuntu-and-debian-with-apt-get-apt-cache
https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-16-04
https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-16-04
https://launchpad.net/ubuntu/xenial/+source/
https://launchpad.net/ubuntu/xenial/+source/git
http://askubuntu.com/questions/445384/what-is-the-difference-between-apt-and-apt-get
Java JDK -> http://tecadmin.net/install-oracle-java-8-jdk-8-ubuntu-via-ppa/#
LAMP - https://www.unixmen.com/how-to-install-lamp-stack-on-ubuntu-16-04/
https://lemp.io/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment