Category Archives: Debian

Craft CMS on Debian 12

How to Install Craft CMS on Debian 12

Craft CMS is a popular content management system (CMS) that allows users to create and manage websites and digital experiences. It is known for its flexibility, powerful features, and user-friendly interface. Craft CMS is developed by Pixel & Tonic, a software development company.

In terms of performance and scalability, Craft CMS is designed to handle websites of all sizes, from small blogs to large enterprise solutions. It utilizes a modern technology stack and provides caching mechanisms to optimize page loading times.

The Craft Plugin Store offers a wide range of plugins for various purposes, such as e-commerce, SEO optimization, analytics, and integrations with third-party services.

In this tutorial, we will guide you through the process of installing Craft CMS on Debian 12 OS.

Step 1: Update Operating System

The first step is to ensure that your system is up-to-date. You can do this by running the following command:

# apt update && sudo apt upgrade

Also, install necessary packages.

# apt install sudo nano wget unzip zip

Now create a new non-root user account with sudo privileges and switch to it.

# /usr/sbin/adduser craftcms

# /usr/sbin/usermod -aG sudo craftcms

# su - craftcms

NOTE: You can replace craftcms with your username.

Step 2: Install Nginx Web Server

Craft CMS requires a web server to run, and we will be using the Nginx web server in this tutorial. To install Nginx, run the following command:

$ sudo apt install nginx

You can start the Nginx service and configure it to run on startup by entering the following commands:

$ sudo systemctl start nginx
$ sudo systemctl enable nginx

Verify the status of the Nginx service using systemctl status command:

$ sudo systemctl status nginx

Step 3: Install PHP and PHP extensions for Craft CMS

To install PHP and additional PHP modules to support Craft CMS, run the following command:

$ sudo apt install php php-cli php-common php-json php-gmp php-fpm php-xmlrpc php-bcmath php-imagick php-curl php-zip php-gd php-mysql php-xml php-mbstring php-xmlrpc php-intl

Verify if PHP is installed.

php -v
Output:
PHP 8.2.7 (cli) (built: Jun  9 2023 19:37:27) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.7, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.7, Copyright (c), by Zend Technologies

After installing all the packages, edit the php.ini file:

$ sudo nano /etc/php/8.2/fpm/php.ini

Change the following settings per your requirements:

max_execution_time = 300
memory_limit = 512M
post_max_size = 128M
upload_max_filesize = 128M
date.timezone = America/Chicago

To implement the changes, restart the php-fpm service:

$ sudo systemctl restart php8.2-fpm

Step 4: Install Composer dependency manager

To install Composer, run the following commands:

$ sudo curl -sS https://getcomposer.org/installer | php
$ sudo mv composer.phar /usr/local/bin/composer

Verify that Composer has been installed successfully by running the following command:

$ composer --version
Composer version 2.5.8 2023-06-09 17:13:21

Step 5: Install MariaDB database server

To install the MariaDB database server, run the following command:

$ sudo apt install mariadb-server mariadb-client

Verify the status of the MariaDB service using systemctl status command:

$ sudo systemctl status mariadb

Step 6: Create a New Database for Craft CMS

Once you have installed MariaDB, you’ll need to create a new database and user for Craft CMS to use.

To do this, log in to your MariaDB server using the following command:

$ sudo mysql -u root

Run the following commands to create a new database and user:

MariaDB [(none)]> CREATE DATABASE craftcms;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON craftcms.* TO 'craft'@'localhost' IDENTIFIED BY 'password';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

Note: Make sure to replace 'password' with a strong password of your choice.

Step 7: Download and Install Craft CMS

Create a new directory for your Craft CMS installation using the following command:

$ sudo mkdir /var/www/craftcms

Change ownership of the /var/www/craft directory to the craftcmsuser.

$ sudo chown -R craftcms:craftcms /var/www/craftcms

Then download the latest stable release of Craft CMS from the command line:

$ cd /var/www/craftcms
$ composer create-project craftcms/craft .

You will be asked to provide database details, admin username, password, site URL as shown below:

Are you ready to begin the setup? (yes|no) [no]:yes
Which database driver are you using? (mysql or pgsql) [mysql] mysql
Database server name or IP address: [127.0.0.1] 127.0.0.1
Database port: [3306] 3306
Database username: [root] craft
Database password: password
Database name: craftcms
Database table prefix:
Install Craft now? (yes|no) [yes]:yes

Username: [admin] admin
Email: admin@your-domain.com
Password:
Confirm:
Site name: Your Website
Site URL: http://your-domain.com
Site language: [en-US] 

Change ownership of the /var/www/craftcms directory to www-data.

$ sudo chown -R www-data:www-data /var/www/craftcms

Step 8: Configure Nginx for Craft CMS

Run the commands below to create a new VirtualHost file called craftcms in the /etc/nginx/conf.d/ directory.

$ sudo nano /etc/nginx/conf.d/craftcms.conf

Paste the content as shown below:

server {

  listen 80;

  server_name your-domain.com www.your-domain.com;
  root /var/www/craftcms/web;
  index index.html index.htm index.php;
  charset utf-8;

  location / {
    try_files $uri/index.html $uri $uri/ /index.php?$query_string;
  }

  location ~ [^/]\.php(/|$) {
    try_files $uri $uri/ /index.php?$query_string;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_param HTTP_PROXY "";
  }
}

Remember to replace your-domain.com with the domain name of your server.

Save and exit the configuration file.

To implement the changes, restart Nginx webserver:

$ sudo systemctl restart nginx

Step 9: Access Craft CMS Web Interface

