This tutorial is all about installing Magento Community Edition in CentOS 7 Operating System. Magento is an Open Source eCommerce software now owned by eBay, Inc. Due to its opensource support base, it has become a very popular open-source product to run any types of eCommerce website.
Magento employs the MySQL relational database management system, the PHP programming language, and elements of the Zend Framework.
As it is free to install and use, it helps to host an awesome eCommerce site on the go with low cost. Now, no need to spend thousands of dollars on custom and proprietary software. This quick tutorial is a complete guide on setting up Magento on your LAMP stack. The LAMP stack is a collection of opensource applications that makes it possible run scripts written in PHP which includes, Apache, MySQL and PHP out of Linux. Here are the steps below on how we can setup Magento Community Edition in CentOS 7.
1. Installing LAMP Stack
Before we start, we'll need to make sure if we have LAMP Stack installed on our server or machine or not. If its installed we can simply skip this step and goto next step else need to follow this step too.
a) Installing Apache Web Server
First of all, we'll gonna install Apache Web Server. To install it, we need to run the following command in a shell or terminal.
$ sudo yum install httpd
After installing run the following command to start the server.
$ sudo systemctl start httpd.service
Now, If we want Apache2 to automatically start up everytime we reboot the server, we'll run the commands below.
$ sudo systemctl enable httpd.service
After running the above commands, we'll want to open Apache2 default configuration file using a text editor and find the lines between </Directory “/var/www/”> </Directory> and we'll change the value to look like the block below.
$ sudo nano /etc/httpd/conf/httpd.conf
After we edit the file and complete the above task, we'll need to save the file and then exit it.
b) Installing MariaDB Server
Now, after we install Apache Web Server, we'll go for MariaDB Server for our Database of Magento. To install MySQL Server in our CentOS 7 Server, we'll run the following commands.
$ sudo yum install mariadb-server mariadb
After the installation is completed, we'll want to start the server.
$ sudo systemctl start mariadb.service
And we also want to make MariaDB Server to startup automatically in every reboot.
$ sudo systemctl enable mariadb.service
Now, to configure and setup our mysql server, run the following command.
When you run the above command, it will prompt you to create a new password for the database root user, and also to enable some secure options. Always choose Y for yes when prompted.
c) Installing Php5 and its modules
After we successfully installed Apache Web Server and MySQL Database server, we'll go for installing Php5 and other Php modules. To install them, we'll need to run the following command in a shell or a terminal.
$ sudo yum install php php-gd php-mysql php-tidy php-xmlrpc php-common php-cli php-xml
Magento requires php-mcrypt, but that packages isn’t available in CentOS 7 default repository so, we'll need to add other repositories that contain the package in order to use. So, we'll need to add a new repository and then install php-mcrypt on our system.
$ cd /tmp/ && wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
$ sudo yum install epel-release-7-5.noarch.rpm
$ rpm --import http://rpms.famillecollet.com/RPM-GPG-KEY-remi
$ rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
As we have added our new repository for installing php-mcrypt, we'll now install it by running the command below.
$ sudo yum install php-mcrypt
After installing them, we'll open its configuration file and increase the memory limit for PHP scripts to about 512MB. Run the commands below to open the file.
$ sudo nano /etc/php.ini
Then we'll change the memory limit to 512MB, then save the file and exit.
memory_limit = 512M
2. Downloading Magento Community Edition
Now, as we have successfully installed our LAMP Stack in our Centos 7 Server. Now, we'll install our Magento Community Edition in over our LAMP Server to make it workable. The Magento Community Edition can be easily and freely download from the offical download site also. To download and extract over our Apache Web Server, we'll want to run the following commands in a terminal or shell.
$ cd /tmp/ && wget http://www.magentocommerce.com/downloads/assets/220.127.116.11/magento-18.104.22.168.zip
Now, we'll extract the download compressed zip file.
$ sudo unzip magento*.zip
We'll then copy the extracted files to our Apache Web Server's Webroot ie /var/www/html/ .
$ sudo cp -rf magento/* /var/www/html/
Now, we need to fix the ownership of the Apache Web Server Webroot. To do that we'll need to run the following command.
$ sudo chown -R apache:apache /var/www/html/
Next, we'll also need to fix the permission of the files so that Magento will work fine.
$ sudo chmod -R 755 /var/www/html/
3. Configuring Magento Database
After we complete extracting our magento to Apache Web Server's Webroot, we'll need to create a new database for Magento. And we'll also need to create a new database user for Magento. To do that, we'll need to run the commands below to logon to the database as the root user.
$ mysql -u root -p
Next, run the SQL statement below to create a database called magento.
> CREATE DATABASE magento;
Then run the commands below to create a new database user called magentouser.
> CREATE USER magentouser@localhost;
Then grant all access and privileges to the new database to the database user by running the commands below.
> GRANT ALL ON magento.* TO magentouser@localhost IDENTIFIED BY 'mypassword';
Note: Please replace the database name, user and password with your to avoid security issues. This details will be used later to setup Magento in web interface.
After we are done, we'll then configure firewall.
4. Configuring Firewall
After completing above steps, we'll need to restart our Apache2 Web Server so that all the changes will take effect correctly.
$ sudo systemctl restart httpd.service
Next, we'll need to open the Firewall Port for HTTP Traffic.
$ sudo firewall-cmd --permanent --zone=public --add-service=http
$ sudo firewall-cmd --permanent --zone=public --add-service=https
$ sudo firewall-cmd --reload
5. Web Interface
Finally, we'll now need to browse our favourite browser to the Server's IP address or domain ie http://ip-address .
If everything went cool as shown above, we should see the Magento Installation Wizard in our browser.
Click Continue then the Localization page will open, change its settings according to one's need then click Continue again.
Now, enter the database name, username and password we created before in step 3 .
If everything was done correctly, Magento should be installed.
To login to Admin Dashboard of Magento, please go to the url http://ip-address/index.php/admin and enter the requried credential created during installation of Magento through web interface. We'll see something like this.
If you run into Magento cannot write to /media/downloadable and /app/etc folder, run the commands below to fix SELinux issues.
$ sudo restorecon -R /var/www/html
$ sudo setsebool -P httpd_unified 1
Hurray! We have successfully installed our latest Magento Community Edition. Magento is an awesome PHP script for better eCommerce Website. It is the world's most famous script used for creating beautiful Online Sales Commerce sites. It is pretty easy to install as we have illustrated above. This script is also available in Cpanel's Softaculous Scripts too. So, if you have any questions, suggestions, feedback please write them in the comment box below. Thank you ! Enjoy Magento :-)