Showing posts with label ubuntu. Show all posts
Showing posts with label ubuntu. Show all posts

Wednesday, September 18, 2019

Wordpress and PhpMyAdmin inside Docker container

Let's see how to run WordPress and PHPMyAdmin inside a Docker container.
Part of the Docker for web developers course.

We will first create an environment file. Its purpose will be to save sensitive credentials data:
.env
MYSQL_ROOT_PASSWORD=mysql_root
MYSQL_ROOT=wp_user
MYSQL_PASSWORD=wp_password

Now it is time for the docker-compose.yml file where we will be describing our containers(services):
version: '3.3'

services:
  db:
      image: mysql:latest
      env_file: .env
      environment:
        - MYSQL_DATABASE=wordpress
      volumes:
          - dbdata:/var/lib/mysql
      command: --default-authentication-plugin=mysql_native_password

  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    env_file: . env
    environment:
      - WORDPRESS_DB_HOST=db
      - WORDPRESS_DB_USER=$MYSQL_USER
      - WORDPRESS_DB_PASSWORD=$MYSQL_PASSWORD
      - WORDPRESS_DB_NAME=wordpress
    volumes:
      - wordpress:/var/www/html
    ports:
      - "80:80"
   
  phpmyadmin:
    depends_on:
      - db
    image: phpmyadmin/phpmyadmin:latest
    env_file: .env
    environment:
      PMA_HOST: db
      MYSQL_ROOT_PASSWORD: $MYSQL_ROOT_PASSWORD
    ports:
       - 3333:80

  volumes:
    wordpress:
    dbdata:

Then you can launch: docker-compose up This will create networks between containers, volumes (to store persistent data), will pull images, configure them in order to create and run the containers.
We will be bringing up MySQL, PHPMyAdmin, and docker containers(services).

You'll need to wait a bit until everything is initialized and then you can browse:
http://127.0.0.1:80 for WordPress
as well as
http://127.0.0.1:3333 for PHPMyAdmin. Please note that for the PHPMyAdmin we need to use user: root, and password: mysql_root

Congratulations and enjoy learning !

Friday, September 13, 2019

Install and configure Webpack

Why use Webpack?
part of the course: JavaScript for beginners - learn by doing

  • to auto minimize, compile and transpile your modern ES6 and above version of JavaScript
  • to auto-reload your browser
  • to auto-include and merge external JavaScript files into one
  • and many more...
In this tutorial, we will focus on those three. First, download and install NodeJS, because we will need npm (node package manager) included in the NodeJS installation.
If you would like you can watch the video:


Prerequisites:
Have two files: index.html and main.js Inside index.html include index.html include
Inside main.js you can place any JavaScript code.

We will start by creating our first project. Why? - again to be able to have a portable version of our code which can other developers run in their machines. The project information will be stored inside the project.json file.
just type: npm init and follow the questions. Next, we will install webpack with:
npm install --save-dev webpack
Open project.json and you will see section devDependencies with the webpack inside. All upcoming package installations or so-called dependencies will have their place in our package.json file. As you can see --save-dev option is just installing the packages for development mode in the devDependencies section -  this means that we can have production and development dependencies and they can differ - which is nice because you would like to include in your production/live application only the needed libraries.
You can also see now that there is directory /node_modules/ - well there all downloaded and installed packages and their dependent packages will be placed.
Upon compilation / transpiling only part of those (certain functions) will be used and have their place in the final development or production project.
By the way, if other users have your files (excluding /node_modules/ which is heavy in KB) they just need to run npm install and they will have all the modules installed automatically based on your package.json file.
We need to install webpack-cli. Please do so with npm
And now we need to modify the "scripts" section of package.json to:
"scripts":{
    "build":"webpack"
}
Then just type npm run build and this will start webpack.
Create folder: /src and place inside index.html and main.js.
Inside package.json replace main.js to index.js.
Rename main.js as index.js ->this is needed as an entry point index.js
Now run again: npm run build and you will see a new directory: /dist This is newly created by webpack and is where the production code resides. So you can browse it via: http://project_directory/dist directly in your browser.

Next, we need a plugin that will minify and load/import directly our JavaScript into the HTML. We will use: html-webpack-plugin and html-loader. Do npm install them!
Now is time to create the webpack.config.js file with the following content:

const htmlplugin = require("html-webpack-plugin");
module.exports = {
module: {
 rules: [
{
   test:/\.html$/,
   use:[  { loader:"html-loader",   options: {minimize:true} }  ]
}
]
},
plugins:[
    new htmlplugin(       {  template:"./src/index.html",filename:"./index.html"} )
]
}
Then npm run build.
And you can see that index.html is modified (inside the /dist folder). From /src/index.html you can now remove the line (npm will auto-include it for us).
You can test the code from /dist directory - now everything works !

