Magento 2.4.4 on Debian 11

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 NextCloud on AlmaLinux 8

NextCloud provides reliable self-hosted cloud services and comes off as a good substitute for platforms such as Box and DropBox. It runs on your own server, protecting your data and giving you access from your desktop or mobile devices. You can synchronize everything between your devices and share files with others as well.

Update Operating System

Update your AlmaLinux 8 operating system to make sure all existing packages are up to date:

$ sudo dnf update

Also, install:

$ sudo dnf install wget nano unzip

Install Apache web server

To install Apache web server, run the following command:

$ sudo dnf install httpd

Apache does not start automatically when it is installed, you need to start it:

$ sudo systemctl start httpd

Then enable it to start on boot time.

$ sudo systemctl enable httpd

Install PHP 8.1 and required PHP modules

Currently, PHP 8.1 is not featured in AlmaLinux’s AppStream. However, you can install PHP from (Remi) repository, a free-to-use third-party repository that deploys the latest PHP 8.0 builds.

To install EPEL, use the following (dnf) terminal command:

$ sudo dnf install epel-release

Now that you have added the EPEL repository, enable (Remi repository) with the following command:

$ sudo dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm

Use the (dnf) command to update your repository list:

$ sudo dnf update

Next, enable PHP 8.1 with the following command:

$ sudo dnf module enable php:remi-8.1

Now that you have added the Remi PHP repository and enabled PHP 8.1 to be the default version on your system, you can install PHP 8.1 with the following command:

$ sudo dnf install php

For NextCloud to seamlessly work some additional PHP modules are required, install them with the following command:

$ dnf install php-mysql php-fpm php-gd php-zip php-intl php-bcmath php-gmp

Increase PHP Memory limit:

$ sudo nano /etc/php.ini

Find memory_limit and set the value to 512M

memory_limit = 512M

Install MariaDB and create a database

MariaDB 10.7 is the latest release version for this relational database system. To be able to install MariaDB 10.7 on AlmaLinux 8 you need to add the MariaDB YUM repository:

$ curl -LsS -O https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
$ sudo bash mariadb_repo_setup --mariadb-server-version=10.7

Once the repository has been added to the system, installing MariaDB is an easy task that can be accomplished with the following command:

$ sudo dnf install MariaDB-server MariaDB-client

Once the installation is complete, verify the installed version of MariaDB.

$ sudo systemctl status mariadb

Output:

 mariadb.service - MariaDB 10.7.1 database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/mariadb.service.d