Open your web browser and type the URL http://your-domain.com. You should see the welcome screen:

To access Craft’s administrative interface type the URL http://your-domain.com/admin you should see the login page:

Provide your admin credential and click on the Sign in button, you should see the Craft CMS dashboard in the following page:

Comments and Conclusion

Congratulations! You have successfully installed Craft CMS with Nginx on Debian 12 OS. You can now create your own website easily using Craft CMS.

For additional help or useful information, we recommend you to check  the official Craft CMS documentation.

How to Install Elgg on Debian 12

Elgg is an open-source social networking platform that allows users to create and manage their own social networks and communities.

It provides a flexible architecture that allows developers to extend and customize its functionality according to their specific needs. Elgg also supports the creation of plugins and themes, enabling further customization and integration with other systems.

In this tutorial, we will show you how to install Elgg on Debian 12 OS.

Step 1: Update Operating System

Update your Debian 12 operating system to the latest version with the following command:

# apt update && apt upgrade

Step 2: Install Apache webserver

You can install it via apt package manager by executing the following command.

# apt install apache2

Verify the status of the Apache service using systemctl status command:

# systemctl status apache2

Output:

 apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; preset: enabled)
     Active: active (running)
       Docs: https://httpd.apache.org/docs/2.4/
   Main PID: 3682 (apache2)
      Tasks: 55 (limit: 2273)
     Memory: 8.6M
        CPU: 32ms
     CGroup: /system.slice/apache2.service
             ├─3682 /usr/sbin/apache2 -k start
             ├─3684 /usr/sbin/apache2 -k start
             └─3685 /usr/sbin/apache2 -k start

Step 3: Install PHP and PHP extensions for Elgg

To install PHP and additional PHP modules to support Elgg, run the following command:

# apt install php php-cli php-common libapache2-mod-php php-curl php-zip php-gd php-mysql php-xml php-mbstring php-xmlrpc php-intl

Verify if PHP is installed.

php -v
Output:
PHP 8.2.7 (cli) (built: Jun  9 2023 19:37:27) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.7, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.7, Copyright (c), by Zend Technologies

After installing all the packages, edit the php.ini file:

# nano /etc/php/8.2/apache2/php.ini

Change the following settings per your requirements:

max_execution_time = 300
memory_limit = 512M
post_max_size = 128M
upload_max_filesize = 128M
date.timezone = America/Chicago

To implement the changes, restart Apache webserver:

# systemctl restart apache2

Step 4: Install MariaDB and create a database

To install MariaDB run the following command:

# apt install mariadb-server mariadb-client

Verify the status of the MariaDB service using systemctl status command:

# systemctl status mariadb

Output:

 mariadb.service - MariaDB 10.11.3 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; preset: enabled)
     Active: active (running)
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
   Main PID: 16734 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 12 (limit: 2273)
     Memory: 203.0M
        CPU: 464ms
     CGroup: /system.slice/mariadb.service
             └─16734 /usr/sbin/mariadbd

By default, MariaDB is not hardened. You can secure MariaDB using the mysql_secure_installation script.

# mysql_secure_installation

Configure it like this:

- Enter current password for root (enter for none): Enter
- Switch to unix_socket authentication [Y/n] Y
- Change the root password? [Y/n] Y
- Remove anonymous users? [Y/n] Y
- Disallow root login remotely? [Y/n] Y
- Remove test database and access to it? [Y/n] Y
- Reload privilege tables now? [Y/n] Y

Now run the command below to log in to the MariaDB shell.

# mysql -u root -p

Once you are logged in to your database server you need to create a database for the Elgg installation:

MariaDB [(none)]> CREATE DATABASE elgg;
MariaDB [(none)]> CREATE USER 'elgg'@'localhost' IDENTIFIED BY 'Str0ngPass2F';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON elgg. * TO 'elgg'@'localhost';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

Step 5: Download Elgg

The latest version of Elgg is available to download from the official website. As of writing this tutorial, the latest version available is 5.0.1.

# wget https://elgg.org/download/elgg-5.0.1.zip

Then extract file into the folder /var/www/ with the following command:

# unzip elgg-5.0.1.zip -d /var/www/

Rename the extracted directory:

# mv /var/www/elgg-5.0.1 /var/www/elgg/

Create a data directory:

# mkdir /var/www/data/

Then enable permission for the Apache webserver user to access the files:

# chown -R www-data:www-data /var/www/data/
# chown -R www-data:www-data /var/www/elgg/

Step 6: Configure Apache for Elgg

Run the commands below to create a new VirtualHost file called elgg in the /etc/apache2/sites-available/ directory.

# nano /etc/apache2/sites-available/elgg.conf

Paste the content as shown below:

 <VirtualHost *:80>
    ServerAdmin admin@your-domain.com
    DocumentRoot /var/www/elgg/
    
    ServerName your-domain.com
    ServerAlias www.your-domain.com

    <Directory /var/www/elgg/> 
        Options FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory> 

    ErrorLog /var/log/apache2/your-domain.com-error_log
    CustomLog /var/log/apache2/your-domain.com-access_log common

 </VirtualHost>

Remember to replace your-domain.com with the domain name of your server.

Save and exit the configuration file.

Then enable the "rewrite" module in Apache:

# a2enmod rewrite

To enable this site run the command:

# ln -s /etc/apache2/sites-available/elgg.conf /etc/apache2/sites-enabled/elgg.conf

To implement the changes, restart Apache webserver:

# systemctl restart apache2

Step 7: Install free Let’s Encrypt SSL certificate

