Install Magento on CentOS 7, with Nginx, PHP-FPM and MariaDB

magento-logoMagento is a very popular and feature rich open source e-commerce web application. Magento is fully customizable to meet the users requirements and allowing them to create and launch a fully functional online store in minutes. In this tutorial we will show you how to install Magento on a CentOS 7 VPS with Nginx web server, PHP-FPM and MariaDB.

As usual, log in to your server as user root and make sure that your CentOS 7 VPS is fully up-to-date

yum -y update

Magento needs a database, so we will install MariaDB server and create an empty database for the store

yum install mariadb mariadb-server

Start the MariaDB server and enable it to start on boot

systemctl start mariadb
systemctl enable mariadb

Run the mysql_secure_installation post-installation script to improve the security of the MariaDB server and set the root password.

Now, log in to the MariaDB server console and create a database

mysql -u root -p
mysql> CREATE DATABASE magentodb;
mysql> GRANT ALL PRIVILEGES ON magentodb . * TO magentouser@'localhost' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;

Don’t forget to change PASSWORD with an actual strong password.

Next, we will install Nginx web server. It is not available by default in CentOS 7 so we will use the official Nginx repository

rpm -UVh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum install nginx

Start the Nginx web server and enable to start on boot

systemctl start nginx
systemctl enable nginx

Install PHP and few PHP modules

yum install php php-fpm php-cli php-mysql php-curl php-gd

Now, go the Magento’s official website and download the latest stable version. At the moment of writing this article it is version 1.9.1.0

wget http://www.magentocommerce.com/downloads/assets/1.9.1.0/magento-1.9.1.0.tar.gz

Unpack the Magento archive to the document root directory on your server

tar -xvzf magento-1.9.1.0.tar.gz -C /var/www/html/
rm magento-1.9.1.0.tar.gz

The content of the archive will be unpacked in a new ‘magento’ directory inside the document root.

Set proper permissions:

cd /var/www/html/magento
chmod -R o+w app/etc/
chmod -R o+w var/
chmod -R o+w media/

Create an Nginx virtual block for your domain with the following content

nano /etc/nginx/conf.d/magentodomain.conf

server {
listen 80 default;
server_name www.magentoodomain.com *.magentoodomain.com;
root /var/www/html/magento

location / {
index index.html index.php;
try_files $uri $uri/ @handler;
expires 30d;
}

location ^~ /app/                { deny all; }
location ^~ /includes/           { deny all; }
location ^~ /lib/                { deny all; }
location ^~ /media/downloadable/ { deny all; }
location ^~ /pkginfo/            { deny all; }
location ^~ /report/config.xml   { deny all; }
location ^~ /var/                { deny all; }

location /var/export/ {
auth_basic           "Restricted";
auth_basic_user_file htpasswd;
autoindex            on;
}

location  /. {
return 404;
}

location @handler {
rewrite / /index.php;
}

location ~ .php/ {
rewrite ^(.*.php)/ $1 last;
}

location ~ .php$ {
if (!-e $request_filename) { rewrite / /index.php last; }

expires        off;
fastcgi_pass   127.0.0.1:9000;
fastcgi_param  HTTPS $fastcgi_https;
fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
fastcgi_param  MAGE_RUN_CODE default;
fastcgi_param  MAGE_RUN_TYPE store;
include        fastcgi_params; ## See /etc/nginx/fastcgi_params
}
}

Replace all instances of magentoodomain.com with your own domain name. and restart Nginx for the changes to take effect.

systemctl restart nginx

We are done with the command line installation. Now, launch the web based Magento installer by accessing http://magentodomain.com and complete the required the steps to finish the installation

Of course you don’t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to install Magento for you. They are available 24×7 and will take care of your request immediately. You can also checkout our guide on How to Install Magento 2 on CentOS 8.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

2 thoughts on “Install Magento on CentOS 7, with Nginx, PHP-FPM and MariaDB”

  1. i guess there are sone problem when im going to the ip m getting “No data received

    ERR_EMPTY_RESPONSE” error problem with
    expires off;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_param HTTPS $fastcgi_https;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param MAGE_RUN_CODE default;
    fastcgi_param MAGE_RUN_TYPE store;
    include fastcgi_params; ## See /etc/nginx/fastcgi_params

    specifically

    “fastcgi_param HTTPS $fastcgi_https;”

    Reply

Leave a Comment