Software

What is the first thing to know about software with Linux?

Well, quite simply, software with Linux derives from either command prompt or more typically and widely used, software that you point and click with in a GUI (Graphical User Interface) format.

If you are new to Linux, moving from Windows or macOS or simply don't know what a command prompt is - you will want to use the Graphical User Interface running either GNOME or KDE.

  • Posted on

    How to Install an Apache Web Server Powered by PHP and MySQL on Linux CLI Using Package Managers

    This guide outlines the steps to install Apache, PHP, and MySQL (often referred to as the LAMP stack: Linux, Apache, MySQL, and PHP) on a Linux system using package managers such as APT (for Debian/Ubuntu-based distributions) and DNF (for CentOS/RHEL-based distributions).

    Prerequisites

    • A Linux server (Debian/Ubuntu/CentOS 8+).
    • Root or sudo privileges to install and configure packages.
    • Access to the command line or SSH.

    Step-by-Step Installation:


    Step 1: Update the System

    Before installing any packages, it’s important to ensure that your system is up to date.

    For Debian/Ubuntu (APT)

    sudo apt update
    sudo apt upgrade -y
    

    For CentOS 8+ (DNF)

    sudo dnf update -y
    

    Step 2: Install Apache Web Server

    Apache is the most widely used web server to serve static and dynamic content.

    For Debian/Ubuntu (APT)

    Install Apache with the following command:

    sudo apt install apache2 -y
    

    Enable Apache to start on boot:

    sudo systemctl enable apache2
    

    Start Apache:

    sudo systemctl start apache2
    

    Verify that Apache is running:

    sudo systemctl status apache2
    

    For CentOS 8+ (DNF)

    Install Apache (httpd) using the following:

    sudo dnf install httpd -y
    

    Enable Apache to start on boot:

    sudo systemctl enable httpd
    

    Start Apache:

    sudo systemctl start httpd
    

    Verify that Apache is running:

    sudo systemctl status httpd
    

    To ensure Apache is accessible through the firewall, run:

    sudo firewall-cmd --permanent --add-service=http
    sudo firewall-cmd --reload
    

    Step 3: Install PHP

    Apache alone can serve static content, but to serve dynamic content (such as web applications), we need PHP.

    For Debian/Ubuntu (APT)

    Install PHP and the required Apache module:

    sudo apt install php libapache2-mod-php -y
    

    Restart Apache to load the PHP module:

    sudo systemctl restart apache2
    

    For CentOS 8+ (DNF)

    On CentOS 8+, PHP can be installed from the default CentOS repositories or from the Remi repository if you need a more recent version of PHP. To install PHP from the default CentOS 8+ repositories:

    sudo dnf install php php-mysqlnd php-fpm -y
    

    After installation, restart Apache to apply the PHP configuration:

    sudo systemctl restart httpd
    

    Step 4: Install MySQL (or MariaDB)

    MySQL (or MariaDB, which is a drop-in replacement for MySQL) is needed to store and retrieve data for web applications.

    For Debian/Ubuntu (APT)

    Install MySQL:

    sudo apt install mysql-server -y
    

    Secure the MySQL installation:

    sudo mysql_secure_installation
    

    Start MySQL:

    sudo systemctl start mysql
    

    Enable MySQL to start on boot:

    sudo systemctl enable mysql
    

    Verify MySQL is running:

    sudo systemctl status mysql
    

    For CentOS 8+ (DNF)

    CentOS 8 comes with MariaDB as the default MySQL-compatible database server. To install MariaDB:

    sudo dnf install mariadb-server -y
    

    Start MariaDB:

    sudo systemctl start mariadb
    

    Enable MariaDB to start on boot:

    sudo systemctl enable mariadb
    

    Secure the MariaDB installation:

    sudo mysql_secure_installation
    

    Verify MariaDB is running:

    sudo systemctl status mariadb
    

    Step 5: Verify the Installation of Apache, PHP, and MySQL

    Now that Apache, PHP, and MySQL/MariaDB are installed, it’s important to verify that everything is working correctly.

    Check Apache and PHP Integration

    1. Create a PHP info file to check if PHP is correctly integrated with Apache:
    sudo nano /var/www/html/info.php
    
    1. Add the following PHP code:
    <?php
    phpinfo();
    ?>
    
    1. Save and exit the file (Press CTRL+X, then Y, then Enter).

    2. In your web browser, visit:

    http://localhost/info.php
    

    You should see a page displaying detailed PHP configuration information, confirming that Apache and PHP are working together.

    Check MySQL/MariaDB Connection

    To check if MySQL/MariaDB is working, log into the database:

    sudo mysql -u root -p
    

    Enter your root password when prompted, and if you see the MariaDB/MySQL prompt (MariaDB [(none)]>), then the installation was successful.


    Step 6: Configure Apache to Use PHP

    If you haven’t already, ensure Apache is configured to handle PHP files.

    For Debian/Ubuntu (APT)

    Apache should automatically be configured to use PHP after installing the libapache2-mod-php module. If it's not, you can enable the PHP module manually with:

    sudo a2enmod php7.x  # Replace 7.x with your PHP version
    sudo systemctl restart apache2
    

    For CentOS 8+ (DNF)

    CentOS 8 will automatically configure Apache to work with PHP. If it's not working, you can ensure that PHP is set up with the following command:

    sudo systemctl restart httpd
    

    Step 7: Remove the PHP Info File (Optional)

    After verifying PHP is working, it's a good idea to delete the info.php file for security reasons:

    sudo rm /var/www/html/info.php
    

    Step 8: Additional Configuration (Optional)

    You may want to configure Apache to serve multiple websites or adjust certain PHP settings.

    Set Up Virtual Hosts (Optional)

    If you want to serve multiple websites, create a configuration file for each site.

    1. Create a new configuration file for your site:
    sudo nano /etc/httpd/conf.d/mywebsite.conf  # CentOS
    
    1. Add the virtual host configuration:
    <VirtualHost *:80>
        ServerAdmin webmaster@mywebsite.com
        DocumentRoot /var/www/mywebsite
        ServerName mywebsite.com
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>
    
    1. Create the directory for the site:
    sudo mkdir /var/www/mywebsite
    
    1. Restart Apache to apply the changes:
    sudo systemctl restart httpd  # CentOS
    

    Conclusion

    You now have a fully functional LAMP stack (Apache, PHP, and MySQL/MariaDB) on your Linux system, ready to serve dynamic websites. Here's a recap of what we did:

    • Installed Apache to serve web content.

    • Installed PHP for dynamic content.

    • Installed MySQL/MariaDB for database management.

    • Configured Apache and PHP to work together.

    • Created virtual hosts for managing multiple sites (optional).

    With Apache, PHP, and MySQL/MariaDB running, your server is ready for hosting web applications, whether it's for a simple website or a full-fledged content management system (CMS).

  • Posted on

    Let's explore each of the programming languages and their interpreters in detail. We'll look into the context in which they're used, who typically uses them, what they are used for, and the power they offer. Additionally, I'll suggest starting points for testing each language, and provide an explanation of their benefits and popularity.

    1. Bash

    Context & Usage:

    • Who uses it: System administrators, DevOps engineers, and developers working in Linux or Unix-like environments.

    • What for: Bash is the default shell for Unix-like systems. It’s used for writing scripts to automate tasks, managing system processes, manipulating files, and running system commands.

    • Where it’s used: System administration, automation, DevOps, server management, and batch processing tasks.

    Benefits:

    • Ubiquity: Bash is available by default on almost all Unix-based systems (Linux, macOS), making it indispensable for server-side administration.

    • Powerful scripting capabilities: It allows for process control, file manipulation, regular expressions, and piping commands.

    • Simple yet powerful syntax: Despite being lightweight, it’s capable of handling complex system-level tasks.

    Hello World Example:

    echo "Hello World"
    

    In-Depth Starting Point:

    • Test file manipulation, process management, and simple system automation by scripting tasks like listing files, scheduling jobs, or managing processes.
    # List all files in the current directory
     ls -l
    # Create and manipulate a simple file
    echo "Hello, World" > hello.txt
    cat hello.txt
    

    2. Python

    Context & Usage:

    • Who uses it: Web developers, data scientists, engineers, and researchers.

    • What for: Python is a general-purpose language used for web development, data analysis, machine learning, and automation.

    • Where it’s used: Web development (Django, Flask), data science (Pandas, NumPy), machine learning (TensorFlow, scikit-learn), scripting, and automation.

    Benefits:

    • Readability & simplicity: Python's syntax is clear and easy to understand, making it a great choice for beginners and experienced developers alike.

    • Extensive ecosystem: Python boasts a vast ecosystem of libraries for everything from web frameworks to scientific computing.

    • Community support: Python’s large community ensures a wealth of resources, tutorials, and libraries.

    Hello World Example:

    python3 -c 'print("Hello World")'
    

    In-Depth Starting Point:

    • Python’s interactive shell and script-based execution allow testing of libraries like math, numpy, or pandas right at the Bash prompt.
    # Using Python's interactive shell to calculate something
    python3 -c 'import math; print(math.sqrt(16))'
    

    3. Perl

    Context & Usage:

    • Who uses it: Web developers, network administrators, and those involved in text processing, bioinformatics, and automation.

    • What for: Perl is primarily used for text processing, systems administration, and web development (CGI scripts).

    • Where it’s used: Log file parsing, web backends, network scripts, and text-based data manipulation.

    Benefits:

    • Text Processing: Perl excels at regular expressions and text manipulation, making it the go-to tool for tasks like log parsing and configuration file handling.

    • CPAN: Perl has a massive collection of reusable code and modules via the Comprehensive Perl Archive Network (CPAN).

    Hello World Example:

    perl -e 'print "Hello World\n";'
    

    In-Depth Starting Point:

    • Test regular expressions or string manipulations by working with log files.
    # Extracting IP addresses from a log file using Perl
    perl -ne 'print if /(\d+\.\d+\.\d+\.\d+)/' access.log
    

    4. Ruby

    Context & Usage:

    • Who uses it: Web developers, particularly those using Ruby on Rails for web applications.

    • What for: Ruby is mainly used for web development, but can also be used for automation scripts, GUI applications, and testing.

    • Where it’s used: Web applications, automation tasks, API development.

    Benefits:

    • Ruby on Rails: The Ruby on Rails framework has made Ruby a popular choice for rapid web development. It follows the principle of “convention over configuration,” speeding up development.

    • Elegant syntax: Ruby’s syntax is designed to be both expressive and easy to read.

    Hello World Example:

    ruby -e 'puts "Hello World"'
    

    In-Depth Starting Point:

    • Ruby can be tested interactively or through simple script execution.
    # Simple Ruby script to fetch the contents of a URL
    ruby -e 'require "net/http"; puts Net::HTTP.get(URI("http://example.com"))'
    

    5. PHP

    Context & Usage:

    • Who uses it: Web developers, especially those working on server-side scripting for web applications.

    • What for: PHP is commonly used for dynamic web page generation and server-side scripting.

    • Where it’s used: Websites (especially CMSs like WordPress), backend development, and APIs.

    Benefits:

    • Web-centric: PHP was designed specifically for web development, with powerful features for working with databases and HTML generation.

    • Ubiquity in web hosting: PHP is widely supported by web hosting providers and powers a significant portion of the web.

    Hello World Example:

    php -r 'echo "Hello World\n";'
    

    In-Depth Starting Point:

    • Test basic PHP functionality and integration with web servers.
    # A simple PHP script to output current time
    php -r 'echo "Current time: " . date("Y-m-d H:i:s") . "\n";'
    

    6. JavaScript (Node.js)

    Context & Usage:

    • Who uses it: Full-stack developers, backend developers, and those working on real-time applications.

    • What for: JavaScript (Node.js) allows JavaScript to be used on the server-side to build scalable, event-driven applications.

    • Where it’s used: Web servers, real-time applications (chat, notifications), APIs, microservices.

    Benefits:

    • Single language for full-stack: Node.js allows JavaScript to be used both on the client-side (in the browser) and server-side (on the backend).

    • Non-blocking I/O: Node.js is known for its asynchronous, non-blocking I/O model, making it highly efficient for I/O-heavy applications.

    Hello World Example:

    node -e 'console.log("Hello World");'
    

    In-Depth Starting Point:

    • Node.js can be tested for its asynchronous capabilities with event-driven scripts.
    # A simple Node.js script to log current time every second
     node -e 'setInterval(() => console.log(new Date()), 1000);'
    

    7. C

    Context & Usage:

    • Who uses it: Systems programmers, embedded system developers, and developers working on performance-critical applications.

    • What for: C is used for low-level system programming, embedded systems, and developing software that interacts directly with hardware.

    • Where it’s used: Operating systems, embedded systems, device drivers, real-time applications.

    Benefits:

    • Performance: C is a low-level language that provides fine control over system resources, making it the language of choice for high-performance applications.

    • Portability: Code written in C can be compiled to run on a wide variety of systems, from embedded devices to supercomputers.

    Hello World Example:

    #include <stdio.h>
    int main() {
        printf("Hello World\n");
        return 0;
    }
    

    In-Depth Starting Point:

    • To test C, you would need a C compiler (e.g., GCC) to compile and run the code.
    gcc hello.c -o hello && ./hello
    

    8. C++

    Context & Usage:

    • Who uses it: Systems programmers, game developers, and developers of performance-intensive applications.

    • What for: C++ is used for object-oriented programming and systems-level applications that require high performance.

    • Where it’s used: Game engines, desktop applications, real-time systems, performance-critical software.

    Benefits:

    • Object-Oriented Programming: C++ adds support for classes and objects to C, making it easier to manage large, complex codebases.

    • Performance: Like C, C++ offers fine-grained control over system resources, making it ideal for real-time applications.

    Hello World Example:

    #include <iostream>
    int main() {
        std::cout << "Hello World" << std::endl;
        return 0;
    }
    

    In-Depth Starting Point:

    • Compile and run C++ code for performance testing.
    g++ hello.cpp -o hello && ./hello
    

    9. Java

    Context & Usage:

    • Who uses it: Enterprise developers, Android developers, and backend system developers.

    • What for: Java is primarily used for building large-scale enterprise applications, Android apps, and server-side components.

    • Where it’s used: Enterprise applications, Android apps, large-scale web servers.

    Benefits:

    • Cross-Platform: Java’s “write once, run anywhere” philosophy allows Java applications to run on any system with a JVM (Java Virtual Machine).

    • Rich Ecosystem: Java has a vast ecosystem of libraries and frameworks, including Spring for backend systems and Android for mobile apps.

    Hello World Example:

    public class HelloWorld {
        public static void main(String[] args) {
            System.out.println("Hello World");
        }
    }
    

    In-Depth Starting Point:

    • Compile and run Java code to explore object-oriented principles.
    javac HelloWorld.java && java HelloWorld
    

    Next is a table with the name of the language, date of inception, and a corresponding Hello World example:

    Language Date of Inception Hello World Example
    Bash 1989 echo "Hello World"
    Python 1991 python3 -c 'print("Hello World")'
    Perl 1987 perl -e 'print "Hello World\n";'
    Ruby 1995 ruby -e 'puts "Hello World"'
    PHP 1994 php -r 'echo "Hello World\n";'
    JavaScript (Node.js) 2009 node -e 'console.log("Hello World");'
    C 1972 printf("Hello World\n");
    C++ 1983 std::cout << "Hello World" << std::endl; return 0;
    Java 1995 System.out.println("Hello World");
    Go 2009 fmt.Println("Hello World") }
    Rust 2010 fn main() { println!("Hello World"); }
    Lua 1993 lua -e 'print("Hello World")'
    Haskell 1990 main = putStrLn "Hello World"
    Shell Script 1989 echo "Hello World"
    AWK 1977 awk 'BEGIN {print "Hello World"}'
    Tcl 1988 tclsh <<< 'puts "Hello World"'
    R 1993 Rscript -e 'cat("Hello World\n")'
    Kotlin 2011 println("Hello World")
    Swift 2014 print("Hello World")
    Julia 2012 julia -e 'println("Hello World")'

    Notes:

    • Bash: Inception was around 1989 by Brian Fox. It's a shell scripting language, often used for system administration tasks.
    • Python: Created by Guido van Rossum in 1991. Known for its simplicity and readability, Python is widely used in web development, data analysis, and scripting.
    • Perl: Developed by Larry Wall in 1987. Known for text processing and used heavily in system administration and web development.
    • Ruby: Created by Yukihiro Matsumoto in 1995. Ruby is famous for its elegant syntax and the Ruby on Rails framework for web development.
    • PHP: Created by Rasmus Lerdorf in 1994, primarily for web development to build dynamic content on websites.
    • JavaScript (Node.js): JavaScript was created in 1995, but Node.js, a runtime environment, was created by Ryan Dahl in 2009. Used for building scalable server-side applications.
    • C: Developed by Dennis Ritchie in 1972. It remains one of the most influential programming languages, used for system programming, embedded systems, and applications that require high performance.
    • C++: Developed by Bjarne Stroustrup in 1983. It builds on C and adds object-oriented programming features. It's used for game development, embedded systems, and high-performance applications.
    • Java: Developed by James Gosling at Sun Microsystems in 1995. Java is widely used for enterprise-level applications, Android development, and large-scale systems.
    • Go: Created by Google in 2009. Known for its simplicity, speed, and concurrency features, Go is widely used for web servers, distributed systems, and cloud computing.
    • Rust: Created by Mozilla in 2010. Rust is known for its memory safety and performance, used in system programming, and other high-performance applications.
    • Lua: Developed by Roberto Ierusalimschy in 1993. Lua is a lightweight scripting language commonly embedded in games and applications for configuration or scripting.
    • Haskell: Created in 1990, it's a purely functional programming language used for research, academic purposes, and systems requiring high levels of mathematical computation.
    • Shell Script: A type of script commonly used in Unix-like systems to automate tasks, write system maintenance scripts, and handle administrative tasks.
    • AWK: Developed in 1977, AWK is a pattern scanning and processing language used for text and data processing tasks.
    • Tcl: Created by John Ousterhout in 1988. Known for its use in embedded systems, testing, and automation.
    • R: Created by Ross Ihaka and Robert Gentleman in 1993, R is used primarily for statistical computing and data analysis.
    • Kotlin: Developed by JetBrains in 2011, Kotlin is a modern, statically-typed language that runs on the Java Virtual Machine (JVM) and is now heavily used for Android development.
    • Swift: Created by Apple in 2014, Swift is a modern language used for iOS and macOS application development.
    • Julia: Created in 2012 for high-performance numerical and scientific computing. It's widely used in data science, machine learning, and large-scale computational tasks.

    Each of these languages has evolved in different directions based on the needs of developers in various industries, from system-level programming and web development to data analysis and machine learning.

    Conclusion:

    Each language comes with its own set of strengths, contexts, and use cases. Whether it's the system-level control of C, the ease of web development in Python or Ruby, or the performance of C++ and Rust, these languages offer rich ecosystems and excellent developer support. By testing them at the Bash prompt, you can start to get a feel for each language's capabilities, from system automation with Bash to interactive and asynchronous tasks with Node.js. Each interpreter brings something unique to the table, making them essential tools for different domains in software development.

  • Posted on

    If you’ve ever used a Linux operating system used on most Virtual Private Servers, you may have heard of bash. It’s a Unix shell that reads and executes various commands.

    What Is Bash?

    Bash, short for Bourne-Again Shell, is a Unix shell and a command language interpreter. It reads shell commands and interacts with the operating system to execute them.

    Why Use Bash Scripts?

    Bash scripts can help with your workflow as they compile many lengthy commands into a single executable script file. For example, if you have multiple commands that you have to run at a specific time interval, you can compile a bash script instead of typing out the commands manually one by one. You then execute the script directly, when it’s necessary.

    Pro Tip Linux has a bash shell command manual. Type man command to find descriptions of all the technical terms and input parameters.

    Get Familiar With Bash Commands

    Bash is available on almost all types of Unix-based operating systems and doesn’t require a separate installation. You will need a Linux command prompt, also known as the Linux terminal. On Windows you would use something like PuTTy. It’s a program that contains the shell and lets you execute bash scripts. 

    1. Comments

    Comments feature a description on certain lines of your script. The terminal doesn’t parse comments during execution, so they won’t affect the output.

    There are two ways to add comments to a script. The first method is by typing # at the beginning of a single-line comment. # Command below prints a Hello World text echo “Hello, world!”

    2. Variables

    Variables are symbols that represent a character, strings of characters, or numbers. You only need to type the variable name in a command line to use the defined strings or numbers.

    To assign a variable, type the variable name and the string value like here: testvar=“This is a test variable”

    In this case, testvar is the variable name and This is a test variable is the string value. When assigning a variable, we recommend using a variable name that’s easy to remember and represents its value.

    To read the variable value in the command line, use the $ symbol before the variable name. Take a look at the example below:

    testvar=“This is a test variable”
    echo $testvar
    

    In order to let the user enter the variable contents use:

    read testvar
    echo $testvar
    

    3. Functions

    A function compiles a set of commands into a group. If you need to execute the command again, simply write the function instead of the whole set of commands.

    There are several ways of writing functions. The first way is by starting with the function name and following it with parentheses and brackets:

    function_name () {
        first command
        second command
    }
    

    Or, if you want to write it in a single line: function_name () { first command; second command; }

    4. Loops

    Loop bash commands are useful if you want to execute commands multiple times. There are three types of them you can run in bash – for, while, and until. The for loop runs the command for a list of items:

    for item in [list]
    do
        commands
    done
    

    The following example uses a for loop to print all the days of the week:

    for days in Monday Tuesday Wednesday Thursday Friday Saturday Sunday
    do
        echo “Day: $days”
    done
    

    On line 2, “days” automatically becomes a variable, with the values being the day names that follow. Then, in the echo command, we use the $ symbol to call the variable values.

    The output of that script will be as follows:

    Day: Monday
    Day: Tuesday
    Day: Wednesday
    Day: Thursday
    Day: Friday
    Day: Saturday
    Day: Sunday
    

    Notice that even with just one command line in the loop script, it prints out seven echo outputs.

    The next type of loop is while. The script will evaluate a condition. If the condition is true, it will keep executing the commands until the output no longer meets the defined condition.

    while [condition]
        do
    commands
    done
    

    5. Conditional Statements

    Many programming languages, including bash, use conditional statements like if, then, and else for decision-making. They execute commands and print out outputs depending on the conditions. The if statement is followed by a conditional expression. After that, it’s followed by then and the command to define the output of the condition. The script will execute the command if the condition expressed in the if statement is true.

    However, if you want to execute a different command if the condition is false, add an else statement to the script and follow it with the command.

    Let’s take a look at simple if, then, and else statements. Before the statement, we will include a variable so the user can input a value:

    echo “Enter a number”
    read num
    if [[$num -gt 10]]
    then
    echo “The number is greater than 10”
    else
    echo “The number is not greater than 10”
    

    OK, so that's it. The 5 building blocks of Bash in plain English. Simple, right?!