First we need to install the Certbot client which is used to create Let’s Encrypt certificates:

# apt install certbot python3-certbot-apache

To get the SSL certificate using the Certbot, type the command given below:

# certbot --apache -d your-domain.com -d www.your-domain.com

If the SSL certificate is successfully obtained, certbot displays a message to show the configuration was successful:

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/your-domain.com.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/your-domain.com/privkey.pem
   Your cert will expire on 2023-09-02. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot
   again. To non-interactively renew *all* of your certificates, run
   "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

Now, you have successfully installed SSL on your website.

Step 8: Access Elgg Web Interface

Open your web browser and type the URL https://your-domain.com. You should see the following page:

Click on the Next button.

The installer will then check the requirements. Once all checks are passed, click on the Next button.

After that, you will have to write the credentials from the database, data directory, and site URL and then click on the Next button:

Then, you have to set up your site name and email and then click on the Next button:

Provide your admin username, password, email and click on the Next button. Once the installation has been completed, you should see the following page:

Click on the Go to site button you should see your administration panel:

Comments and Conclusion

Congratulations! You have successfully installed Elgg. Thanks for using this tutorial for installing Elgg on your Debian 12 OS.

For additional help or useful information, we recommend you to check  the official Elgg documentation.

How to Install Elasticsearch 8 on Debian 11

Elasticsearch is a highly scalable and distributed open-source full-text search and analytics engine tool. It is designed to store, search, and analyze large volumes of data in real-time, making it a popular tool for a variety of use cases such as log analytics, e-commerce product search, and security analytics.

Elasticsearch uses a document-oriented data model, which means that it stores data in JSON documents that can be easily searched and analyzed. It also provides a powerful query language called Elasticsearch Query DSL, which allows users to perform complex queries on the data stored in the engine.

In this tutorial, we will show you how to install Elasticsearch on Debian 11.

Step 1: Update Operating System

Update your Debian 11 operating system to make sure all existing packages are up to date:

# apt update && apt upgrade

Also, install:

# apt install curl wget gnupg apt-transport-https

Step 2: Add Elasticsearch Repository

By default, Elasticsearch is not included in the Debian 11 default repository. So you will need to add the Elasticsearch repository to APT.

First, import the Elasticsearch GPG key.

# wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor -o /usr/share/keyrings/elasticsearch-keyring.gpg

Then add the Elasticsearch repository.

# echo "deb [signed-by=/usr/share/keyrings/elasticsearch-keyring.gpg] https://artifacts.elastic.co/packages/8.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-8.x.list

Once you are done, update the repository with the following command:

# apt update

Step 3: Install and Configure Elasticsearch

Now, you can install the Elasticsearch using the following command:

# apt install elasticsearch

After installation is completed, edit Elasticsearch configuration file “/etc/elasticsearch/elasticsearch.yml”:

# nano /etc/elasticsearch/elasticsearch.yml

Add the following content:

cluster.name: LinuxTuto
node.name: Debian 11
path.data: /var/lib/elasticsearch
network.host: 127.0.0.1 
xpack.security.enabled: false

Then start and enable the service.

# systemctl start elasticsearch
# systemctl enable elasticsearch

To confirm the status of the service of Elasticsearch, run the command:

$ sudo systemctl status elasticsearch.service
 elasticsearch.service - Elasticsearch
Loaded: loaded (/lib/systemd/system/elasticsearch.service; enabled; vendor preset: enabled)
Active: active (running)
Docs: https://www.elastic.co
Main PID: 73979 (java)
Tasks: 100 (limit: 2301)
Memory: 1.3G
CPU: 53.939s
CGroup: /system.slice/elasticsearch.service
├─73979 /usr/share/elasticsearch/jdk/bin/java -Xms4m -Xmx64m -XX:+UseSerialGC -Dcli.name=server -Dcli.script=/usr/share/elasticsearch/bin/elast>
├─74040 /usr/share/elasticsearch/jdk/bin/java -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -Djava.security.manage>
└─74063 /usr/share/elasticsearch/modules/x-pack-ml/platform/linux-x86_64/bin/controller

Step 4: Test Elasticsearch

To verify that Elasticsearch is running correctly, you can use the curl command:

# curl -X GET "localhost:9200/"

If Elasticsearch is working properly, the result should be like this:

{
  "name" : "Debian 11",
  "cluster_name" : "LinuxTuto",
  "cluster_uuid" : "ezWPhn_fQLS5dcSiexroQA",
  "version" : {
    "number" : "8.7.0",
    "build_flavor" : "default",
    "build_type" : "deb",
    "build_hash" : "09520b59b6bc1057340b55750186466ea715e30e",
    "build_date" : "2023-03-27T16:31:09.816451435Z",
    "build_snapshot" : false,
    "lucene_version" : "9.5.0",
    "minimum_wire_compatibility_version" : "7.17.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "You Know, for Search"
}

This means that Elasticsearch is active and running on your server.

Step 5: Uninstall Elasticsearch

Run the following script to remove Elasticsearch from your system.

# apt remove elasticsearch

Comments and Conclusion

In this tutorial we have installed the free version which is released under the Elastic license. You can check the Subscriptions page for more information about Elastic license levels.

For additional help or useful information, you can check the official Elasticsearch Documentation.

If you have any questions please leave a comment below.

How to Install PostgreSQL 15 on Debian 11

PostgreSQL also known as Postgres, is a free and open source object-relational database system that runs on Client-Server architecture. It is one of the leading database servers used for production servers. DevOps use it as an alternative to MariaDB.

In this guide we are going to install PostgreSQL 15 in Debian 11.

1. Update Operating System

Update your Debian 11 operating system to make sure all existing packages are up to date:

# apt update && sudo apt upgrade -y

2. Install PostgreSQL 15 using the official repository

PostgreSQL is available in the default Debian repositories but the available versions are not up to date.

To get the latest packages of PostgreSQL, you must add the official repo of PostgreSQL.

First, install all required dependencies by running the following command:

# apt-get install wget sudo curl gnupg2 -y

After installing all the dependencies, create the file repository configuration with the following command:

# sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

Now import the repository signing key by using the following command:

# wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

Update your local package index with the following command:

# apt -y update

Now you can run the following command to install the latest version of the PostgreSQL server:

# apt-get install postgresql-15 -y

After the successful installation, start the PostgreSQL service and enable it to start after the system reboot:

# systemctl start postgresql
# systemctl enable postgresql

Verify that is active and running on your server:

# systemctl status postgresql
Output
● postgresql.service - PostgreSQL RDBMS
     Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
     Active: active (exited)
   Main PID: 7543 (code=exited, status=0/SUCCESS)
      Tasks: 0 (limit: 2300)
     Memory: 0B
        CPU: 0
     CGroup: /system.slice/postgresql.service

By default, PostgreSQL listens on port 5432. You can check it with the following command:

# ss -antpl | grep 5432

You will get the PostgreSQL listening port in the following output:

LISTEN 0      244             127.0.0.1:5432       0.0.0.0:*    users:(("postgres",pid=7525,fd=6))
LISTEN 0      244                 [::1]:5432          [::]:*    users:(("postgres",pid=7525,fd=5))

You can also check the version using the following command:

# sudo -u postgres psql -c "SELECT version();"

You will get the version in the following output:

                                                           version
-----------------------------------------------------------------------------------------------------------------------------
 PostgreSQL 15.0 (Debian 15.0-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
(1 row)

3. Logging into PostgreSQL

To access your PostgreSQL server, you must log in as a Postgres user. To do this run the following command:

# su postgres

Now you can access your PostgreSQL shell with the following command:

$ psql

In your output you will see:

Output
psql (15.0 (Debian 15.0-1.pgdg110+1))
Type "help" for help.

postgres=#

Once you have accessed the command shell of Postgres, you can now use SQL queries to perform several database-related operations.

To set the Postgres pasword, run the following command:

ALTER USER postgres PASSWORD 'password';

To create a database named test, run the following command:

CREATE DATABASE test;

To list all databases, run the following command:

\l

You should see all databases in the following output:

To switch the database to test, run the following command:

\c test

To create a table (e.g accounts), run the following command:

CREATE TABLE accounts (
	user_id serial PRIMARY KEY,
	username VARCHAR ( 50 ) UNIQUE NOT NULL,
	password VARCHAR ( 50 ) NOT NULL,
	email VARCHAR ( 255 ) UNIQUE NOT NULL,
	created_on TIMESTAMP NOT NULL,
        last_login TIMESTAMP 
);

To list all tables, run the following command:

\dt

You should see all tables in the following output:

          List of relations
 Schema |   Name   | Type  |  Owner
--------+----------+-------+----------
 public | accounts | table | postgres
(1 row)<

To exit from the shell, run the following command:

exit

4. Backup and Restore a Single Database

You can back up and restore a single database using the pg_dump utility.

For example, to back up a single database named test and generate a backup file named test_backup.sql, run the following command:

su - postgres
pg_dump -d test -f test_backup.sql

You can also restore a single database using psql command.

For example, to restore a single database named test from a backup file named test_backup.sql, run the following command:

su - postgres
psql -d test -f test_backup.sql

Comments and Conclusion

At this point, you learn to set up PostgreSQL 15 on Debian 11.  If you need more information, or have any questions, just comment below and we will be glad to assist you!

Check below for some of our other articles.

How to Install Moodle on Debian 11

Moodle is a popular, free, and open-source Course Management system based on PHP released under the GNU General Public License.

The Moodle platform is highly customizable and takes a modular approach to features, so it is extensible and adaptable to your needs. It is probably most popular open source learning management platform available today.

In this tutorial, we will show you how to install Moodle on your Debian 11 OS.

Step 1: Update Operating System

Update and upgrade the system repositories to make sure all existing packages are up to date:

$ sudo apt update && sudo apt upgrade

Step 2: Install Apache webserver

Apache web server is available on the Debian repository and can be installed via apt package manager by executing the following command:

$ sudo apt install apache2

You can start the Apache service and configure it to run on startup by entering the following commands:

$ sudo systemctl start apache2
$ sudo systemctl enable apache2

Verify the status of the Apache service using systemctl status command:

$ sudo systemctl status apache2

Output:

 apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running)
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 459 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 666 (apache2)
      Tasks: 6 (limit: 2301)
     Memory: 24.3M
        CPU: 439ms
     CGroup: /system.slice/apache2.service
             ├─666 /usr/sbin/apache2 -k start
             ├─677 /usr/sbin/apache2 -k start
             ├─678 /usr/sbin/apache2 -k start
             ├─679 /usr/sbin/apache2 -k start
             ├─680 /usr/sbin/apache2 -k start
             └─681 /usr/sbin/apache2 -k start

You can test to make sure everything is working correctly by navigating to:

http://your-IP-address

If everything is configured properly, you should be greeted by the Apache2 Debian Default Page, as seen below.

Step 3: Install PHP and PHP extensions for Moodle

By default, Debian 11 comes with PHP version 7.4.

You can install PHP and required PHP extensions using the following command:

$ sudo apt install php libapache2-mod-php php-iconv php-intl php-soap php-zip php-curl php-mbstring php-mysql php-gd php-xml php-pspell php-json php-xmlrpc

Verify if PHP is installed.

php -v
Output: PHP 7.4.28 (cli) (built: Feb 17 2022 16:17:19) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.28, Copyright (c), by Zend Technologies

Step 4: Install MariaDB

We will use MariaDB as the database system for Moodle (Moodle supports MariaDB/MySQL and PostgreSQL).

You can install MariaDB with the following command:

$ sudo apt install mariadb-server mariadb-client

The commands below can be used to stop, start and enable MariaDB service to start automatically at the next boot:

$ sudo systemctl start mariadb
$ sudo systemctl stop mariadb
$ sudo systemctl enable mariadb

Also, you can verify the status of the MariaDB service using systemctl status command:

$ sudo systemctl status mariadb

Output:

 mariadb.service - MariaDB 10.5.15 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
     Active: active (running)
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
   Main PID: 16987 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 8 (limit: 2287)
     Memory: 63.0M
        CPU: 1.403s
     CGroup: /system.slice/mariadb.service
             └─16987 /usr/sbin/mariadbd

Then open the MariaDB default configuration file:

$ sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf

Under ‘[mysqld]‘ line, paste the following configuration:

default_storage_engine = innodb
innodb_file_per_table = 1
innodb_file_format = Barracuda

Save and exit, then restart MariaDB service:

$ sudo systemctl restart mariadb

Step 5: Create Database

Log into the MariaDB prompt:

$ sudo  mysql -u root

To create a database, database user, and grant all privileges to the database user run the following commands:

MariaDB [(none)]> CREATE DATABASE moodledb;
MariaDB [(none)]> CREATE USER 'moodle_user'@'localhost' IDENTIFIED BY 'Moodle_Passw0rd!';
MariaDB [(none)]> GRANT ALL ON moodledb.* TO 'moodle_user'@'localhost';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT

Step 6: Download Moodle

We will now download the latest stable Moodle version from the Moodle Official site.

Use the following command to download Moodle:

$ sudo wget https://download.moodle.org/download.php/direct/stable400/moodle-4.0.1.zip

Extract file into the folder /var/www/html/ with the following command:

$ sudo unzip moodle-4.0.1.zip -d /var/www/html/

Then, create a new directory in /var/www/html directory:

$ sudo mkdir /var/www/html/moodledata

Enable permission for the Apache webserver user to access the files:

$ sudo chown -R www-data:www-data /var/www/html/moodle/
$ sudo chmod -R 755 /var/www/html/moodle/
$ sudo chown -R www-data:www-data /var/www/html/moodledata/

Step 7: Configure Apache Web Server for Moodle

Navigate to /etc/apache2/sites-available directory and run the following command to create a configuration file for your installation:

$ sudo nano /etc/apache2/sites-available/moodle.conf

Add the following content:

<VirtualHost *:80>

ServerAdmin webmaster@your-domain.com

ServerName your-domain.com
ServerAlias www.your-domain.com
DocumentRoot /var/www/html/moodle

<Directory /var/www/html/moodle/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>

ErrorLog ${APACHE_LOG_DIR}/your-domain.com_error.log
CustomLog ${APACHE_LOG_DIR}/your-domain.com_access.log combined

</VirtualHost>

Save the file and Exit.

Enable the virtual host:

$ sudo a2ensite moodle.conf

After that, restart the Apache web server.

$ sudo systemctl restart apache2

Step 8: Access Moodle Web Installer

Open your browser type your domain e.g http://your-domain.com You will see the Moodle installation page.

Choose a language, and then click ‘Next‘:

Configure the URL, web root directory, and data directory and then click ‘Next‘:

Configure ‘Database driver‘, use MariaDB database server and then click ‘Next‘.

Type in the database information and then click ‘Next‘ to continue.

Accept the Copyright Agreement. Just click ‘Continue‘.

System Checking, checks the server configuration and all PHP extensions needed by Moodle.

 

If all the requirements are OK click ‘Continue

Make sure all results are ‘Success‘. Then click ‘Continue‘ again.

Fill in your admin info and click ‘Update profile‘.

You will be redirected to the user admin ‘Dashboard‘:

Comments and Conclusion

That’s it. You have successfully installed Moodle on Debian 11 OS.

If you have any questions please leave a comment below.

How to Install Magento 2.4.4 on Debian 11

Magento is a open source e-commerce platform written in PHP and uses the Zend Framework. It is highly popular ecommerce platform and it is owned and managed by Adobe Inc. The platform is flexible and has a large variety of features to build an online store.

In this tutorial we will show you how to install the Open Source version of Magento 2.4.4 on Debian 11.

Before starting the installation, you can check the system requirement for installing Magento2 here:

System prerequisites

Your system will need to satisfy the requirements below before proceeding.

  • Apache Web server
  • MySQL 8.0
  • PHP 8.1
  • Composer – an application-level package manager for the PHP

Step 1: Update Operating System

Update your Debian 11 operating system to make sure all existing packages are up to date:

$ sudo apt update && sudo apt upgrade -y

Step 2: Install Apache web server

To install Apache web server, run the following command:

$ sudo apt install apache2

Once installed, Apache should be running. If it’s not, for whatever reason, start it:

$ sudo systemctl start apache2

Then enable it to start on boot time.

$ sudo systemctl enable apache2

Step 3: Install PHP and PHP extensions for Magento 2.4.4

Magento 2.4.4 require PHP 8.1, so we will install PHP 8.1 in this tutorial.

By default, PHP 8.1 is not included in the Debian 11 default repository. So you will need to add the DEB.SURY.ORG repository to APT.

First, install the required packages using the following command:

$ sudo apt-get install ca-certificates apt-transport-https software-properties-common -y

Once all the packages are installed, add a Sury repository to APT using the following command:

$ sudo echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/sury-php.list

Next, download and add the GPG key with the following command:

$ sudo wget -qO - https://packages.sury.org/php/apt.gpg | apt-key add -

Once you are done, update the repository with the following command:

$ sudo apt-get update -y

Now, you can install the PHP 8.1 using the following command:

$ sudo apt-get install php8.1 libapache2-mod-php php8.1-dev php8.1-bcmath php8.1-intl php8.1-soap php8.1-zip php8.1-curl php8.1-mbstring php8.1-mysql php8.1-gd php8.1-xml

Verify if PHP is installed.

php -v
Output:
PHP 8.1.4 (cli) (built: Mar 20 2022 16:52:39) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.4, Copyright (c) Zend Technologies
with Zend OPcache v8.1.4, Copyright (c), by Zend Technologies

Update php.ini file

Now it’s time to increase values in the php.ini file. Open php.ini file:

$ sudo nano /etc/php/8.1/apache2/php.ini

Change the following data:

file_uploads = On
allow_url_fopen = On
short_open_tag = On
memory_limit = 512M
upload_max_filesize = 128M
max_execution_time = 3600

Then save this php.ini file.

After that, you should restart apache2 for the configuration to take effect:

$ sudo systemctl restart apache2.service

Step 4: Install MySQL 8 and create a database

To add the MySQL APT repository to your system run the following command:

$ sudo wget https://dev.mysql.com/get/mysql-apt-config_0.8.22-1_all.deb

Install the release package.

$ sudo apt install ./mysql-apt-config_0.8.22-1_all.deb

You can install MySQL with the following command:

$ sudo apt install mysql-server

Start the database server daemon, and also enable it to start automatically at the next boot with the following commands:

$ systemctl start mysql
$ systemctl enable mysql

Once the database server is installed, log into the MySQL prompt:

$ sudo  mysql -u root -p

To create a database, database user, and grant all privileges to the database user run the following commands:

mysql> CREATE DATABASE magento_db;
mysql> CREATE USER 'magento_user'@'localhost' IDENTIFIED BY 'Password';
mysql> GRANT ALL ON magento_db.* TO 'magento_user'@'localhost';
mysql> FLUSH PRIVILEGES;
mysql> EXIT

Step 5: Installing Elasticsearch

Starting Magento 2.4, all installations must be configured to use Elasticsearch as the catalog search engine.

Elasticserach uses a secure HTTPS transaction for its repositories. Before we proceed with the installation we need to install the required dependencies:

$ sudo apt install apt-transport-https ca-certificates gnupg2

Import the Elasticsearch GPG key.

$ sudo wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -

Add the Elasticsearch repository.

$ sudo sh -c 'echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" > /etc/apt/sources.list.d/elastic-7.x.list'

Update the apt package manager and install Elasticsearch:

$ sudo apt update && apt install elasticsearch

Then start and enable the service.

$ sudo systemctl start elasticsearch.service
$ sudo systemctl enable elasticsearch.service

To verify that Elasticsearch is running correctly, you will use the curl command:

$ curl -X GET "localhost:9200/"

If Elasticsearch is working properly, the result should be like this:

{
"name" : "debian",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "_95g0f6tQpOQZMR7ySyQQw",
"version" : {
"number" : "7.17.2",
"build_flavor" : "default",
"build_type" : "deb",
"build_hash" : "de7261de50d90919ae53b0eff9413fd7e5307301",
"build_date" : "2022-03-28T15:12:21.446567561Z",
"build_snapshot" : false,
"lucene_version" : "8.11.1",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}

Step 6: Install Composer

To download Composer, run the following command:

$ sudo curl -sS https://getcomposer.org/installer | php

Next, move the composer file to the /usr/local/bin path.

$ sudo mv composer.phar  /usr/local/bin/composer

Assign execute permission:

$ sudo chmod +x   /usr/local/bin/composer

Verify the Composer version installed:

$ sudo composer --version

Output:
Composer version 2.2.6 2022-02-04 17:00:38

Step 7: Install Magento 2.4.4

For most situation it is recommended to install Magento using the Marketplace by creating access key.

For generating Access keys go to:
My profile > Marketplace > My products > Access Keys

Run the following  command to download Magento 2.4.4 data:

$ composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=2.4.4 /var/www/magento2
Username : Your Public Key
Password : Your Private Key

Navigate to the Magento directory:

$ cd /var/www/magento2

Chmod cache and static content folder

$ find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +

Change the ownership of the Magento directory to the webserver user and also the permissions:

$ sudo chown -R www-data:www-data /var/www/magento2
$ sudo chmod -R 755 /var/www/magento2

Now, install Magento using the composer command, type:

$ sudo bin/magento setup:install \
--base-url=http://your-domain.com \
--db-host=localhost \
--db-name=magento_db \
--db-user=magento_user \
--db-password=Password \
--admin-firstname=Admin \
--admin-lastname=User \
--admin-email=admin@your-domain.com \
--admin-user=admin \
--admin-password=admin123 \
--language=en_US \
--currency=USD \
--timezone=America/Chicago \
--use-rewrites=1 

After the installation process you will see the admin link for your Magento site.

[SUCCESS]: Magento installation complete.
[SUCCESS]: Magento Admin URI: /admin_1od1xl
Nothing to import.

Step 8: Configure Apache Web Server for Magento 2.4.4

Navigate to /etc/apache2/sites-available directory and run the following command to create a configuration file for your Magento installation:

$ sudo nano /etc/apache2/sites-available/magento.conf

Add the following content:

<VirtualHost *:80>

ServerAdmin webmaster@your-domain.com

ServerName your-domain.com
ServerAlias www.your-domain.com
DocumentRoot /var/www/magento2/pub

<Directory /var/www/magento2/>
        AllowOverride All
</Directory>

ErrorLog ${APACHE_LOG_DIR}/your-domain.com_error.log
CustomLog ${APACHE_LOG_DIR}/your-domain.com_access.log combined

</VirtualHost>

Save the file and Exit.

Enable the Magento virtual host and make sure you enable rewrite mod to use site friendly URLs:

$ sudo a2ensite magento.conf
$ sudo a2enmod rewrite

Restart the Apache web server.

$ sudo systemctl restart apache2

Step 9: Access your Magento 2.4.4 Application

Open your browser and type your domain e.g http://your-domain.com

Comments and Conclusion

That’s it. You have successfully installed Open Source version of Magento 2.4.4 on Debian 11.

If you have any questions please leave a comment below.

How to Install MongoDB 5 on Debian 11

MongoDB is an open-source document database used in many modern web applications. It is classified as a NoSQL database. Unlike relational databases which store data in tables according to a rigid schema, MongoDB stores data in documents with flexible schema. Applications can then retrieve this information in a JSON format.

Update Operating System

Update your Debian 11 operating system to make sure all existing packages are up to date:

$ sudo apt update && sudo apt upgrade -y

Install Dependencies

Install the required packages for the installation with the following command:

$ sudo apt install curl apt-transport-https software-properties-common ca-certificates dirmngr gnupg2

Import MongoDB GPG Key

We first need to import MongDB public GPG key as below:

$ wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo  apt-key add -

The output of the executed command should be “OK”.

Add MongoDB 5.0 Repository

MongoDB 5.0 packages are not available to install directly from the base repository of Debian 11 and we need to add the official one offered by the developers of this NoSQL database:

echo "deb http://repo.mongodb.org/apt/debian buster/mongodb-org/5.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list

Update the repository:

$ sudo apt update

Install MongoDB on Debian 11

Now we will Install MongoDB with the following command:

$ sudo apt-get install -y mongodb-org

By default, MongoDB service is not started. Start the MongoDB service:

$ sudo systemctl start mongod

Confirm that MongoDB is actually running:

$ sudo systemctl status mongod

Output:

 mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
Active: active (running) since Sun 2022-04-03 08:02:06 EDT; 9s ago
Docs: https://docs.mongodb.org/manual
Main PID: 6197 (mongod)
Memory: 66.4M
CPU: 974ms
CGroup: /system.slice/mongod.service
└─6197 /usr/bin/mongod --config /etc/mongod.conf

Apr 03 08:02:06 debian systemd[1]: Started MongoDB Database Server.

To check the version of MongoDB which is installed.

$ sudo mongod --version
 version v5.0.6
Build Info: {
    "version": "5.0.6",
    "gitVersion": "212a8dbb47f07427dae194a9c75baec1d81d9259",
    "openSSLVersion": "OpenSSL 1.1.1k  25 Mar 2021",
    "modules": [],
    "allocator": "tcmalloc",
    "environment": {
        "distmod": "debian10",
        "distarch": "x86_64",
        "target_arch": "x86_64"
    }
}

Let us enable it to start on boot using this command:

$ sudo systemctl enable mongod

As needed, you can stop the mongod process by run the following command:

$ sudo systemctl stop mongod

Configure MongoDB

By default, the configuration file for MongoDB is located at “/etc/mongod.conf”.

Enable password authentication

To enable password authentication open the configuration file:

$ sudo nano /etc/mongod.conf

Find the line #security and uncomment it (remove the #) and add “authorization: enabled”:

security:
  authorization: enabled

After that restart the mongod service for the changes to take effect:

$ sudo systemctl restart mongod

Enable remote access

To enable remote access to your MongoDB database, you need to edit the configuration file at “/etc/mongod.conf”.

$ sudo nano /etc/mongod.conf
# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1,your-server-IP

After you’ve added the IP, restart the service:

$ sudo systemctl restart mongod

You also need to allow on the firewall the trusted remote IP addresses if you have enabled your firewall:

$ sudo ufw allow from your-server-ip to any port 27017

Creating Administrative MongoDB User

If you enabled the MongoDB authentication, you’ll need to create an administrative user that can access and manage the MongoDB instance.

To access MongoDB shell, run the command mongosh on the terminal as shown:

$ mongosh

List existing databases:

show dbs
admin 41 kB
config 36.9 kB
local 41 kB

Connect to the admin database:

use admin

Create a admin user which will be used to manage the MongoDB:

db.createUser(
   {
     user: "admin",
     pwd: "CR7yT5cfgB",
     roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
   }
 )

Exit the mongo shell.

exit

Try to connect to MongoDB using a admin user you have previously created:

$ sudo mongosh -u admin -p --authenticationDatabase admin

You can try to connect to MongoDB by typing mongosh without any arguments.

Once connected, you can execute show dbs command. You will get error:

MongoServerError: command listDatabases requires authentication

Uninstall MongoDB

If you want to completely remove MongoDB and related dependencies, run the following command:

$ sudo apt purge --autoremove -y mongodb-org

You can also remove MongoDB logs, data, and other related directories and files:

$ sudo rm -rf /var/log/mongodb
$ sudo rm -rf /var/lib/mongodb
$ sudo rm -rf ~/.mongodb
$ sudo rm -rf ~/.dbshell
$ sudo rm -rf ~/.mongorc.js

Comments and Conclusion

That’s it. You have successfully installed MongoDB 5.0 on Debian 11.

If you have any questions please leave a comment below.

How to Install Laravel 9 on Debian 11

Laravel is a popular open source web framework built for PHP developer. It’s an MVC framework for building simple to complex web applications using the PHP programming language, and it strictly follows the MVC (model–view–controller) architectural pattern.

In this tutorial we will show you how to install Laravel 9 (LTS) on Debian 11.

System prerequisites

Your system will need to satisfy the requirements below before proceeding.

  • Apache Web server
  • MySQL/MariaDB
  • PHP >= 8.0.2 with OpenSSL, PDO, Mbstring, Tokenizer, XML, Ctype and JSON PHP Extensions.
  • Composer – an application-level package manager for the PHP

Update Operating System

Update your Debian 11 operating system to make sure all existing packages are up to date:

$ sudo apt update && sudo apt upgrade -y

Install Apache web server

To install Apache web server, run the following command:

$ sudo apt install apache2

Once installed, Apache should be running. If it’s not, for whatever reason, start it:

$ sudo systemctl start apache2

Then enable it to start on boot time.

$ sudo systemctl enable apache2

Install PHP and PHP extensions for Laravel Application

First and most importantly, Laravel 9 requires the latest PHP 8.

By default, PHP 8.1 is not included in the Debian 11 default repository. So you will need to add the DEB.SURY.ORG repository to APT.

First, install the required packages using the following command:

$ sudo apt-get install ca-certificates apt-transport-https software-properties-common -y

Once all the packages are installed, add a Sury repository to APT using the following command:

$ echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/sury-php.list

Next, download and add the GPG key with the following command:

$ wget -qO - https://packages.sury.org/php/apt.gpg | apt-key add -

Once you are done, update the repository with the following command:

$ apt-get update -y

Now, you can install the PHP 8.1 using the following command:

$ sudo apt-get install php8.1 libapache2-mod-php php8.1-dev php8.1-zip php8.1-curl php8.1-mbstring php8.1-mysql php8.1-gd php8.1-xml

Verify if PHP is installed.

php -v
Output:
PHP 8.1.2 (cli) (built: Jan 27 2022 12:22:31) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
with Zend OPcache v8.1.2, Copyright (c), by Zend Technologies

Install MariaDB and create a database

You can install MariaDB with the following command:

$ sudo apt install mariadb-server mariadb-client

Note: If you want newer version of MariaDB you can follow our tutorial here.

Start the database server daemon, and also enable it to start automatically at the next boot with the following commands:

$ systemctl start mariadb
$ systemctl enable mariadb

Once the database server is installed, log into the MariaDB prompt:

$ sudo  mysql -u root -p

To create a database, database user, and grant all privileges to the database user run the following commands:

MariaDB [(none)]> CREATE DATABASE laravel_db;
MariaDB [(none)]> CREATE USER 'laravel_user'@'localhost' IDENTIFIED BY 'Password';
MariaDB [(none)]> GRANT ALL ON laravel_db.* TO 'laravel_user'@'localhost';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT

Install Composer

To download Composer, run the following command:

$ curl -sS https://getcomposer.org/installer | php

Next, move the composer file to the /usr/local/bin path.

$ sudo mv composer.phar  /usr/local/bin/composer

Assign execute permission:

$ sudo chmod +x   /usr/local/bin/composer

Verify the Composer version installed:

$ composer --version

Output:
Composer version 2.2.6 2022-02-04 17:00:38

Install Laravel 9 on Debian 11

Navigate to the webroot directory, type:

$ cd /var/www/html

Now, install Laravel using the composer command, type:

$ sudo composer create-project laravel/laravel laravelapp

The command creates a new directory called laravelapp and installs all the files and directories for Laravel.

Change the ownership of the Laravel directory to the webserver user and also the permissions:

sudo chown -R www-data:www-data /var/www/html/laravelapp
sudo chmod -R 775 /var/www/html/laravelapp/storage

Once the installation is done navigate to the installation directory and check the Laravel version:

$ cd laravelapp
$ php artisan

Framework 9.0.2

Configure Apache Web Server for Laravel

Navigate to /etc/apache2/sites-available directory and run the following command to create a configuration file for your Laravel installation:

$ sudo nano /etc/apache2/sites-available/laravel.conf

Add the following content:

<VirtualHost *:80>

ServerName your-domain.com

ServerAdmin webmaster@your-domain.com
DocumentRoot /var/www/html/laravelapp/public

<Directory /var/www/html/laravelapp/>
Options +FollowSymlinks
AllowOverride All
Require all granted
</Directory>

ErrorLog ${APACHE_LOG_DIR}/your-domain.com_error.log
CustomLog ${APACHE_LOG_DIR}/your-domain.com_access.log combined

</VirtualHost>

Save the file and Exit.

Enable the laravel virtual host.

$ sudo a2ensite laravel.conf

Restart the Apache web server.

$ sudo systemctl restart apache2

Access your Laravel Application

Open your browser and type your domain e.g http://your-domain.com

Comments and Conclusion

That’s it. You have successfully installed Laravel 9 on Debian 11.

If you have any questions please leave a comment below.