Clouding offers the preinstalled Magento 2 image, but if you would like to install it yourself, below is a tutorial with all the steps to install the Magento e-commerce platform. Would you prefer our technical team to install it for you? Call us or email soporte@clouding.io, and we will get to work right away so you can start your online business now!
Magento is the most popular content management system for e-commerce websites. This CMS is used by both small and large businesses because it can be adapted to each one's needs thanks to thousands of extensions and themes.
Magento uses MySQL, the programming language PHP and parts of the Zend framework. In the following tutorial, we will explain how to install Magento on a VPS from Clouding with a preexisting installation of LAMP running Ubuntu 20.04.
Before you begin
Before continuing with the tutorial, it is important to have a VPS on Clouding with the following:
- We recommend that your VPS have 2GB or more of RAM due to the processing requirements of Magento.
- To proceed correctly, it is important that the VPS have LAMP installed (Linux, Apache, MySQL, PHP), as well as a basic configuration.
Preparing the server for Magento
First, update the system:
# apt update && apt upgradeNext, install MYSQL:
# apt install mysql-serverInstall apache2:
# apt install apache2Install PHP:
# apt-get install php7.4Magento requires additional PHP dependencies to work properly:
# apt install php7.4-fpm php7.4-common php7.4-mysql php7.4-gmp php7.4-curl php7.4-intl php7.4-mbstring php7.4-xmlrpc php7.4-gd php7.4-xml php7.4-cli php7.4-zip php7.4-bcmath php7.4-soapYou will need to download Elasticsearch to install magento 2:
# cd /opt
# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.6.1-amd64.deb
# dpkg -i elasticsearch-7.6.1-amd64.deb
# systemctl start elasticsearchApache configuration for Magento
Before downloading and installing Magento, Apache needs to be configured to properly handle the traffic and computing tasks of Magento, and some additional modules will need to be installed and enabled.
First, check that you are using version 2.4 of Apache with:
# apache2 -vEnable the rewrite module for Apache:
# a2enmod rewriteCreate a configuration file for Magento:
# touch /etc/apache2/sites-available/magento.conf
And add the following to it:
<Directory /var/www/html/vhosts/magento/www>
Require all granted
</Directory>
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/vhosts/magento/www
ErrorLog /var/www/html/vhosts/magento/logs/error.log
CustomLog /var/www/html/vhosts/magento/logs/access.log combined
<Directory /var/www/html/vhosts/magento/www>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
</VirtualHost>It is important to modify these configuration parameters: ServerName, ServerAlias, ServerAdmin and DocumentRoot.
Create the directories where you will copy Magento:
# mkdir -p /var/www/html/vhosts/magento/{logs,www}Enable the VirtualHost for Magento:
# a2ensite magento.confAnd reload the configuration for Apache:
# systemctl reload apache2Creating the database
Log in to MySQL as the user root:
# mysql -u root -pCreate the database for Magento, create a user, and configure permissions. For this tutorial, we have chosen to name both the database and the user Magento. Replace p4ssw0rd with a strong password.
CREATE DATABASE magento;
CREATE USER 'magento'@'localhost' IDENTIFIED BY 'p4ssw0rd';
GRANT ALL PRIVILEGES ON magento.* TO 'magento';Exit the MySQL shell:
quitPHP configuration
You need to modify two parameters in the PHP configuration for Magento to work correctly. Edit the files /etc/php/7.4/cli/php.ini and /etc/php/7.4/apache2/php.ini. Find the following parameters and modify them as follows:
memory_limit = 2G
date.timezone = Europe/MadridDownload Magento
Download Magento to the installation folder using the following commands:
# cd /var/www/html/vhosts/magento/www/
# git clone https://github.com/magento/magento2.git /var/www/html/vhosts/magento/www/Configuring users and permissions
Create a user for the files of Magento. For simplicity, we will call it magento:
# useradd magentoNext, add it to the group for Apache (www-data):
# usermod -g www-data magentoOnce the user has been created, configure permissions as follows. Run the following commands in the specified order:
# cd /var/www/html/vhosts/magento/www
# find var vendor pub/static pub/media app/etc -type f -exec chmod g+w {} \;
# find var vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} \;
# chown -R magento:www-data ../../magento
# chmod u+x bin/magentoMagento installation
You will need to download and update composer:
# curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer
# composer installProceed with the installation using the command:
# bin/magento setup:install --db-host=localhost --db-name=magento --db-user=magento --db-password=p4ssw0rd --admin-firstname=Soporte --admin-lastname=Clouding --admin-email=your@emailaddress.com --admin-user=soporte --admin-password=p4ssw0rd --language=en_US --currency=USD --timezone=Europe/Madrid --use-rewrites=1It is important to replace all example values with the ones you want to configure:
- base-url: The domain to configure; keep in mind that if you do not want SSL, you will need to specify http.
- admin-firstname / admin-lastname: The administrator's full name.
- admin-email: The email address for resetting the password and receiving notifications
- admin-user / admin-password: The credentials for logging in to the control panel of Magento.
- db-name: Database name
- db-host: MySQL server host; if it is the same server, use localhost.
- db-user: Database user.
- db-password: Password configured for the database.
Assign permissions for the directories:
# chown -R www-data:www-data /var/www/html/vhosts/magento/You're all set! You can now access your Magento store.
To access the administration panel, at the end of the installation you will see :
Magento Admin URI: /admin_XXXXXXAccessing the administration panel is as simple as going to www.ejemplo.com/admin_xxxxx (the result of Magento Admin URI)
SSL configuration
Start by installing certbot:
# apt install certbot python3-certbot-apache# certbot --apache -d ejemplo.com -d www.ejemplo.comThis will automatically redirect traffic over HTTPS.
Magento configuration
If you have accessed the Magento Dashboard, you will see that some Cron Jobs notices have appeared. The following must be configured for proper operation:
Configure Cron Jobs
Open crontab as the magento user we created:
# crontab -u magento -eIf this is your first time using cron, a message will appear asking which editor you want to use. Select one by number.
Add the following at the end of the file:
* * * * * /usr/bin/php /var/www/html/vhosts/magento/www/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /var/www/html/vhosts/magento/www/var/log/magento.cron.log
* * * * * /usr/bin/php /var/www/html/vhosts/magento/www/update/cron.php >> /var/www/html/vhosts/magento/www/var/log/update.cron.log
* * * * * /usr/bin/php /var/www/html/vhosts/magento/www/bin/magento setup:cron:run >> /var/www/html/vhosts/magento/www/var/log/setup.cron.logNote: Remember to replace /var/www/html/vhosts/magento/www with the path of the Magento installation you configured. It is important to run php using the absolute path /usr/bin/php so that it works correctly in Cron Jobs.
The first line handles reindexing. The second and third are required for the Component Manager and system updates.
Now, to check that this configuration works, log out of Magento and log back in. You should not see any notifications.
Configure X-Frame options
We strongly recommend disabling the ability to display the Magento store in a frame to prevent attacks involving clickjacking. To do this, modify the file app/etc/env.php.
Change SAMEORIGIN to DENY, as shown below:
'X-frame-options' => 'DENY',This prevents attackers from embedding your store in a frame (for example, on a malicious site that imitates your store) in an attempt to intercept payments and other confidential customer information.
Remember, if you have questions about this or any other issue related to your servers on Clouding, feel free to email soporte@clouding.io We are here for whatever you need. Get in touch!