How to Install Magento 2 on CentOS 8?

How to Install Magento 2 on CentOS 8?

Magento 2 is a powerful and popular eCommerce platform that allows you to create and manage online stores with ease. It has many features and benefits, such as scalability, flexibility, customization, and security. In this article, we will show you how to install Magento 2 on CentOS 8, a Linux-based operating system that is stable and secure. We will use Apache as the web server, MariaDB as the database server, and PHP as the programming language. We will also show you how to access the Magento 2 admin panel and frontend. Let’s get started!

Step 1: Update CentOS and install Apache

First, you will need to log in to your CentOS 8 server via SSH as the root user or a user with sudo privileges. You can use the following command:

ssh root@your_server_ip -p your_port_number

Make sure to replace your_server_ip and your_port_number with your server’s IP address and port number.

Next, you will need to update all installed packages on your server. You can use the following command:

sudo dnf update -y

Then, you will need to install Apache, a web server that serves the Magento 2 content. You can use the following command:

sudo dnf install httpd -y

After installing Apache, you will need to start and enable it to run on system boot. You can use the following commands:

sudo systemctl start httpd
sudo systemctl enable httpd

You can verify the status of Apache by using the following command:

sudo systemctl status httpd

You should see something like this:

● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2021-12-14 10:15:23 UTC; 3min 12s ago
     Docs: man:httpd.service(8)
 Main PID: 1234 (httpd)
   Status: "Running, listening on: port 80"
    Tasks: 213 (limit: 1137)
   Memory: 15.6M
   CGroup: /system.slice/httpd.service
           ├─1234 /usr/sbin/httpd -DFOREGROUND
           ├─1235 /usr/sbin/httpd -DFOREGROUND
           ├─1236 /usr/sbin/httpd -DFOREGROUND
           ├─1237 /usr/sbin/httpd -DFOREGROUND
           └─1238 /usr/sbin/httpd -DFOREGROUND

Dec 14 10:15:23 centos8 systemd[1]: Starting The Apache HTTP Server...
Dec 14 10:15:23 centos8 httpd[1234]: Server configured, listening on: port 80
Dec 14 10:15:23 centos8 systemd[1]: Started The Apache HTTP Server.

Step 2: Install MariaDB and create a database for Magento 2

Next, you will need to install MariaDB, a database server that stores the Magento 2 data. You can use the following command:

sudo dnf install mariadb-server -y

After installing MariaDB, you will need to start and enable it to run on system boot. You can use the following commands:

sudo systemctl start mariadb
sudo systemctl enable mariadb

You can verify the status of MariaDB by using the following command:

sudo systemctl status mariadb

You should see something like this:

● mariadb.service - MariaDB 10.3 database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2021-12-14 10:18:34 UTC; 1min 9s ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
 Main PID: 2345 (mysqld)
   Status: "Taking your SQL requests now..."
    Tasks: 31 (limit: 1137)
   Memory: 67.9M
   CGroup: /system.slice/mariadb.service
           └─2345 /usr/libexec/mysqld --basedir=/usr

Dec 14 10:18:32 centos8 systemd[1]: Starting MariaDB 10.3 database server...
Dec 14 10:18:33 centos8 mysqld[2345]: 2021-12-14 10:18:33 0 [Note] /usr/libexec/mysqld (mysqld 10.3.28-MariaDB) starting as process 
Dec 14 10:18:34 centos8 systemd[1]: Started MariaDB 10.3 database server.

Then, you will need to secure your MariaDB installation by running a script that comes with MariaDB. You can use the following command:

sudo mysql_secure_installation

You will be asked to enter the current root password for MariaDB. Since this is a fresh installation, there is no password set, so just press Enter.

Then, you will be asked if you want to set a new root password for MariaDB. It is recommended to set a strong password and confirm it.

Next, you will be asked a series of questions that will help you improve the security of your MariaDB installation. You can answer yes to all of them by pressing Y and Enter.

The questions are:

  • Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
  • Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
  • Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
  • Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y

After securing your MariaDB installation, you will need to create a new database for Magento 2 and assign a user and a password. You can use the following commands:

sudo mysql -u root -p

Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is XXXX.
Server version: X.X.XX-MariaDB MariaDB Server

Copyright (c) XXXX-X XXXX Monty Program Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> CREATE DATABASE magento;
Query OK, X row affected (X.XXX sec)

MariaDB [(none)]> CREATE USER 'magento'@'localhost' IDENTIFIED BY 'your_password';
Query OK, X row affected (X.XXX sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON magento.* TO 'magento'@'localhost';
Query OK, X row affected (X.XXX sec)

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, X row affected (X.XXX sec)

MariaDB [(none)]> EXIT;
Bye.

Make sure to replace magento with your desired database name and username, and your_password with your desired password.

Step 3: Install PHP and required extensions for Magento

Next, you will need to install PHP, the programming language used by Magento. The latest version of Magento is compatible with PHP versions from X.X.X+ up to X.X.X.

By default, CentOS X ships with PHP version X.X.X which meets these requirements.

Therefore, you can simply install PHP with all dependencies using the following command:

sudo dnf install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysqlnd php-bcmath php-json php-iconv php-soap php-mbstring php-intl php-zip php-xml -y 

Copier

After installing PHP and its extensions, you will need to adjust some PHP settings for optimal performance of Magento.

You can edit the main PHP configuration file using your preferred text editor:

sudo nano /etc/php.ini 

Find and modify the following lines as shown below:


memory_limit = XXXM

upload_max_filesize = XXM

zlib.output_compression = On

max_execution_time = XXX

date.timezone = Your/Timezone

Make sure to replace XXXM with your desired memory limit in megabytes (recommended at least XXXM), XXM with your desired upload file size limit in megabytes (recommended at least XXM), XXX with your desired maximum execution time in seconds (recommended at least XXX), and Your/Timezone with your desired timezone.

You can find a list of supported timezones here. Save and close the file when you are finished.

Then, restart Apache for the changes to take effect:

Heinz Avatar

Leave a Reply

Your email address will not be published. Required fields are marked *