Lets apply Babel to be able to use ES6 on a wide range of browsers !
npm i --save-dev babel-loader @babel.core @babel/preset-env
create .babelrc file and place there:
{
 "presets":[ "@babel/present-env" ]
}
Now add babel to webpack.config.js
{
 test: /\.js$/, exclude:/node_modules/,
 use[{loader:"babel-loader"}]
}

Type again npm build and you can see that the project now transpiles ES6 into ES5 !

Let's do some live code reloading:
npm i --save-dev webpack-dev-server
then in package.json:
place new line inside of scripts:
"dev":"webpack-dev-server"
Now: npm run dev
Load up your website and then modify something inside of your JavaScript file.
You will see how the browser auto-reloads and you can see your changes!

Congratulations and enjoy learning!

Tuesday, September 10, 2019

Docker - Apache, PHP and MySQL setup

Here we will be doing an installation of the development/production environment of PHP and MySQL using Docker under Ubuntu. Here is a full video on the subject:


For more information, you can check the Docker for web developers course.

First, we will install docker and docker-compose:  

sudo apt install docker docker-compose

Then we will create docker group and place our user inside(to be able to use the docker command without sudo): 

sudo groupadd docker && sudo usermod -aG docker $USER

 
Now we either exit and re-run the terminal or type: 

newgrp docker

to switch our group.


Let's check the current images we are having: from docker image ls. We can test if docker's installation is successful with: 

docker run hello-world

 
Keep in mind that we can check what images we have in our system via:  

docker image ls

and our containers via 

docker container ls
 

With docker 

rmi hello-world: latest

we will remove the just installed image, but only if it is empty.
 

Let's check once again  

docker container ls -a

which will list all the images: running or not. We see our image is placed inside a container.


As a rule: if we want to remove an image, first we have to remove its container.
So we look up the container name. It is usually assigned by docker and in our case is: relaxed_cray and then we type 

docker container rm relaxed_cray

Now we can remove the image with 

docker rmi hello-world:latest


Setting up the PHP development environment
We will make a directory web_dev : 

mkdir web_dev

and will go inside:  

cd web_dev

Then we will create docker-compose file with: 

nano docker-compose.yml

Inside we will place the following config:
Keep in mind that for the indentations we are using 2 spaces! 

services:
  web:
       image: php:8.1-apache
        container_name: php81
        volumes:
           - ./php:/var/www/html/
        ports:
          - 8008:80

Short explanation: under volumes: we are specifying which local directory will be connected with the container directory. So whenever we are changing something local, the container will reflect and display the changes. For the ports: when we open/browse local port 8008 (127.0.0.1:8008) docker will redirect us to the 80 port of the docker container (achieved via port forwarding).
For the PHP image, you can choose whatever image you prefer from hub.docker.com
Next run: docker-compose up. This will read the docker-compose file and create a container by loading up different parts/layers of the packages, later will create a default network for our container and will load up the already provided PHP image.
The installation is ready, but if you want to display practical information, you have to create index.php file inside the newly created local PHP directory (storing our PHP files)
First, it is good to change the ownership of the directory with:
sudo chown your_user:your_user php/ -R

Then with
sudo nano index.php
we can type inside:
<?php 
echo "Hello from docker";
?>
Then again run docker-compose up. Also, try changing the .php file again and refresh the browser pointing to 127.0.0.0:8008

MYSQL support
let's create a new file Dockerfile, inside the PHP directory. Place inside:

FROM php:8.1-apache
RUN apt-get update && apt-get upgrade -y RUN docker-php-ext-install mysqli
EXPOSE 80

This will base our MySQL on the PHP image, that we already have, update the container system, run  specific docker extensions supporting MySQL from within PHP and expose 80-port

Next, we will customize the docker-compose.yml :
We will replace the line: image: PHP
with

buid:
  context: ./php
  dockerfile: Dockerfile 

This will read the docker file which we have set previously and create web service out of it.

Now we will be building the MySQL service:

db:
  container_name: mysql8
  image: mysql:latest
  command: --default-authentication-plugin=mysql_native_password
  restart: always
  environment:
    MYSQL_ROOT_PASSWORD: root
    MYSQL_DATABASE: test_db
    MYSQL_USER: devuser
    MYSQL_PASSWORD: devpass
   ports:
       - 6033:3306

Notes: We are using default authentication for MySQL in order to be able to login to the MySQL database, then docker is hardcoding mysql_user, mysql_password and mysql_database with: deuser, devpass, and test_db, and is exposing externally port 6033 for the MySQL service.

One last change: we would like first start the MySQL then the DB service, so we will add to the web service config:

depends_on:
  - db

To test the PHP-MySQL connection inside of our index.php file we can specify:

$host = 'db';  //the name of the mysql service inside the docker file.
$user = 'devuser';
$password = 'devpass';
$db = 'test_db';
$conn = new mysqli($host,$user,$password,$db){
 if($conn->connect_error){
  echo 'connection failed'. $conn->connect_error;
}
echo 'successfully connected to MYSQL';
}

If you experiencing problems you can remove the several images already created:

docker image ls -a 
docker rmi image ...fill here image names...
then run again docker-compose up and browse: 127.0.0.1:8008

Cheers and enjoy learning further.

Install Docker on Ubuntu 19.04 and 19.10

Here is how you can install Docker on Ubuntu 19.04

(part of the Docker course)


Video of the installation:



Steps:
1. Update the latest version of your repository and install additional packages for the secure transport of apt
sudo apt update && sudo apt install \ apt-transport-https \ ca-certificates \ curl \ gnupg-agent \ software-properties-common

2. Fetch and add docker's gpg key

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

3. Add the docker's repository (specific for our Ubuntu version) to our local repository
sudo add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable"
Note: if you are running an unsupported Ubuntu release you can replace the string: $(lsb_release -cs) with the supported versions such as: disco


4. update again the local repository and install the latest docker version (community edition)
sudo apt update  && sudo apt install docker-ce docker-ce-cli containerd.io

5. Test the installation by fetching and running test image:
sudo docker run hello-world
For more information, you can visit: https://docs.docker.com/install/linux/docker-ce/ubuntu/

Notes:
1. when having problems with the socket docker binds on you can allow your user to be owner of the socket: sudo chown $USER:docker /var/run/docker.sock

2. If you want to run docker without sudo, just add docker group to the users with: usermod -aG docker $USER

and change the current running group with: newgrp docker
or su ${USER}

3. If you get: ERROR: Couldn't connect to Docker daemon at http+docker://localhost - is it running?
check out the docker service status: sudo systemctl status docker
if it is stopped and masked: Loaded: masked (Reason: Unit docker.service is masked.) then you need to unmask the service: sudo systemctl unmask docker
then again start the docker service: sudo systemctl start docker 
until you see sudo systemctl status docker: Active: active (running)

Congratulations, and you can further explore the Docker for web developers course.

Wednesday, March 06, 2019

Ubuntu 19.04 & 19.10 firewall examples


In order to offer more than one service from a single IP address, Linux uses the notion of PORTS. For example, 80 is the common name of port for HTTP, 21 - FTP, 443 - ssh. Users can connect to services by typing the service IP address and its specific port number. Firewalls help us to open and close ports for specific IP addresses or whole network subnets. This is suitable when we want certain IP addresses to have access to our server while its default access to stay restricted.
For video information on firewalls, you can check this course.

In ubuntu, the firewall wrapper is named uncomplicated firewall or in short "ufw". It is installed in Ubuntu by default but is not active. We can check the status of ufw with: "status". If we want to completely isolate access to our machine we could use: "default deny incoming", while: "default allow outgoing" will allow packets to exit our machine. Keep in mind that in order for them to work, we have to activate those rules by typing: "enable". Next, we can explicitly: "reject out ssh" and then "delete reject out ssh".
Hint: If we are unsure of our actions we can always type: "reset" to empty the firewall rules. To deactivate the firewall please use "disable".

Since we are already connected with SSH, if we enable the firewall we will lose our connection so let's allow the forwarded port 22/tcp by typing: sudo ufw allow 22/tcp and run: sudo ufw enable.
We can actually show rules with numbers: status numbered, and to delete a rule we use: "delete rule_number". In order to insert a rule at a particular place, we use: "insert 1 your_rule".

Here are some commonly used service names: secure shell: ssh, mail: smtp, web server: http, https, SAMBA/File sharing: 139/tcp, 445/tcp. Not common service names are hard to remember, so here is a trick: ufw reads from /etc/services. When certain service is installed in order to communicate with the outside word it could modify the firewall rules by adding its own rules. In such cases with "app list" we can see all the installed service /application profiles and "app info 'SSH'" will dig us deeper into what ports certain application profile allows.

Lets' see the following examples on practical usage of the firewall:

//deny all incoming connections from 10.0.0.1 to interface eth0
deny in on eth0 from 10.0.0.1

// limit ssh access of specific IP address
deny proto tcp from 10.0.0.1 to any port 22

// limit a whole subnet
allow from 10.0.0.0/24 to any port 22

// allow ssh access only to IP: 10.0.0.1
allow proto tcp from any to 10.0.0.1 port 22

// deny outgoing SMTP traffic
deny out 25

// allow connections on eth1 interface to MySQL
allow in on eth1 to any port 3306

If we want to use filtering my mac address we can add: -A ufw-before-input -m mac –mac-source 00:00:00:00:00:AA -j DROP in /etc/ufw/before.rules
(these are rules who are read and act before the firewall rules)