└─migrated-from-my.cnf-settings.conf
Active: active (running)
Docs: man:mariadbd(8)
https://mariadb.com/kb/en/library/systemd/
Process: 1450 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
Process: 1000 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= || VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -eq 0 ] && systemctl set-environment _WSREP_START_POSITION=$VAR || exit 1 (code=exited, status>
Process: 987 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
Main PID: 1017 (mariadbd)
Status: "Taking your SQL requests now..."
Tasks: 8 (limit: 11234)
Memory: 89.1M
CGroup: /system.slice/mariadb.service
└─1017 /usr/sbin/mariadbd

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

$ sudo systemctl start mariadb
$ sudo 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 nextcloud_db;
MariaDB [(none)]> CREATE USER 'nextcloud_user'@'localhost' IDENTIFIED BY 'Passw0rd';
MariaDB [(none)]> GRANT ALL ON nextcloud_db.* TO 'nextcloud_user'@'localhost';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT

Installing NextCloud

Use the following command to download NextCloud 23:

$ sudo dnf -y install wget
$ sudo wget https://download.nextcloud.com/server/releases/nextcloud-23.0.2.zip

Extract file into the folder /var/www/ with the following command,

$ sudo dnf -y install unzip 
$ sudo unzip nextcloud-23.0.2.zip -d /var/www/

Create a directory to store the user data,

$ sudo mkdir -p /var/www/nextcloud/data

Enable permission for the Apache webserver user to access the NextCloud files,

$ sudo chown -R apache:apache /var/www/nextcloud/

Open port 80 on the webserver:

$ sudo firewall-cmd --add-port=80/tcp --zone=public --permanent

$ sudo firewall-cmd --reload

Configure Apache Web Server for NextCloud

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

$ sudo nano /etc/httpd/conf.d/nextcloud.conf

Add the following content:

<VirtualHost *:80>

ServerName cloud.your-domain.com

ServerAdmin webmaster@your-domain.com
DocumentRoot /var/www/nextcloud

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

ErrorLog /var/log/httpd/cloud.your-domain.com_error.log
CustomLog /var/log/httpd/cloud.your-domain.com_access.log combined

</VirtualHost>

Save the file and Exit.

Restart the Apache web server.

$ sudo systemctl restart httpd

Access your NextCloud Application

Open your browser and complete the final steps at http://cloud.your-domain.com

Click the Install button, you will see the Web interface of NextCloud.

Comments and Conclusion

That’s it. You have successfully installed NextCloud on AlmaLinux 8.

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.

How to Install Tomcat 10 on Debian 11

Apache Tomcat is an open-source Java HTTP web server developed by the Apache Software Foundation. Tomcat helps to deploy the Java Servlet and the JavaServer Pages and serves them like an HTTP web server.

In this tutorial, we will show you the complete steps to install Tomcat 10 on Debian 11.

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 Java 17 (OpenJDK 17) on Debian 11

Java 17 packages are available on Debian 11 repositories and you can install it with the following command:

$ sudo apt install openjdk-17-jdk

Check Java version after installation:

$ java -version
openjdk version "17.0.1" 2021-10-19
OpenJDK Runtime Environment (build 17.0.1+12-Debian-1deb11u2)
OpenJDK 64-Bit Server VM (build 17.0.1+12-Debian-1deb11u2, mixed mode, sharing)

Create Tomcat User

It is recommended to have tomcat user for tomcat services.

To create a new account, type:

sudo useradd -m -d /opt/tomcat -U -s /bin/false tomcat 

The above command will create a user and group with the name “tomcat” in your system.

Download and Install Tomcat

You can download the Tomcat 10 directly from the official webpage of the Tomcat, or use the wget command:

$ sudo wget https://downloads.apache.org/tomcat/tomcat-10/v10.0.16/bin/apache-tomcat-10.0.16.tar.gz

Extract the downloaded file to /opt/tomcat directory using tar command:

$ sudo tar xpvf apache-tomcat-10.0.16.tar.gz -C /opt/tomcat --strip-components=1

Set the correct permissions on files and directories:

$ sudo chown tomcat:tomcat /opt/tomcat/ -R
$ sudo chmod u+x /opt/tomcat/bin -R

Create a Systemd service file

By default, we won’t have a Systemd unit file for Tomcatto run it in the background and to easily stop, start and enable its services.

Create systemd unit for tomcat to start / stop and restart service.

nano /etc/systemd/system/tomcat.service

Paste following lines:

[Unit]
Description=Tomcat
After=syslog.target network.target
[Service]
Type=forking

User=tomcat
Group=tomcat

Environment=JAVA_HOME=/usr/lib/jvm/java-1.17.0-openjdk-amd64
Environment='JAVA_OPTS=-Djava.awt.headless=true'

Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid

ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh

[Install]
WantedBy=multi-user.target 

Reload system daemon and start Tomcat Service:

$ sudo systemctl daemon-reload
$ sudo systemctl start tomcat
$ sudo systemctl enable tomcat

To confirm everything is working normally, check the status of service:

systemctl status tomcat

Output:

 tomcat.service - Tomcat
Loaded: loaded (/etc/systemd/system/tomcat.service; enabled; vendor preset: enabled)
Active: active (running)
Main PID: 5605 (java)
Tasks: 37 (limit: 2301)
Memory: 77.1M
CPU: 5.700s
CGroup: /system.slice/tomcat.service
└─5605 /usr/lib/jvm/java-1.17.0-openjdk-amd64/bin/java -Djava.util.logging.config.fil>

Note: In case firewall is enable and running on your Debian 11 system then allow 8080 tcp port:

$ sudo ufw allow 8080/tcp

Now open your web browser and type https://yourIP:8080. You will see the default tomcat page.

Apache Tomcat

Add Roles and Admin username and password

To do it, you need to edit the configuration file /opt/tomcat/conf/tomcat-users.xml. You can edit it with nano by executing the following command:

$ sudo nano /opt/tomcat/conf/tomcat-users.xml

Add following lines before context </tomcat-users>:

<role rolename="admin"/>
<role rolename="admin-gui"/>
<role rolename="manager"/>
<role rolename="manager-gui"/>

<user username="linuxtuto" password="Pa$$word" roles="admin,admin-gui,manager,manager-gui"/>

save and exit the file.

Allow Remote Access of Tomcat

By default, you won’t be able to access your installed Tomcat Manager sections (web interface) outside the local system.

In case you want to access tomcat applications from outside then edit the context.xml file for manager & host-manager and comment out the remote access section:

$ sudo nano /opt/tomcat/webapps/manager/META-INF/context.xml
........
<!--      <Valve className="org.apache.catalina.valves.RemoteAddrValve"
                 allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
  -->
........
$ sudo nano /opt/tomcat/webapps/host-manager/META-INF/context.xml
........
<!--      <Valve className="org.apache.catalina.valves.RemoteAddrValve"
                 allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
  -->
........

Restart Tomcat service:

$ sudo systemctl restart tomcat

To Access Tomcat Web Manager page type http://yourIP:8080/manager/html

It will prompt for username and password, Use username and password that you specify in the ‘/opt/tomcat/conf/tomcat-users.xml’ file:

Tomcat Web Application Manager

To access Tomcat Host Manager Web Page page type http://yourIP:8080/host-manager/html

It will prompt for username and password, Use username and password that you specify in the ‘/opt/tomcat/conf/tomcat-users.xml’ file:

Tomcat Virtual Host Manager

Comments and Conclusion

That’s it. You have successfully installed Tomcat 10 on Debian 11. If you have any questions please leave a comment below.

How to Install MariaDB 10.7 on Debian 11

MariaDB is an open-source relational database management system developed by the developers of MySQL as an enhanced drop-in replacement to the MySQL server. MariaDB is focused on reliability, stability, security, and performance.

In this tutorial, we will show you the complete steps to install MariaDB 10.7 on Debian 11 from an APT repository.

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 of MariaDB 10.7 with the following command:

$ sudo apt install curl software-properties-common dirmngr gnupg2

Add MariaDB 10.7 Repository

MariaDB 10.5 is the currently available version on the default Debian 11 repositories. To be able to install MariaDB 10.7 on Debian 11 you need to add the MariaDB 10.7 APT repository:

$ curl -LsS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash -s -- --mariadb-server-version=10.7 --skip-maxscale --skip-tools

Install MariaDB 10.7

Once the repository has been added to the system, You are now ready to install MariaDB 10.7 with the following command:

$ sudo apt install mariadb-server mariadb-client

You can verify the installed version of MariaDB with the following command:

$ mariadb --version

Output:

mariadb Ver 15.1 Distrib 10.7.1-MariaDB, for debian-linux-gnu (x86_64) using readline EditLine wrapper

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

Check the status of the service:

$ systemctl status mariadb

Example output:

$  mariadb.service - MariaDB 10.7.1 database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
Drop-In: /etc/systemd/system/mariadb.service.d
└─migrated-from-my.cnf-settings.conf
Active: active (running) 
Docs: man:mariadbd(8)
https://mariadb.com/kb/en/library/systemd/
 Process: 3274 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS)
