Linux Tactic

Mastering Magento: A Comprehensive Guide to Installing and Configuring on CentOS 7

Introduction to Magento and Prerequisites

The world of e-commerce has grown rapidly in recent years, with businesses of all sizes seeking to expand their online presence and reach more customers. One of the most popular platforms for creating online stores is Magento, an open-source e-commerce platform that offers a wealth of features and benefits to merchants.

But before you can start building your Magento store, there are a few prerequisites you need to have in place. In this article, well take a closer look at the system requirements for Magento, as well as some other prerequisites like generating an access key pair for the Magento Marketplace.

Overview of Magento features and benefits

First, lets take a look at some of the key features and benefits of Magento that make it such a popular choice for merchants. Flexible and scalable: Magento can be customized to meet the unique needs of your business, whether youre just starting out or have a large and complex enterprise-level store.

Powerful marketing tools: Magento offers a range of marketing tools, including promotions, discounts, and email marketing campaigns, to help you attract and retain customers. Mobile-friendly: With the rise of mobile shopping, its important that your online store is optimized for mobile devices.

Magento is designed to work seamlessly on mobile devices, ensuring that your customers can browse, buy, and engage with your store from anywhere. Multi-store functionality: If you have more than one online store, Magento makes it easy to manage them all from a single dashboard.

Robust reporting tools: With Magentos advanced reporting functionality, you can track sales, monitor customer behavior, and gain insights into your stores performance.

System requirements and prerequisites

Now that weve seen some of the benefits of Magento, lets dive into the system requirements and other prerequisites you need to have in place before building your store. CentOS 7: Magento runs on the CentOS 7 operating system.

Youll need to ensure that your server is running CentOS 7 or a compatible version. RAM: Magento requires at least 2GB of RAM on your server, with 4GB or more recommended for optimal performance.

Swap file: A swap file is a space on your servers hard drive that can be used to store inactive memory. Magento recommends setting up a swap file thats equal in size to your servers RAM.

Domain name: Before you can install Magento, youll need to have a domain name registered and pointing to your servers IP address. Nginx: Nginx is a high-performance web server thats recommended for running Magento.

Youll need to install and configure Nginx on your server. MySQL: Magento requires a MySQL database to store its data.

Youll need to install and configure MySQL on your server. PHP 7.1: Magento requires PHP version 7.1 or later.

Youll need to install and configure PHP 7.1 on your server. SSL certificate: An SSL certificate is essential for securing your stores transactions and keeping your customers data safe.

Youll need to obtain and install an SSL certificate on your server.

Magento Access Key Pair

Finally, lets take a look at how to generate an access key pair for the Magento Marketplace. The Marketplace is a code repository for Magento extensions, themes, and other add-ons that can enhance your stores functionality and design.

To generate an access key pair, follow these steps:

1. Log in to your Magento Marketplace account.

2. Navigate to the Access Keys section of your account dashboard.

3. Click the Create a New Access Key button.

4. Give your new access key a name, and select the appropriate permissions (read-only or full access).

5. Click the Generate Key button.

6. Copy the Access Key and Secret Key values to a safe location, as you wont be able to view them again after leaving the page.

With your access key pair in hand, you can now browse the Marketplace for Magento extensions and themes that can help take your store to the next level.

Conclusion

Building an online store can be a complex process, but Magento makes it easier with its flexible and scalable platform, powerful marketing tools, and robust reporting functionality. And with the right system requirements and access key pair in place, youll be well on your way to creating a successful online store that meets the needs of your business and your customers.

3) Create MySQL Database

When building a website with Magento, it’s important to have a MySQL database to store your site’s data. MySQL is a popular open-source relational database management system thats compatible with Magento.

Alternatively, you can use MariaDB, a MySQL fork thats also compatible with Magento. In this section, we’ll take a closer look at how to install MySQL/MariaDB and create a new database and user.

Compatibility and installation of MySQL/MariaDB

Before installing MySQL/MariaDB, youll need to ensure that your server meets the minimum system requirements for running these database management systems. These include server resources, such as CPU, memory (RAM), and disk space.

The version of MySQL/MariaDB you install should also be compatible with your servers operating system. To install MySQL on CentOS 7, you can use the following command:

sudo yum install mariadb-server mariadb

Once the installation is complete, you can start the MySQL/MariaDB service with the following command:

sudo systemctl start mariadb

Creating a new database and user

With MySQL/MariaDB installed, you can create a new database for your Magento site. Follow these steps:

1.

Log in to your server as the root user. 2.

Start the MySQL/MariaDB command-line client by running the following command:

mysql -u root -p

3. Enter your MySQL/MariaDB root password when prompted.

4. Create a new database by running the following command:

CREATE DATABASE magento;

Note: Replace magento with the name you want to give your database.

5. Create a new MySQL/MariaDB user by running the following command:

CREATE USER ‘magento’@’localhost’ IDENTIFIED BY ‘password’;

Note: Replace magento with the name you want to give your Magento database user, and password with the password you want to use.

6. Grant privileges to the new database user by running the following command:

GRANT ALL PRIVILEGES ON magento.* TO ‘magento’@’localhost’;

Note: Replace magento with the name you gave your Magento database, and magento with the name you gave your Magento database user.

7. Flush the MySQL/MariaDB privileges by running the following command:

FLUSH PRIVILEGES;

Your Magento site is now ready to use the new MySQL/MariaDB database.

4) Install PHP extensions

To run Magento, youll need to install a number of PHP extensions. PHP is a server-side scripting language that powers Magento and many other web applications.

In this section, well look at how to enable the PHP 7.1 Remi repository, install the required PHP extensions, and set PHP options. Enabling PHP 7.1 Remi repository

To enable the PHP 7.1 Remi repository, you can run the following command:

sudo rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm

sudo yum-config-manager –enable remi-php71

This will enable the Remi repository for PHP 7.1 on your CentOS 7 server.

Installing required PHP extensions

To install the required PHP extensions, you can run the following command:

sudo yum install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysqlnd

This will install the necessary extensions for Magento to run smoothly on your server.

Setting PHP options

PHP has many customizable options that can be set to improve performance and security. To set PHP options, you can edit the /etc/php.ini file.

Some of the most important options to consider include:

– Upload maximum filesize: This option determines the maximum size of files you can upload to your site. – Memory limit: This option determines how much memory PHP can allocate to scripts running on the server.

– Error reporting: This option controls how errors are reported in PHP. – Timezone: This option sets the default timezone for your server.

Make sure to restart your web server after making changes to the PHP configuration file with the following command:

sudo systemctl restart httpd

Conclusion

By installing MySQL/MariaDB and the required PHP extensions, youve set up the foundation for running Magento on your CentOS 7 server. By following the steps outlined in this article, you can create a new database and user for your Magento site, and set up PHP with the necessary extensions and options to ensure a smooth running site.

With these prerequisites in place, you can move on to installing and configuring Magento itself.

5) Install Composer

Composer is a dependency manager for PHP that allows you to manage packages and their dependencies in your PHP applications. It simplifies the process of installing, updating, and managing packages that are required for your application to run.

In this section, we’ll take a closer look at how to install Composer globally on your CentOS 7 server.to Composer as a dependency manager for PHP

Composer is designed to help PHP developers manage packages and their dependencies in their applications. With Composer, you can easily install packages, update packages, and manage dependencies between packages.

This can be particularly helpful in larger PHP-based projects, where you need to manage many different packages. Composer can also help you stay up to date with security patches and other important updates.

Installing Composer globally

To install Composer globally on your CentOS 7 server, follow these steps:

1. Make sure you have PHP installed on your server.

2. Download the Composer installer script by running the following command:

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

3.

Move the Composer executable to a directory within your system path by running the following command:

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

You have now successfully installed Composer globally on your CentOS 7 server.

6) Create a new System User

To make your Magento installation more secure, its recommended to create a new system user account that will be used to run the Magento application. This system user account will have its own set of permissions and access rights to specific directories on your server.

In this section, well look at how to create a new system user account and set its permissions.

Creating a new user and group for Magento installation

To create a new user and group for your Magento installation, follow these steps:

1. Log in to your server as the root user.

2. Create a new group by running the following command:

sudo groupadd magento

3. Create a new system user by running the following command:

sudo useradd -g magento -d /var/www/html/magento -s /sbin/nologin magento

Note: Replace /var/www/html/magento with the path where your Magento installation files will be stored.

4. Set a password for the new system user account by running the following command:

sudo passwd magento

Setting user permissions and ownership

Once youve created a new system user and group, youll need to set the appropriate permissions and ownership for the Magento installation files. To do this, follow these steps:

1.

Change the ownership of the Magento installation directory to the new system user and group by running the following command:

sudo chown -R magento:magento /var/www/html/magento/

2. Change the permissions of the Magento installation directory to allow the new system user and group to write to the directory:

sudo chmod -R 775 /var/www/html/magento/

Note: Be careful when setting file permissions, as setting incorrect permissions can cause security vulnerabilities.

You have now created a new system user and group for your Magento installation and set the appropriate permissions and ownership for the Magento installation files. This will help ensure the security and stability of your Magento application.

Conclusion

In this article, weve looked at how to install Composer globally on your CentOS 7 server, and create a new system user and group for your Magento installation. These steps will help ensure the security and stability of your Magento application, making it easier to manage dependencies and packages with Composer, while ensuring correct permissions and ownership for the Magento installation files.

With these prerequisites in place, youre now ready to move on to installing and configuring Magento according to your needs.

7) Configure PHP FPM

PHP-FPM (FastCGI Process Manager) is a PHP processor that allows for better performance and scalability when running PHP applications. In this section, we will explore how to configure PHP-FPM for your Magento installation, including setting up the PHP configuration and creating an FPM pool for the Magento user.

PHP configuration and FPM pool creation for Magento user

To configure PHP-FPM for your Magento installation, follow these steps:

1. Locate the PHP configuration file on your server.

The path to this file may vary depending on your server setup, but it is commonly found at /etc/php.ini or /etc/php/7.1/fpm/php.ini. Open the file using a text editor.

2. Edit the PHP configuration settings as needed to optimize performance and accommodate the requirements of your Magento installation.

Some key settings to consider modifying include:

– memory_limit: Increase the value of this setting to ensure sufficient memory is allocated to PHP to handle Magento’s resource-intensive tasks. For example, set it to 512M or higher.

– max_execution_time: Increase the value to allow PHP to run longer scripts, as Magento’s installation process can be time-consuming. For example, set it to 180 or higher.

– max_input_vars: Increase the value to allow PHP to handle a larger number of form variables. For example, set it to 3000 or higher.

– post_max_size and upload_max_filesize: Adjust these settings to accommodate the sizes of files that you may upload or process in your Magento installation. 3.

Save the changes and exit the file. 4.

Now, create a new FPM pool specifically for the Magento user. Locate the FPM pool configuration directory, which is typically found at /etc/php-fpm.d or /etc/php/7.1/fpm/pool.d, and navigate to that directory.

5. Create a new FPM pool configuration file for the Magento user.

For example, create a file called magento.conf using a text editor. 6.

In the new FPM pool configuration file, add the following settings:

[magento]

user = magento

group = magento

listen = /run/php/magento.sock

listen.owner = magento

listen.group = magento

pm = ondemand

pm.max_children = 50

pm.process_idle_timeout = 10s

pm.max_requests = 500

7. Save the changes and exit the file.

8. Restart the PHP-FPM service for the changes to take effect.

Use the following command:

sudo systemctl restart php-fpm

You have now successfully configured PHP-FPM for your Magento installation, optimizing performance and creating a dedicated FPM pool for the Magento user.

8) Install Magento

When installing Magento, it is recommended to avoid using the official Magento GitHub repository for production installations. Instead, Magento provides official repositories that can be used with Composer to install the platform.

In this section, we will walk through the steps to install Magento from the repositories using Composer and set options for the installation via the command line.

Avoiding GitHub repository for production installation

Using the official Magento GitHub repository for production installations is discouraged due to potential security risks and limited control over the codebase. Instead, Magento provides two official repositories: magento/project-community-edition and magento/project-enterprise-edition.

These repositories contain the necessary files and dependencies for a production-ready installation.

Installing Magento from repositories using Composer

To install Magento from the official repositories using Composer, follow these steps:

1. Navigate to the directory where you want to install Magento.

For example, /var/www/html/magento. 2.

Run the following Composer command to create a new Magento project:

composer create-project –repository=https://repo.magento.com/ magento/project-community-edition . Note: Replace magento/project-community-edition with magento/project-enterprise-edition if you are installing the enterprise edition.

3. Composer will prompt you to enter your Magento Marketplace access keys.

These keys can be generated from your Magento Marketplace account. Follow the prompts to enter the access keys.

4. Once the installation is complete, run the following command to set the correct ownership and permissions for the Magento files:

sudo chown -R magento:magento /var/www/html/magento/

sudo chmod -R 755 /var/www/html/magento/

Setting options for install with the command line

During the installation process, Magento provides a command-line interface (CLI) that allows you to set various options and configurations. Here are some key options you can set during installation:

– Base URL: Set the base URL of your Magento site.

– Admin username and password: Set the username and password for the admin panel. – Database options: Specify the database name, username, password, and host.

– Encryption key: Generate and set an encryption key that is used to secure sensitive data in Magento. – Timezone: Set the default timezone for your store.

– Currency: Set the default currency for your store. By setting these options during installation, you can streamline the initial configuration of your Magento installation.

Conclusion

In this article, we have explored the process of configuring PHP-FPM for your Magento installation, ensuring optimal performance and creating dedicated FPM pools. We have also mentioned the recommended approach of avoiding the use of the official Magento GitHub repository for production installations and instead installing Magento from the official repositories using Composer.

By following these steps and setting appropriate options during installation, you can successfully install Magento and customize it to meet your specific requirements.

9) Create the Magento crontab

Magento relies on cron jobs to perform various tasks, such as indexing data, cleaning the cache, and sending transactional emails. In this section, we will provide an overview of Magento cron jobs and walk you through the process of creating the Magento crontab using the command line.

Overview of Magento cron jobs

Cron is a time-based job scheduler in Unix-like operating systems. Magento uses cron jobs to schedule and automate various tasks that need to run periodically.

These tasks include indexing product data, generating sitemaps, sending newsletters, and more. By setting up and configuring the Magento crontab, you enable these tasks to execute on a predetermined schedule.

Creating the Magento crontab using the command line

To create the Magento crontab, follow these steps:

1. Log in to your server as the Magento user.

2. Open a command prompt or terminal.

3. Run the following command to edit the Magento crontab:

crontab -e

4.

If prompted, choose a text editor to edit the crontab. 5.

Add the following lines to the crontab file:

*/5 * * * * /bin/magento cron:run –group=default

*/5 * * * * /bin/magento cron:run –group=php

*/5 * * * * /bin/magento cron:run –group=index

*/5 * * * * /bin/magento cron:run –group=system

Note: Replace with the absolute path to your Magento installation directory. This configuration runs the Magento cron jobs every five minutes.

The “–group” parameter specifies different cron job groups, allowing you to control the execution frequency for different tasks. 6.

Save the changes and exit the crontab file. 7.

Restart the cron service to apply the changes:

sudo systemctl restart crond

You have now successfully created the Magento crontab, which will execute the scheduled tasks at the specified intervals.

10) Configure Nginx

Nginx is a high-performance web server that can be used to serve your Magento installation. In this section, we will explore the process of installing and configuring Nginx for Magento, including creating a new server block and including the default Nginx configuration shipped with Magento.

Installing and configuring Nginx for Magento installation

To install Nginx, use the following command:

sudo yum install nginx

Once Nginx is installed, you’ll need to configure it to serve your Magento installation. 1.

Navigate to the Nginx configuration directory, typically located at /etc/nginx/conf.d/ or /etc/nginx/sites-available/. 2.

Create a new Nginx server block configuration file for your Magento installation. For example, create a file called magento.conf using a text editor.

3. In the new server block configuration file, add the following configuration:

server {

listen 80;

server_name your_domain.com;

root /var/www/html/magento/pub;

include /var/www/html/magento/nginx.conf.sample;

}

Note: Replace your_domain.com with your actual domain name, and /var/www/html/magento/pub with the path to your Magento installation’s “pub” directory.