To monitor the usage of the firewall we can use: sudo tail -f /var/log/ufw.log, but just if the "ufw logging" is enabled.
While experimenting with the firewall you can use an external network scanner such as Nmap (sudo apt install nmap) to check which ports are open on the machine.

More useful examples you can find with: man ufw
as well as on the ubuntu firewall page: https://help.ubuntu.com/lts/serverguide/firewall.html More information, you can find in this course.

Wednesday, February 27, 2019

Ubuntu 19.04 - files, directories, users and groups

The following are working examples for managing files, directories, users and groups in Ubuntu server environment.
For more information you can take a look at this course on ubuntu linux server:

https://udemy-images.udemy.com/course/480x270/2215088_32d5.jpg

Work with the console:
By typing "History" without the quotes, you can take a look at your previous commands and with "history | grep name_of_command " you can search for specific command that you already used. If you want to return the previously used command just press the "up" arrow. And if you have problems remembering filenames you can start typing the first letter of the name and then press several times "TAB" button - this will give you autocomplete for the rest of the word. 
You can clear the console by using "clear".

Directories:
All the directories are contained into the root directory /. Pay attention: Linux file and directory names are case sensitive, so "Linux.txt" is different than "linux.txt".
If you want to see your current directory just type: "pwd". With "cd .." you go up to the parent directory, with "cd /" you will go to the root directory. Using the command "ls" you can see the current objects(files, directories and symbolic links) residing in the file system.
You can create directories using mkdir new_dir_name
To delete directory use: rm dir_name . Before removing a directory, please make sure that it is empty.
"ls -la" will give you more information like properties, date of creation, size, permissions, owner and grop of the files and directories.
if you go to the root / directory: "cd /" "ls -la |grep bin" will show you not only the /bin directory but any directories that start with "bin" characters. We can also use * to show all files starting with 'linux': "ls linux*" or listing all .html files "ls .html"

If you want to know more about the "ls" command just append "--help" next to it:
"ls --help"
and if you want to list the resulting information in pages you can type:
"ls --help | more"
"Enter" and "Space" keys can be used for navigation
For more information on the command try: "man ls". You can exit the help screen with the key "q"



Files:
You can create an empty file with the command "touch file_name.txt". To see the contents of the file just type: cat file_name.txt
In just one line we can actually filter the contents of a file based on condition (all the lines containing "Example"), and output them in a new file(output.txt): "cat examples.desktop | grep "Example" > output.txt "
To remove the file we type: "rm output.txt"
We can edit files with the "nano" editor: "nano output.txt" Inside we can use crtl + O to write the changes, and ctrl + X to exit the editor
Hint: if there are spaces or special symbols in the filename to work with it, just wrap the name with quotes or just to put / before the special symbol:
“123–!.txt”
123-\’.txt \‘file name!\’
file\ name\!
Hint: a convenient way of displaying text files is with "more /var/log/syslog" - this will give us the content paginated and if we use: watch tail /var/log/syslog we can watch if there are any changes to the last few lines of the file.
"watch -n 5 tail -n 15 logfile.txt" will grab last 15 lines of "logfile.txt" and will watch them every 5 seconds.
Moving and copying files:
to move file we use: "mv source_filename /directory/destination_filename"
same is for copying files: "cp filename /directory/"
We can delete files using: "rm file_name" or just all files within a directory with "rm *"

Permissions
When we run: ls -la we see bunch of information about the objects within a directory. For example:
 -rwxr-xr-x   1 nevyan nevyan   4096 nov 25 20:34  file
drwxr-xr-x   2 nevyan nevyan   4096 nov 25 20:34  Public

Lets start with the first row representing a file. We know it is a file because the first character of the first column doesn't start with D.
Then we can see its permissions: They are divided into groups of 3(rwx). (read, write and execute)
First 1 group are for the owner(creator) of the file, then for the group it belongs, and last ones are for every other user.
We use groups in order to be able to set once permissions for multiple users belonging to a group, so they can automatically get those permissions.
For example:
just to be able to "cd" into a directory we need to have (+x) execute rights over the directory.
to be able to list file contents with cat we need (+r)read rights over the file.

Linux applies the principle of least privileges, which means that a user is given not more than the privileges he/she needs for completing a certain task. Let's now take a look of what is inside of /etc/shadow with the cat command. We will see: 13 permission denied
Reason is that only the root user can read this file. You can check this out by issuing: ls -la /etc/shadow and look at the others group(3rd) we see - which means no one else except its owner have rights over this file. And the owner can be seen on the second column (root).
If we run the same command, appending "sudo" in front:
"sudo ls -la /etc/shadow"
(and type the root password)
we will see that we have rights to look at the file. This is because for this particular command we have gained temporary "root" rights
Next we can take a look at /etc/passwd - there we can see all the users registered into the server, their login names, hidden password, user id, group, home directory as well as working shell(command prompt).

