Stored Content

1. Installing Ubuntu Server on VMware

1. Download the latest Ubuntu Server ISO from Ubuntu Official Website.

2. Open VMware Workstation or VMware Player and create a new virtual machine.

3. Select "Typical" configuration and choose the downloaded Ubuntu Server ISO.

4. Allocate RAM (recommended: 2GB or more) and create a virtual hard disk (recommended: 20GB or more).

5. Complete the VM setup and start the installation.

6. Follow the Ubuntu Server installation steps: 

1. Choose minimal installation.

2. Configure network settings.

3. Set up a user and password.

7. After installation, reboot the VM and log in.

2. Initial Server Configuration

Step 3: Install OpenSSH Server

To manage your server remotely via SSH, install OpenSSH server:

 

After installation, you can start the SSH service:

 

To check if SSH is running:

Enable firewall and allow SSH:

3. Install Apache, PHP, and PHP-FPM

Install Apache Web Server:

Install PHP 7.4 and PHP 8.3:

Enable and start PHP-FPM:

4. Install MySQL Server

5. Install PHPMyAdmin

To manage MySQL through a web interface, you can install PHPMyAdmin:

 


During installation, select Apache as the web server.


To enable PHPMyAdmin in Apache, link the PHPMyAdmin configuration file:

 


Enable the site and restart Apache:


Now, you can access PHPMyAdmin at http://example.com/phpmyadmin (replace example.com with your server's domain or IP).

 

 

IF ANY ISSUE WHEN SETTING PASSWORD OF PHPMYADMIN :

 

6. Configure Apache Virtual Hosts for Multiple PHP Versions

Create configuration for site1.com (PHP 7.4):

Add:

<VirtualHost *:80>

    ServerName site1.com

    DocumentRoot /var/www/site1

    <FilesMatch \.php$>

        SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost"

    </FilesMatch>

</VirtualHost>

Create configuration for site2.com (PHP 8.3):

<VirtualHost *:80>

    ServerName site2.com

    DocumentRoot /var/www/site2

    <FilesMatch \.php$>

        SetHandler "proxy:unix:/run/php/php8.3-fpm.sock|fcgi://localhost"

    </FilesMatch>

</VirtualHost>

Enable sites and restart Apache:

7. Domain Binding in Windows Hosts File

Edit the Windows hosts file:

C:\Windows\System32\drivers\etc\hosts

Add:

192.168.1.100 site1.com

192.168.1.100 site2.com

Now, you can access http://site1.com and http://site2.com in your browser.

 

Introduction to Git

Git is a distributed version control system that allows developers to track and manage changes in their codebase. It helps in collaboration by enabling multiple developers to work on the same project simultaneously without overwriting each other's work.

Git works by storing commits (snapshots) of your project over time, allowing you to revert to previous versions of your project if needed.

Git Credentials

Git requires your username and email to track the commits you make. You can configure this globally or locally for each repository.

1. Setting up Git credentials

git config --global user.name "Your Name"

git config --global user.email "your.email@example.com"

2. Viewing your Git configuration

 

git config --list

Basic Git Commands

1. Initializing a Git repository

 

git init

2. Cloning a repository

 

git clone <repository_url>

3. Checking the status of your repository

git status

4. Adding changes to the staging area

 

git add <filename>    # For a specific file

git add .             # For all files

5. Committing changes

 

git commit -m "Your commit message"

6. Viewing commit history

 

git log

7. Pushing changes to the remote repository

 

git push origin <branch_name>

8. Pulling changes from the remote repository

 

git pull origin <branch_name>

9. Creating a new branch

 

git branch <branch_name>

10. Switching branches

git checkout <branch_name>

11. Merging branches

 

git merge <branch_name>

 


 

Using SSH for Git Authentication

When using SSH (Secure Shell) for Git, you don't need to enter your username and password every time you interact with a remote repository. SSH keys provide a secure way to authenticate without needing to expose your credentials.

1. Generating SSH Keys

ssh-keygen -t rsa -b 4096 -C "your.email@example.com"

2. Adding the SSH key to the SSH agent

 

