Youtube channel !

Be sure to visit my youtube channel

Sunday, November 03, 2019

Install NodeJS and Angular on Windows 10 WSL2

Let's see how under Windows Subsystem for Linux (WSL 2) we can setup NodeJs, Npm and install Angular. So that we can later do our web development projects or trying examples from Angular courses. You can also watch the video on the installation.



We will first enable WSL 2 in order to be able to support and load Linux systems:
launch PowerShell by typing: powershell and with right click run it in administrative mode. Paste the following content which will enable WSL as well as the virtual machine platform:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux 
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform
wsl --set-default 2The last line will set the 2nd more performant version of WSL as a default when running OS such as Ubuntu.

Next, we will go to Microsoft's store, download and launch the Ubuntu When launching the application, you might be prompted to restart your computer. Then again try to Launch the ubuntu application by just typing ubuntu. It will ask you to set up a default user and password so you can access the Ubuntu system.

Now it is time to update the local distribution packages with:
sudo apt update && sudo apt dist-upgrade

Installing Angular
Since Ubuntu version provided in WSL is not the latest one, we will go to https://github.com/nodesource/distributions
and then install the latest available node version
curl -sL https://deb.nodesource.com/setup_13.x | sudo -E bash - sudo apt-get install -y nodejs


We are ready to install the Angular CLI:
sudo npm i -g @angular/cli
(we install the package globally, so to be able to execute ng command from anywhere inside our system)
Now we can type ng new_project followed by cd new_project and ng serve
You can browse the newly created project under http://localhost:4200

Congratulations!

Saturday, November 02, 2019

Install VirtualBox under Ubuntu 19.10

You may have noticed that VirtualBox is having problems to install via the usual apt install method on Ubuntu 19.10. The reason is that it relies on old libraries from Ubuntu 19.04 which conflict with the current ones. When having such problems with compatibility there is also interesting solutions.
Reference: Practical Ubuntu Linux Server for beginners
You can watch the video for more details:



First, uninstall any previous VirtualBox leftovers that you might have with sudo apt remove virtualbox
Just go to https://www.virtualbox.org/wiki/Testbuilds and download the test build for Linux64-bit
then do: chmod +x file.run (where the file is the downloaded file)
and just run: sudo ./file.run

And that's it, the installer will run and you'll have the newest version of VirtualBox under Ubuntu 19.10 running.

Notes:
- Please also check the version of your kernel (uname -r), for now, Virtualbox supports kernel 5.3, so playing on anything above this version will also not allow Virtualbox modules to be compiled into the kernel and run.
- Your further virtual machines will reside inside the /root/ directory
- In order to remove the VirtualBox, you can run ./file.run uninstall

Congratulations!

Wednesday, October 30, 2019

Optimize Ubuntu for speed and performance

Here are some ways to optimize your Ubuntu system to take fewer resources and to be more performant. If you are interested there is a complete course on ubuntu administration.

You can take a look at the video:



I advise you at first to take a look at Conky as a hardware monitoring application
sudo apt install conky-all
and then run conky
From there just monitor which resources are fully utilized such as Disks, CPU, and Memory. This way you can really understand if you need to buy new hardware.

2. Use Lubuntu
sudo apt install lubuntu-desktop
you will be amazed by the performance gains.

3. Clean up your system using bleachbit
https://www.bleachbit.org/download

4. Tab wrangler - this addon to Firefox or Chrome will stop any inactive tabs, thus freeing up precious memory

5. Services:
systemd-analyze blame - will output all the services loading at bootup and which are taking most of the time. Feel free to disable with systemctl disable service_name those that you don't want.
You can inspect why certain service takes too long by typing:
systemctl status udisks2
and then
systemd-analyze critical-chain udisks2.service
(here we are inspecting the udisks2.service)
journalctl -b | grep udisks2
will show you even more detailed information about a particular service
Additional:
- You can also disable package indexing with sudo apt-get purge apt-xapian-index
- If you are not using thin clients, or have servers that need internet access for boot/configuration  you can also do:
sudo systemctl disable NetworkManager-wait-online.service
- Do check if UUID's listed in blkid and /etc/fstab match up and edit /etc/fstab to match accordingly.

Extra note: Install kernel modification such as Xanmod, which optimizes the performance to be suited for Desktop users:
echo 'deb http://deb.xanmod.org releases main' | sudo tee /etc/apt/sources.list.d/xanmod-kernel.list && wget -qO - https://dl.xanmod.org/gpg.key | sudo apt-key add - 
sudo apt update && sudo apt install linux-xanmod
I am really impressed by the performance of this kernel mod.


Congratulations and enjoy the course.

Monday, October 28, 2019

Install PHPMyAdmin under Ubuntu 19.10

Here is how to install PHPMyAdmin on Ubuntu 19.10. If you are interested in working within the Ubuntu environment, I would recommend you taking a more comprehensive Ubuntu course.
You can watch the following video for reference:

The steps are as follows:

1. Apache server
sudo apt install apache2
you can type: http://localhost to see if apache works

2. Install the PHP interpreter, add PHP support for Apache
sudo apt install php libapache2-mod-php

then go to /var/www/html and set the correct read/write permissions for our current user:
sudo chown $USER:$USER /var/www -R

create a new file index.php with:

echo "hello from php";
?>
and test in the browser http://localhost - you should be able to see the output: hello from php

3. Mysql server
sudo apt install mysql-server php-mysql
this will install the MySQL server as well as enable PHP to run MySQL queries
sudo mysql_secure_installation
will set our initial root password
just set the password and answer Y to flush privileges to be able to apply the new password to MySQL.
sudo mysql
to ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'password'.
this will enable password authentication and set the MySQL root password to password.
Exit the MySQL client and lets test with mysql -uroot -p
and then enter the password: password