Changing permissions:
"chmod ugo+rwx file_name.txt"
this will give maximum privileges(rwx) to all(user,group and others) to file_name.txt

Changing ownership:
to change the ownership we can type:
"chown user1:user1 file_name.txt"
will set user=user1 and group=user1 to the file.

Groups:
Each user can belong to one primary and several secondary groups.
"id" shows the current groups our user belongs to. We can issue: groups and user_name to find out which groups specific user belongs to:
"groups user_name" will list the information in format: (primary, secondary) groups
The same information can be gained from the file: "/etc/group" and we can list information about particular group with: "cat /etc/group | grep mygroup"
"addgroup mygroup" will add new "mygroup" to our currenly existing groups
"usermod -G mygroup nevyan" will remove all secondary groups and will add secondary group "mygroup" to user "nevyan"
With the flag -g we can change the user primary group and if we want just to append another secondary group to our user we can use the -aG flag.
In order to remove user from a group: "deluser nevyan mygroup"
and finally to remove a group we do: "sudo delgroup mygroup"
Notice that we need to "logout" in order to see the effect of those group changes. Congratulations and enjoy the ubuntu linux server course:

Saturday, December 10, 2016

Install OpenStack Mitaka under Virtualbox

First, let's get VirtualBox and set up our VirtualBox machine:

Give it at least 6 GB RAM, having a 64-bit processor
Then create 3 networks:
NatNetwork(for connection with the external world) with address: 10.0.2.0/24, to support DHCP
and allow port forwarding which we will use to connect to the internal Virtual Machine (VM)s:
name:ssh, protocol: TCP, host IP: 10.0.2.15, host port 22, guest IP: 127.0.0.1, guest port:2022
this way you can use ssh or putty to connect to 127.0.0.1:2022 and access the internal Virtual machines.
Next, create 2 other host-only networks with the following details(for communication and data transfer):
ip:10.50.0.1
mask:255.255.255.0
and
ip:10.254.254.1
mask:255.255.255.0
both with DHCP disabled

SSH access:
If you experience problems connecting to the Virtual Machine, you can try to disable and stop the firewall:
sudo systemctl disable firewalld
sudo systemctl stop firewalld
add an exception for SSH access in the firewall
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
check the selinux configuration
sudo nano /etc/selinux/config
check the open ports on your network with:
1. find all the networks you would like to inspect:
ip a |more
2. Install and use Nmap to portscan those networks:
sudo yum install nmap
scan the open ports on the virtual machines:
nmap 10.0.2.*
nmap 10.254.254.*

Install CentOS host system
Download CentOS minimal ISO and boot up the machine via VirtualBox.
Once logged in in the VM, edit the sudoers file and place your account there:  sudo cat /etc/sudoers
(instead of always typing sudo in front of the commands, you can write: sudo -i and continue working)
sudo dhclient - to make DHCP give access to the Virtual machines to outside(Internet) IP addresses
then edit /etc/resolv.conf sudo nano /etc/resolv.conf and add google nameserver 8.8.8.8 to be able to fetch internet websites from VM.

Configure the three network interfaces using information such as IP addresses from above :
cd /etc/sysconfig/network-scripts/
sudo nano ifcfg-enp0s3
sudo ifdown enp0s3
sudo ifup enp0s3
(repeat the process for enp0s9 and enp0s8)
check if the configuration is correct
ip a

Preparing installation
We need to install additional packages:
sudo yum install wget tcpdump curl
install network synchronizing time server
sudo yum install ntp
set the hostname of our virtual machine:
sudo hostnamectl set-hostname myopenstack.com
stop and disable network interference from Network Manager:
sudo systemctl stop NetworkManager.service
sudo systemctl disable NetworkManager.service


Upgrade to the latest available kernel to ensure better performance on virtualization and integration with VirtualBox:
enable elrepo kernel repository
yum --enablerepo=elrepo-kernel install kernel-ml
install ncurses library:
sudo  yum install gcc ncurses ncurses-devel
sudo rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
sudo rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
install fastestmirror to get closest repository:
sudo yum install yum-plugin-fastestmirror
install the kernel:
sudo yum --enablerepo=elrepo-kernel install kernel-ml
Reboot the system to make new kernel effectively loading
sudo reboot
check the kernel version
uname -a

Installing OpenStack Mitaka
get the RDO-release:
sudo yum install http://rdo.fedorapeople.org/rdo-release.rpm
then install the RPM package: sudo yum install openstack-packstack
Generate answers file for easier installation configuration of OpenStack
sudo packstack --gen-answers-file=.answers.cfg
install OpenStack using the answer-file:
sudo packstack --answer-file=.answers.cfg
Upgrade the openstack distribution as well as all other CentOS packages
sudo yum upgrade

Enter OpenStack dashboard using browser
(in Windows you can install xming server - to allow access from outside to OpenStack via ssh graphical screen )