Process: 3276 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
Process: 3278 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= || VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -eq 0 ] && systemctl set-environment _WSREP_START_POSITION=$VAR || exit 1 (code=exited, stat>
Process: 3340 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
Process: 3342 ExecStartPost=/etc/mysql/debian-start (code=exited, status=0/SUCCESS)
Main PID: 3326 (mariadbd)
Status: "Taking your SQL requests now..."
Tasks: 13 (limit: 2301)
Memory: 68.1M
CPU: 345ms
CGroup: /system.slice/mariadb.service
└─3326 /usr/sbin/mariadbd

Secure MariaDB

Run mariadb-secure-installation script which helps you secure your MariaDB database server:

$ sudo mariadb-secure-installation

You can set a root password for MariaDB along with removing empty databases, restricting remote access except for localhost, removing anonymous users, and more:

Set 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

MariaDB Create Database

We need to login to MariaDB with the following command:

$ sudo mysql -u root -p

Note: Use -p if you have set the root password.

To create a database in MariaDB you need to run the following command:

MariaDB [(none)]> CREATE DATABASE your_db;

View the new database:

SHOW DATABASES;

To create a new MariaDB user, run the following command:

MariaDB [(none)]> CREATE USER 'your_user'@localhost IDENTIFIED BY 'password';

You should replace password with a secure password.

View the new user:

SELECT User FROM mysql.user;

The newly created user does not have privileges to manage databases.

Create a new user (only with local access) and grant privileges to this user on the database:

MariaDB [(none)]> GRANT ALL PRIVILEGES ON your_db.* TO 'your_user'@'localhost' IDENTIFIED BY 'password';

Create a new user (with remote access) and grant privileges to this user on the database:

MariaDB [(none)]> GRANT ALL PRIVILEGES ON your_db.* TO 'your_user'@'%' IDENTIFIED BY 'password';

Flush the privileges:

MariaDB [(none)]> FLUSH PRIVILEGES;

Exit the MariaDB shell:

MariaDB [(none)]> exit

Reset the MariaDB Root Password

If you forget your root MariaDB password, it can be reset.

Stop the MariaDB server:

$ sudo systemctl stop mariadb

Start the database without loading the grant tables or enabling networking:

$ sudo systemctl set-environment MYSQLD_OPTS="--skip-grant-tables --skip-networking"

Restart MariaDB:

$ sudo systemctl start mariadb

Now you can connect to the database as the root user,:

$ sudo mysql -u root

Use the following commands to reset root’s password. Replace password with a strong password:

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> UPDATE mysql.user SET password = PASSWORD('password') WHERE user = 'root';

Update the authentication methods for the root password:

MariaDB [(none)]> UPDATE mysql.user SET authentication_string = '' WHERE user = 'root';
MariaDB [(none)]> UPDATE mysql.user SET plugin = '' WHERE user = 'root';
exit;

Revert the environment settings to allow the database to start with grant tables and networking:

$ sudo systemctl unset-environment MYSQLD_OPTS

Then restart MariaDB:

$ sudo systemctl start mariadb

You should now be able to log into the database with your new root password:

$ sudo mysql -u root -p

Comments and Conclusion

That’s it. You have successfully installed MariaDB 10.7 on Debian 11. Also, In the tutorial, you have learned how to create database and reset your MariaDB root password.

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

If you have any questions please leave a comment below.

How to Install LAMP Stack on AlmaLinux 8.5

LAMP is a popular open-source software stack that is mostly used for testing and hosting web applications. It’s an acronym for Linux Apache MariaDB / MySQL and PHP.

Apache is a popular open-source and widely used web server. MariaDB is a free and open-source, commercially supported relational database management system, and PHP is a server-side scripting language used for developing dynamic web pages.

In this tutorial, we will show you how to install LAMP stack on AlmaLinux 8.

Update Operating System

Update your AlmaLinux 8 operating system to make sure all existing packages are up to date:

$ sudo dnf update

Install Apache webserver

Well, like most of the Linux operating systems, we don’t have to add any third-party Repos to install Apache- HTTPd server.

You can install Apache via dnf package manager by executing the following command.

$ sudo dnf install httpd

Apache does not start automatically when it is installed. You can start the Apache service and configure it to run on startup by entering the following commands:

$ sudo systemctl start httpd
$ sudo systemctl enable httpd

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

$ sudo systemctl status httpd

Output:

 httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Drop-In: /usr/lib/systemd/system/httpd.service.d
└─php-fpm.conf
Active: active (running)
Docs: man:httpd.service(8)
Main PID: 36360 (httpd)
Status: "Running, listening on: port 80"
Tasks: 213 (limit: 11221)
Memory: 38.6M
CGroup: /system.slice/httpd.service
├─36360 /usr/sbin/httpd -DFOREGROUND
├─36375 /usr/sbin/httpd -DFOREGROUND
├─36376 /usr/sbin/httpd -DFOREGROUND
├─36378 /usr/sbin/httpd -DFOREGROUND
└─36405 /usr/sbin/httpd -DFOREGROUND

If firewalld is enabled consider allowing HTTP and HTTPS services:

$ sudo firewall-cmd --permanent --add-service={http,https}
$ sudo firewall-cmd --reload

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 default AlmaLinux Test Page, as seen below.

AlmaLinux Test Page

Install MariaDB 10.7

MariaDB 10.7 is the latest release version for this relational database system. To be able to install MariaDB 10.7 on AlmaLinux 8 you need to add the MariaDB YUM repository:

$ curl -LsS -O https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
$ sudo bash mariadb_repo_setup --mariadb-server-version=10.7

Once the repository has been added to the system, installing MariaDB is an easy task that can be accomplished with the following command:

$ sudo dnf install MariaDB-server MariaDB-client

Once the installation is complete, verify the installed version of MariaDB.

$ sudo dnf info MariaDB-server

MariaDB 10.7 on AlmaLinux 8.5

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

Check the status of the service:

$ systemctl status mariadb

Example output:

$  mariadb.service - MariaDB 10.7.1 database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/mariadb.service.d
└─migrated-from-my.cnf-settings.conf
Active: active (running) 
Docs: man:mariadbd(8)
https://mariadb.com/kb/en/library/systemd/
Main PID: 35787 (mariadbd)
Status: "Taking your SQL requests now..."
Tasks: 13 (limit: 11221)
Memory: 68.0M
CGroup: /system.slice/mariadb.service
└─35787 /usr/sbin/mariadbd

Secure MariaDB

Run mariadb-secure-installation script which helps you secure your MariaDB database server:

$ sudo mariadb-secure-installation

You can set a root password for MariaDB along with removing empty databases, restricting remote access except for localhost, removing anonymous users, and more:

Set 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

Install PHP 8.1

Currently, PHP 8.1 is not featured in AlmaLinux’s AppStream. However, you can install PHP from (Remi) repository, a free-to-use third-party repository that deploys the latest PHP 8.1 builds.

To install EPEL, use the following (dnf) terminal command:

$ sudo dnf install epel-release

Now that you have added the EPEL repository, enable (Remi repository) with the following command:

$ sudo dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm

Use the (dnf) command to update your repository list:

$ sudo dnf update

Next, enable PHP 8.1 with the following command:

$ sudo dnf module enable php:remi-8.1

Now that you have added the Remi PHP repository and enabled PHP 8.1 to be the default version on your system, you can install PHP 8.1 with the following command:

$ sudo dnf install php

You can check your PHP version using the following command:

$ php -v

Example output:

PHP 8.1.1 (cli) (built: Dec 15 2021 02:00:45) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.1.1, Copyright (c) Zend Technologies
with Zend OPcache v8.1.1, Copyright (c), by Zend Technologies

If you would like to install the most commonly used extensions for PHP 8.1, use the following command:

$ sudo dnf install php-cli php-fpm php-curl php-mysqlnd php-gd php-opcache php-zip php-intl php-common php-bcmath php-imap php-imagick php-xmlrpc php-json php-readline php-memcached php-redis php-mbstring php-apcu php-xml php-dom php-redis php-memcached php-memcache

You can check your PHP modules using the following command:

$ php -m

Example output:

[PHP Modules]
..............
igbinary
imagick
imap
intl
json
libxml
mbstring
memcache
memcached
msgpack
mysqli
mysqlnd
openssl
..............

[Zend Modules]
Zend OPcache

Comments and Conclusion

In the tutorial, you have learned how to install LAMP stack on AlmaLinux 8.

If you have any questions please leave a comment below.

How to Install PHP 8.1 on Debian 11

“HyperText Processor”, commonly known as PHP, is the open-source programming language used for Web application development. It is a scripting language, mostly used for the front end with HTML. The latest PHP 8.1 version is officially released on November 25th, 2021.

In this tutorial, we will show you how to install PHP 8.1 on a Debian 11 system.

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

Add PHP Repository

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

Install PHP 8.1

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

$ sudo apt-get install php8.1

Install PHP 8.1

Once the PHP is installed, you can check the PHP version on your system with the following command:

$ php8.1 --version

Output:

$ php8.1 --version
PHP 8.1.1 (cli) (built: Dec 20 2021 21:35:13) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.1, Copyright (c) Zend Technologies
with Zend OPcache v8.1.1, Copyright (c), by Zend Technologies

Install PHP 8.1 FPM for Nginx

For the Nginx web server, you need to install the FPM service, you can install it using the following command:

$ sudo apt install php8.1-fpm

Once the installation has been completed, you can confirm that the PHP-FPM service has been installed correctly with the following command:

$ systemctl status php8.1-fpm

Output:

 php8.1-fpm.service - The PHP 8.1 FastCGI Process Manager
Loaded: loaded (/lib/systemd/system/php8.1-fpm.service; enabled; vendor preset: enabled)
Active: active (running)
Docs: man:php-fpm8.1(8)
Process: 43762 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /run/php/php-fpm.sock /etc/php/8.1/fpm/pool.d/www.conf 81 (code=exited, status=0>
Main PID: 43759 (php-fpm8.1)
Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec"
Tasks: 3 (limit: 2303)
Memory: 8.9M
CPU: 194ms
CGroup: /system.slice/php8.1-fpm.service
├─43759 php-fpm: master process (/etc/php/8.1/fpm/php-fpm.conf)
├─43760 php-fpm: pool www
└─43761 php-fpm: pool www

Install PHP Extension

Installing PHP extensions are simple with the below-mentioned syntax:

$ sudo apt install php8.1-[extension]

Replace [extension] with the extension you want to install, if you want to add multiple extensions then include them in braces:

$ sudo apt install php8.1-mysql php8.1-imap php8.1-ldap php8.1-xml php8.1-fpm php8.1-curl php8.1-mbstring php8.1-zip

To check loaded PHP modules use the command:

$ php8.1 -m

Example Output:


[PHP Modules]
..............
imap
json
ldap
libxml
mbstring
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
..............

[Zend Modules]
Zend OPcache

Running PHP 8.1 with Other Versions

Instead of removing old PHP versions, it is also possible to run multiple PHP versions side-by-side.

Multiple PHP versions

The update-alternatives command provides an easy way to switch between PHP versions for PHP CLI.

$ sudo update-alternatives --config php

This brings up a prompt to interactively select the alternative PHP binary path that php points to.

There are 2 choices for the alternative php (providing /usr/bin/php).

  Selection    Path             Priority   Status
------------------------------------------------------------
* 0            /usr/bin/php8.1   81        auto mode
  1            /usr/bin/php7.4   74        manual mode
  2            /usr/bin/php8.1   81        manual mode

To set the path without the interactive prompt:

$ update-alternatives --set php /usr/bin/php7.4

Comments and Conclusion

In the tutorial, you have learned how to install PHP 8.1 on Debian 11.

If you have any questions please leave a comment below.