4. PHPMyAdmin
install composer via: sudo apt install composer
install minimum required libraries for PHPMyAdmin: sudo apt install php-xml php-zip
fetch and install PHPMyAdmin: composer create-project phpmyadmin/phpmyadmin

Congratulations and enjoy the course!

Tuesday, October 22, 2019

Laravel inside Docker as a non root user

Laravel installation under Docker seems a painful experience but at the same time, it is a rewarding learning experience. The following are the steps for achieving the development environment for Laravel. For more information you can take a look at the Docker for web developers course, and also watch the following video for further details:


Let's assume you've installed Docker on Ubuntu or Windows 10 WSL2 with:
# sudo apt install docker
# sudo apt install docker-compose

Initially, we will get the source files of Laravel from its GIT repository. First, inside a newly created directory, we will use: git clone https://github.com/laravel/laravel.git .

Let's now run the Laravel project deployment locally:
sudo apt install composer && sudo composer install
(because we would like to develop our code locally so the changes to be reflected inside the docker container)

Then we will create our Dockerfile with the following content:
Be cautious when writing the yaml files: you will need to indent each element line: with space, incrementing the space for each sub-element

#we are copying the existing database migration files inside the docker container and are fetching and installing composer without user interaction and processing of scripts defined in composer.json
FROM composer:1.9 as vendor
COPY database/ database/
COPY composer.json composer.json
COPY composer.lock composer.lock
RUN composer install --no-scripts --ansi --no-interaction

# we are installing node, creating inside our container /app/ directory and copying the requirements as well as the js, css file resources there
# Then we install all the requirements and run the CSS and JS preprocessors

FROM node:12.12 as frontend
RUN mkdir -p /app/public
COPY package.json webpack.mix.js  /app/
COPY resources/ /app/resources/
WORKDIR /app
RUN npm install && npm run production

# get php+apache image and install pdo extension for the laravel database
FROM php:7.3.10-apache-stretch
RUN docker-php-ext-install  pdo_mysql

# create new user www which will be running inside the container
# it will have www-data as a secondary group and will sync with the same 1000 id set inside out .env file

ARG uid
RUN useradd  -o -u ${uid} -g www-data -m -s /bin/bash www

#we copy all the processed laravel files inside /var/www/html
COPY --chown=www-data:www-data . /var/www/html
COPY --chown=www-data:www-data --from=vendor /app/vendor/ /var/www/html/vendor/
COPY --chown=www-data:www-data --from=frontend /app/public/js/ /var/www/html/public/js/
COPY --chown=www-data:www-data --from=frontend /app/public/css/ /var/www/html/public/css/
COPY --chown=www-data:www-data --from=frontend /app/mix-manifest.json /var/www/html/mix-manifest.json

# allow the storage as well as logs to be read/writable by the web server(apache)
RUN chown -R www-data:www-data /var/www/html/storage

# setting the initial load directory for apache to be laravel's /public
ENV APACHE_DOCUMENT_ROOT /var/www/html/public
RUN sed -ri -e 's!/var/www/html!${APACHE_
DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf

# changing 80 to port 8000 for our application inside the container, because as a regular user we cannot bind to system ports.
RUN sed -s -i -e "s/80/8000/" /etc/apache2/ports.conf /etc/apache2/sites-available/*.conf

RUN a2enmod rewrite

# run the container as www user
USER www

Here are the contents of the .env file which contains all the environment variables we would like to set and to be configurable outside of the container, while it has been build and run.

DB_CONNECTION=mysql
DB_HOST=mysql-db
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=laravel
DB_PASSWORD=mysql
UID=1000

Keep in mind that we are creating a specific user inside of MySQL which is: laravel, as well as setting its UID=1000 in order to be having synchronized UIDs between our container user and our outside user.

Follows the docker-compose.yml file where we are using multi-stage container build.

version: '3.5'

services:
  laravel-app:
    build:
      context: '.'
# first we set apache to be run under user www-data
      args:
        uid: ${UID}
    environment:
      - APACHE_RUN_USER=www-data
      - APACHE_RUN_GROUP=www-data

    volumes:
      - .:/var/www/html
# exposing port 8000 for our application inside the container, because run as a regular user apache cannot bind to system ports
    ports:
      - 8000:8000
    links:
      - mysql-db

  mysql-db:
    image: mysql:8.0
# use mysql_native authentication in order to be able to login to MySQL server using user and password
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    volumes:
      - dbdata:/var/lib/mysql
    env_file:
      - .env
# setup a newly created user with password and full database rights on the laravel database
    environment:
      - MYSQL_ROOT_PASSWORD=secure
      - MYSQL_USER=${DB_USERNAME}
      - MYSQL_DATABASE=${DB_DATABASE}
      - MYSQL_PASSWORD=${DB_PASSWORD}

# create persistent volume for the MySQL data storage
volumes:
  dbdata:


Lets not forget the .dockerignore file
.git/
vendor/
node_modules/
public/js/
public/css/
run/var/

Here we are just ensuring that those directories will not be copied from the host to the container.

Et voila!

You can now run:
docker-compose up
php artisan migrate
and start browsing your website on: 127.0.0.1:8000
Inside you can also invoke: php artisan key:generate

Congratulations, you have Laravel installed as a non-root user!

Subscribe To My Channel for updates

Things to do after install Fedora 43

--- ##### SYSTEM UPDATES & FIRMWARE   sudo dnf upgrade --refresh -y   ##### Check Firmware (Only if supported hardware is found)   fwupd...