install xauth authorization
sudo yum install xauth
sudo yum groupinstall fonts
*start the graphical terminal xterm
export DISPLAY=:0.0
start firefox and open up OpenStack dashboard
firefox 10.254.254.100/dashboard

Congratulations, you can now start using OpenStack :)
Enjoy!

Saturday, December 03, 2016

How to install the newest kernel on Ubuntu

Being with the latest stable kernel usually brings lots of benefits resulting in:

- having the latest supported drivers for your hardware
- fixing commonly reported bugs
- increase in overall system performance
- various speed and stability related, software-oriented optimizations
Reference: Practical Ubuntu Linux Server for beginners

Here is a video of the update process:



In order to do a simple kernel upgrade, so to be sure to have the latest one installed.
First visit: https://www.kernel.org/
Then choose from stable or unstable(mainline) kernel branch you would like to have your kernel installed. Just look up the numbers. Note: r.c. has the meaning of release candidate, so the kernel is still in development.
Then go to http://kernel.ubuntu.com/~kernel-ppa/mainline/
You'll find a huge directory with supported kernels tailored for Ubuntu distributions.
Scroll down, to pick the chosen one and enter its directory. Then open up a terminal and write:

cd /tmp
This way we will enter the temporary folder, which will be erased automatically when we reboot our machine.
We have to download the proper kernel version. To check if we have 32 or 64-bit system installed  type:
uname -m
which if shows i686 then your kernel should be 32 bit, and if shows x86_64 then you have to download the 64-bit kernel packages.
Next point at the right kernel with the right mouse click, copy the link location from 3 files: one with a name ending on: _all, and two _generic .deb packages
  linux-headers-4.15.2-041502_4.15.2-041502.201802072230_all.deb
  linux-headers-4.15.2-041502-generic_4.15.2-041502.201802072230_amd64.deb
  linux-headers-4.15.2-041502-lowlatency_4.15.2-041502.201802072230_amd64.deb
  linux-image-4.15.2-041502-generic_4.15.2-041502.201802072230_amd64.deb
  linux-image-4.15.2-041502-lowlatency_4.15.2-041502.201802072230_amd64.deb

from those we need to download everything, except the 2 lowlatency packages.
In terminal just enter wget then paste the link location. Here follows an example of the first package:
wget linux-headers-4.15.2-041502_4.15.2-041502.201802072230_all.deb
The last step is to install the downloaded packages using sudo privileges:
sudo dpkg -i linux*
Reboot the computer in order to load the new kernel:
sudo reboot

If you have problems with the newly installed kernel, just press several times on restart the 'ESC' key and choose from Advanced options the previous working stable kernel version.
After some time you may notice that kernels begin to pile up, thus reducing your disk space. I advise you to remove the redundant ones with: sudo apt remove linux- and then list the not used: modules, image and headers packages.
Congratulations and happy learning!

Wednesday, November 30, 2016

Install Laravel on Ubuntu

Here is briefly how to do a basic install of Laravel on Ubuntu. First, get the PHP language interpreter. And here is updated video on how to do the installation on Ubuntu 19.04 / 19.10, also, please enjoy the Ubuntu admin course



sudo apt-get install php
Then install and run composer which will take care of packages dependencies:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
copy composer binary file into /sbin directory to be able to run composer from everywhere.
sudo mv composer.phar /usr/local/sbin/composer
or update the local path to be able to access composer vendor binaries and later be able to run laravel: export PATH = "$HOME/.config/composer/vendor/bin:$PATH" . If you would like the path change to be persistent just add the line into the .bashrc file.

install the two minimal PHP libraries required for laravel:
sudo apt-get install php-mbstring
sudo apt-get install php-xml
use composer to create a new project called learning-laravel from a package named laravel/laravel. The new directory which package would get installed will be called learning-laravel:
composer create-project laravel/laravel learning-laravel
enter into the new directory
cd learning-laravel
and start a local listening PHP server on port 8888 and address localhost(127.0.0.1). This will also make PHP interpret all the files within the subdirectory /public:
php -S localhost:8888 -t public
Open a browser on localhost:8888 Congratulations! You have installed a running Laravel project!

Monday, February 01, 2016

Internet Connection Sharing in Ubuntu

For this setup, you'll need 2 physical network cards installed on your server - one connected to your Internet provider, and the second connected to a hub or second computer. Reference: Practical Ubuntu Linux Server for beginners


1. Go to the upper right corner of the desktop and right-click on Edit connections. Then rename your both connections using the Edit button as 'incoming' (Internet provider) and 'localnet' (home network). If you don't know which one(eth0, eth1, etc.) is which just unplug cables one by one to check. This step will save you lots of trouble down the process.

2.Choose to Edit the 'localnet' connection, click on tab: IPv4 Settings and for method choose: 'Shared to other computers'. Repeat the same procedure for the 'incoming' connection, but this time choose DHCP.