eval "$(ssh-agent -s)"

ssh-add ~/.ssh/id_rsa

3. Adding your SSH key to GitHub/GitLab

4. Testing SSH Connection

 

This will authenticate your SSH key with GitHub/GitLab.

5. Using SSH URL for Git Remote

When cloning or adding a remote URL, use the SSH format instead of HTTPS:

Conclusion

Git, along with SSH, is a powerful combination for managing codebases and collaborating with other developers. By setting up Git credentials and SSH keys, you streamline the process of pushing, pulling, and managing code changes securely and efficiently.

 


GITHUB ACTION

GitHub Actions can be used to deploy code to a server automatically. It is a CI/CD (Continuous Integration/Continuous Deployment) tool that helps automate workflows like testing, building, and deploying applications.

 

Configure GitHub Actions for Deployment

Modify your .github/workflows/deploy.yml to use the VMware VM's IP:

yaml

name: Deploy to VMware VM

on:

  push:

    branches:

      - main

jobs:

  deploy:

    runs-on: ubuntu-latest

 

    steps:

      - name: Checkout Code

        uses: actions/checkout@v3

 

      - name: Deploy via SSH

        uses: appleboy/ssh-action@v0.1.7

        with:

          host: ${{ secrets.VMWARE_HOST }}

          username: ${{ secrets.VMWARE_USER }}

          key: ${{ secrets.VMWARE_SSH_KEY }}

          script: |

            cd /var/www/html/your_project  # Change to your project path

            git pull origin main

            composer install --no-dev --optimize-autoloader

            php artisan migrate --force

            php artisan cache:clear

            php artisan config:clear

            systemctl restart apache2

 

EXECUTE

git add .github/workflows/deploy.yml

git commit -m "Added GitHub Actions deployment workflow"

git push origin main

 

LINUX SERVICES

 

1. Introduction to Linux Services

What are Services in Linux?

Types of Services in Linux

  1. System Services: Essential for OS functionality (e.g., SSH, Cron, Firewall).

  2. Application Services: Related to specific applications (e.g., Apache, MySQL, Docker).

  3. Network Services: Manage networking functions (e.g., DHCP, DNS, FTP).


2. Managing Services with systemctl & service 

Checking the Status of a Service

systemctl status apache2
service apache2 status

Starting and Stopping Services

systemctl start apache2
systemctl stop apache2

Enabling and Disabling Services (at startup)

systemctl enable apache2
systemctl disable apache2

Restarting and Reloading Services

systemctl restart apache2
systemctl reload apache2

Checking Logs for Debugging

journalctl -u apache2 --no-pager | tail -n 20

3. Common Linux Services and Their Uses 

Service Description Demo Commands
SSH (Secure Shell) Secure remote access sudo systemctl start ssh
Apache/Nginx Web server hosting sudo systemctl start apache2
MySQL/MariaDB Database service sudo systemctl start mysql
Cron Jobs Scheduling tasks crontab -e
Firewall (UFW/Firewalld) Security filtering sudo ufw enable
DNS (BIND) Domain Name Resolution systemctl start named
DHCP Dynamic IP Address Allocation systemctl start dhcpd

Hands-on Demos:

  1. Install Apache/Nginx:

    sudo apt install apache2 -y  # Debian-based
    sudo yum install httpd -y    # RHEL-based
  2. Create and Access a Test HTML Page:

    echo "<h1>Linux Service Demo</h1>" | sudo tee /var/www/html/index.html
    sudo systemctl restart apache2
  3. Start and Secure an SSH Connection:

    sudo systemctl start ssh
    ssh user@localhost
  4. Create a Scheduled Cron Job:

    crontab -e
    # Add: * * * * * echo "Hello, World" >> /tmp/cron_test.log

4. Advanced Service Management (30 min)

Configuring Custom Service Files (.service)

[Unit]
Description=Custom Python Web Service
After=network.target

[Service]
ExecStart=/usr/bin/python3 -m http.server 8080
Restart=always

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable myservice
sudo systemctl start myservice

Monitoring and Debugging Services