4. Save the changes and exit the file.

Creating a separate server block allows you to customize the Nginx configuration for your Magento installation.

Including the default Nginx configuration shipped with Magento

Magento provides a default Nginx configuration file that can be included in your server block configuration. This file contains the necessary Nginx directives and optimizations for running Magento.

To include the default Nginx configuration, follow these steps:

1. Download the default Nginx configuration file using the following command:

sudo curl -o /var/www/html/magento/nginx.conf.sample https://raw.githubusercontent.com/magento/magento2/2.4/nginx.conf.sample

Note: Replace /var/www/html/magento/ with the path to your Magento installation directory.

2. Open the server block configuration file you created earlier, and add the following line:

include /var/www/html/magento/nginx.conf.sample;

3.

Save the changes and exit the file. Restart the Nginx service to apply the changes:

sudo systemctl restart nginx

You have now successfully configured Nginx for your Magento installation, including creating the server block and including the default Nginx configuration provided by Magento.

Conclusion

In this article, we covered the process of creating the Magento crontab to schedule and automate tasks using cron jobs. We also explored the installation and configuration of Nginx for serving your Magento installation, including creating a new server block and including the default Nginx configuration shipped with Magento.

By following these steps, you can ensure that tasks are executed on schedule and that Nginx is properly configured to serve your Magento site, optimizing performance and ensuring proper functioning of your e-commerce store. 11)

Conclusion

In this article, we have covered the steps to install and configure Magento 2 on CentOS 7, ensuring that your e-commerce store is set up for success. Let’s summarize the key steps covered:

1)

to Magento and Prerequisites: We began with an overview of Magento’s features and benefits, as well as the system requirements and prerequisites needed for a smooth installation.

These prerequisites included CentOS 7, RAM, swap file, domain name, Nginx, MySQL, PHP 7.1, and an SSL certificate. 2)

Magento Access Key Pair: We explored the importance of generating an access key pair for the Magento Marketplace, which is a code repository for extensions and themes.

This key pair allows authentication and access to the marketplace.

3) Create MySQL Database: We discussed the compatibility and installation of MySQL/MariaDB and provided step-by-step instructions for creating a new database and user for your Magento installation.

4) Install PHP extensions: We showed you how to enable the PHP 7.1 Remi repository, install the necessary PHP extensions, and set PHP options to optimize your Magento installation.

5) Install Composer: We introduced Composer as a dependency manager for PHP and explained how to install it globally on your CentOS 7 server to manage packages and their dependencies in your Magento application.

6) Create a new System User: We emphasized the importance of creating a new system user and group for your Magento installation, and provided instructions for setting user permissions and ownership for enhanced security and stability.

7) Configure PHP FPM: We covered the configuration of PHP-FPM, including setting up the PHP configuration and creating an FPM pool for the Magento user to optimize performance and manage PHP processes.

8) Install Magento: We discouraged using the official Magento GitHub repository for production installations and instead recommended installing Magento from the official repositories using Composer. We also highlighted the importance of setting options for installation via the command line.

9) Create the Magento crontab: We explained the significance of Magento cron jobs for scheduling and automating various tasks, and detailed the process of creating the Magento crontab using the command line.

10) Configure Nginx: We discussed the installation and configuration of Nginx for serving your Magento installation, including creating a server block and including the default Nginx configuration provided by Magento. By following these steps, you can confidently install and configure Magento 2 on CentOS 7, ensuring a secure and optimized setup for your e-commerce store.

Remember to take into account the specific requirements and customizations needed for your business. Good luck with your Magento journey!

In conclusion, installing and configuring Magento 2 on CentOS 7 is crucial for building a successful e-commerce store.

By ensuring that you meet the system requirements, generate an access key pair for the Magento Marketplace, create a MySQL database, install PHP extensions, configure PHP FPM, create a new system user, set up the Magento crontab, and configure Nginx, you can establish a resilient and high-performing platform. Following these steps will optimize the performance, security, and stability of your Magento installation, allowing you to provide an exceptional shopping experience to your customers.

Remember, a well-structured and properly configured Magento store is the foundation for your e-commerce business’s growth and success in the digital marketplace.

Popular Posts