(if you are using PPPOE)
Click on DSL - Edit and type your username and password given by the Internet provider.

3. Next you'll have to enable the two logical connections followed by the DSL connection(if you use one) by just clicking on them. During the process notice if 'wired media is connected' message appears. If the media gets connected and quickly disconnects you can try to disable the IPv6 Settings on the 'localnet' by setting their method to 'ignore'.


Also, it's necessary not to let the NetworkManager setup the default gateway for the 'localnet' connection, so just do:
# sudo nano /etc/NetworkManager/NetworkManager.conf
and set its managed parameter = 'false'.


Same can be achieved if you click on 'localnet' connection Routes button and check the 'Use this connection only for resources on its network'. This way its default gateway won't get overwritten by the NetworkManager.


Finally turn on the internal firewall with the command invoked in terminal:
# sudo ufw enable
This way your server setup is OK, now for the computers that want to use Internet click on Edit connections and just give them the 'localnet' configured IP address as a gateway.

Cheers!

Thursday, January 28, 2016

Install latest Ubuntu version under VirtualBox and set up ssh

Here is how to install Ubuntu in a virtual machine "Virtual Box" and set up an ssh server. Reference: Practical Ubuntu Linux Server for beginners
First install the free version of Virtual Box from Oracle website: https://www.virtualbox.org/ . Then open the program and let's create a new virtual machine from the button new.
Note: Ubuntu requires around 10GB of disk space and please make sure that all visualization instructions and software code protections are enabled within your BIOS.
Then we download the latest Ubuntu version from http://cdimage.ubuntu.com/daily-live/current
Now is time to start the virtual machine and open up the Ubuntu .iso file. The installation will start, where is important to choose the root partition mount point/.
Here is how to do the installation:



After finishing installation it is time to install the networking, but first please update the system by opening a terminal (Ctrl+t):
# sudo apt update
# sudo apt dist-upgrade
If you wish to install ssh server and use it within your network, this can be done the following way: To install an ssh-server in a terminal type:
# sudo apt install ssh-server
Then we have to remove the built-in network manager(which will mess with the static IP addressing we need to set) via:
# sudo apt purge network-manager
At this point you may notice that other virtual boxes could not contact your machine, this is because you have to set the virtual box networking model. So open VirtualBox Ubuntu image settings and set the virtual machine networking from NAT to BRIDGED, which means that it can use private addresses and set up servers on. Warning this will stop your internet access. Then restart the ubuntu virtual machine and is time to set up our network so type:
# sudo ifconfig eth0 192.168.0.1 netmask 255.255.255.0 up
this will set up your network interface card. If you want to make the changes persistent on the next restart you can place this information in /etc/network/interfaces file:
# sudo nano /etc/network/interfaces
iface eth0 inet static
address 192.168.0.1
netmask 255.255.255.0
gateway 192.168.0.255

next you can do the same steps for other virtual installations of Ubuntu.
and try to connect to 192.168.0.1 via ssh client
# ssh 192.168.0.1 -l username

That's it. Enjoy learning !

Monday, January 25, 2016

Install Wordpress in Ubuntu

This post will show how to install WordPress blog under Ubuntu I've prepared a video describing the process, and you might be interested in following a whole course.


We'll be using the default blog directory of /usr/share/nginx/html, so if you have a different one like /var/www/html please use it instead.
The first step is to get the WordPress system from wordpress.org
in a terminal type:
cd /tmp
wget http://wordpress.org/latest.tar.gz
then we unpack the archive
tar -zxvf latest.tar.gz
and move to our blog directory
mv wordpress/ /usr/share/nginx/html/
next, we change the group and owner of this directory to www-data, which is needed by our web-server to have access to the files:
chown -R www-data:www-data /usr/share/nginx/html/wordpress
then give permissions for all users in this owner to read, write and execute(7) files in the blog directory, and for the group and other users just to be able to read and execute files(5):
chmod -R 755 /usr/share/nginx/html/wordpress
we set the same rules to be automatically applied for any sub-directory to be created within /wordpress/, to serve image or other uploads, plugins etc.
sudo chmod g+s /usr/share/nginx/html/wordpress
Then we launch mysql client
mysql -u root
and lets create the default wordpress database:
CREATE DATABASE wordpress;
create one user wp_user in order to have access to our wordpress database:
CREATE USER wp_user IDENTIFIED BY 'wp_pass';

and give permissions to wp_user to be able to create tables, insert data etc. inside the wordpress database:
GRANT ALL PRIVILEGES ON wordpress.* TO wp_user;
now is time to set up the default configuration of our blog to use this database so we go to our blog directory, rename and use the default config file:
mv wp-config-sample.php wp-config.php
then open it up for editing via:
sudo nano wp-config.php
just change these three to ensure that WordPress will have access to MySQL:
define('DB_NAME', 'wordpress');
set database user name:
define('DB_USER', 'wp_user');
set database password
define('DB_PASSWORD', 'wp_pass');
finally, open up a browser and type:
http://localhost/wordpress/index.php



then follow the steps and your WordPress installation is ready!

Install & setup NGINX, PHP, MYSQL and FTP in Ubuntu 19.04

This post will describe how to install how to set up a brand new website hosting using the following software technologies: webserver: Nginx, language: PHP, database: MySQL, and set up ssh secure shell and FTP access under Linux Ubuntu 19.04.
Knowing how to install these services is essential when developing web applications, it is also very useful while taking comprehensive course projects, which prefer local installations. 
 

Please take a look at the video:


We start with installing the ssh server so in the console ( terminal ) start typing the following commands:
sudo apt install openssh-server
then we start the server:
sudo systemctl start sshd
from now on we can access our server via: ssh 192.168.100.1 -l myuser just replace your IP address and the user parameters

NGINX
install the Nginx server
sudo apt-get install nginx
edit the sites directive and ...
sudo nano /etc/nginx/sites-available/default
and place the following information, replacing the server_name IP address with your own(check it with the 'ifconfig' command) and if you wish the root directory of the server:
 
 server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /usr/share/nginx/html;
    index index.php index.html index.htm;

    server_name 192.168.100.1;

    location / {
        try_files $uri $uri/ =404;
    }

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php7.2-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

write out with ctrl+o and exit.

open the Nginx configuration file
sudo nano /etc/nginx/nginx.conf
and make sure that the user www-data; is present!
restart Nginx to apply the settings
sudo systemctl restart nginx
then if you type: http://your_ip_address/ the webserver should give you a webpage!

MYSQL

install the MySQL server
sudo apt install mysql-server
automatically set up default permissions for databases, remove users and restrict access
sudo mysql_secure_installation

change ownership of MySQL directory in order to have database access from the MySQL client / or API interface running on PHP applications
sudo chown mysql:mysql mysql/ -R
change connection of MySQL from a socket to password authentication:
sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
next, apply the changes with:
FLUSH PRIVILEGES;
EXIT
optional: add DB permissions in order for the MySQL interface used by PHP to access the databases and tables
open up MySQL. When asked for password type "password"
mysql -u root -p
give privileges: replace your_database with the DB you want to access from within PHP and your_user with a chosen user, you want to give privileges on:
GRANT ALL PRIVILEGES ON your_database.* TO 'your_user'@'%' WITH GRANT OPTION;

FTP SERVER
install FTP server vsftpd
sudo apt install vsftpd
edit the vsftpd configuration file:
sudo nano /etc/vsftpd.conf
make sure that these are uncommented (without ; in front of the line)
enable local_enable = YES;
write_enable = YES;
local_umask = 022;
and add
local_root=/usr/share/nginx/html
to be able when connecting with FTP client to jump straight to the website directory.

Note:
use only one of these, the other option should be set to NO:
for IPv4: listen=YES
for IPv6: listen_ipv6=YES

restart vsftpd to apply the new changes
sudo systemctl restart vsftpd

PHP
install php language
sudo apt install php-fpm php-mysql
edit php config files:
sudo nano /etc/php7.3/fpm/php-fpm.conf

make sure that
user = www-data
group = www-data
are set in: sudo nano /etc/php7.3/fpm/pool.d/www.conf

in the following file you can set up error logging:
sudo nano /etc/php7.3/fpm/php.ini
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
restart the PHP service to accept the changes:
sudo systemctl restart php-fpm

PHPMYADMIN
install PHPMyAdmin
sudo apt install phpmyadmin
(& create PHPMyAdmin with user and password of your choice)

create a symbolic link from the default HTML directory of Nginx to PHPMyAdmin so it can be browsed via http://your_host/phpmyadmin (where your_host could be 127.0.0.1 or you IP address)
sudo ln -s /usr/share/phpmyadmin /usr/share/nginx/html

change ownership of default Nginx directory to be created and owned by www-data
sudo chown www-data:www-data /usr/share/nginx/html/ -R
give permissions of any owner and member of this www-data group to read and write files in the default website directory (for FTP and console access) 
sudo chmod -R 775 /usr/share/nginx/html/

set sticky bit for anyone who is a member of the group www-data to create new files and directories with default read write and execute permissions.
sudo chmod g+rwxs /usr/share/nginx/html
add our user $USER to be a member of the www-data group, which is the default group of Nginx server (to enable writing into files)
add our user $USER to the www-data group
sudo usermod -a -G www-data $USER
note: you'll have to re-login in the server to see the effect of creating new files and directories or the alternative is to type: newgrp www-data and test the changes!

That's it, enjoy and happy coding. And if you want to learn more on Ubuntu administration you can try this course

Subscribe To My Channel for updates