Magento is one of the most popular open-source e-commerce platform written in PHP powered by Zend framework. In this tutorial, you will learn the steps required to install and setup Magento on your Linux/Centos 7 server.
To install and start Apache use the following commands:
$ sudo yum install httpd $ sudo systemctl start httpd $ sudo systemctl enable httpd
Create a new configuration file name magento.conf:
$ sudo vim /etc/httpd/sites-available/magento.conf
Paste the following code into the newly created config file:
<VirtualHost *:80> ServerAdmin email@example.com DocumentRoot /var/www/html/magento/ ServerName domain.com ServerAlias www.domain.com <Directory /var/www/html/magento/> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> ErrorLog /var/log/httpd/magento_error.log CustomLog /var/log/httpd/magento_access.log combined </VirtualHost>
Now with this, you will be debugging all the Magento setup related errors in the magento_error.log and magento_access.log
Use the below command to install all required PHP dependencies:
$ sudo yum -y install php72u php72u-pdo php72u-opcache php72u-xml php72u-gd php72u-devel php72u-intl php72u-mbstring php72u-json php72u-iconv php72u-mysqlnd php72u-fpm php72u-bcmath php72u-soap unzip
Open the php.ini file:
$ sudo vim /etc/php.ini
Change the following credentials:
file_uploads = On allow_url_fopen = On short_open_tag = On memory_limit = 512M upload_max_filesize = 128M max_execution_time = 3600
Restart Apache service:
$ sudo systemctl restart httpd
$ wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
$ sudo rpm -ivh mysql57-community-release-el7-9.noarch.rpm
$ sudo yum install mysql-server
$ sudo systemctl start mysqld
- Once the installation completes, a temporary password will be generated in the mysqld.log file. You can access this password by the following command:
$ sudo grep 'temporary password' /var/log/mysqld.log
- Now you will get a message something like the following:
[Note] A temporary password is generated for root@localhost: ,b*-rkuIR4Zas
- Copy this password for the next step and enter the following command:
$ sudo mysql_secure_installation
- This will prompt you to enter the root password. You can enter the copied password which you got in the previous step.
- After entering the password you will be prompted to enter a new MySQL password.
- Enter a new 12 character password with uppercase, lowercase letters, numerical and a special character
- You will now be prompted with multiple questions on how to set up the MySQL installation. You can say yes to all except if asked to change the password again.
$ sudo mysql -u root -p
mysql > create database magento; mysql > CREATE USER 'magentouser'@'localhost' IDENTIFIED BY 'password'; mysql > GRANT ALL PRIVILEGES ON * . * TO 'magentouser'@'localhost'; mysql > FLUSH PRIVILEGES; mysql > exit;
You need Composer to install all the Magento and its dependencies.
Use the below command to install composer globally on your ubuntu system:
$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" $ sudo php composer-setup.php --install-dir=/usr/bin/ --filename=composer
Check the composer installation by the following command:
$ composer -v
In order to install Magento in the next step, you will have to specify Public and Private keys from your Magento market-place account. If you haven't registered yet you can register here.
After this, your Public and Private key will be generated. Use these keys for installation in the next step.
Enter your servers root directory
Run the composer command to install Magento
sudo composer create-project --repository=https://repo.magento.com/ magento/project-community-edition magento
You will be prompted to provide a username password for this. Put your public key as the username and the private key as the password. It will take some time for the Composer to download and install all the required dependencies so be patient.
Open this link.
In the download tab, select your preferred version and click on download.
Follow the below commands:
$ sudo mkdir /var/www/html/magento/ $ sudo unzip ~/Downloads/magento2-ce.zip -d /var/www/html/magento/
If you have downloaded zip file to your local machine follow these steps
# On local machine $ scp -r magento2-ce.zip user@<your-domain-name/ip-address>:/var/www/html/magento/magento.zip # On remote server $ cd /var/www/html/magento/ $ sudo unzip magento.zip
Install dependencies from using composer
$ composer install
After following the installation steps we can now open the Magento setup in your specified domain name or server IP address. for example <www.domain.com> or IP address <184.108.40.206>
If you are getting 500 error after the installation please follow these steps:
$ sudo chown -R www-data:www-data /var/www/html/magento $ sudo chmod -R 755 /var/www/html/magento
You have to set the user group according to your setup.
Your user group will depend on your Http server instance. In our case it was www-data it might be nginx or apache by default depending on the setup. You can check that by using
$ ps aux | grep apache $ groups <apache-user>
If you are still getting errors you can debug those errors by referring the following logs
tail -f /var/log/httpd/magento_error.log tail -f /var/log/httpd/magento_access.log
Now you just have to wait for the installation to complete.
After the successful installation, all of your Magento setup details will be shown, you can note these and click on Launch Magento Admin.
This will open the login panel for Magento and you can log in with your admin credentials.
Cronjob is nothing but a scheduler that runs a specified file path at a specified interval. Magento needs some of these Cron Jobs to be set up in order to function properly.
Use the below commands to add the cron:
$ cd /var/www/html/magento $ sudo php bin/magento cron:install
You can check the installed Magento Cron Jobs by using the below command:
$ sudo crontab -l
You should find theses settings in your Cron:
* * * * * /usr/bin/php /var/www/html/magento/bin/magento cron:run 2>&1 | grep -v "Ran jobs by schedule" >> /var/www/html/magento/var/log/magento.cron.log * * * * * /usr/bin/php /var/www/html/magento/update/cron.php >> /var/www/html/magento/var/log/update.cron.log * * * * * /usr/bin/php /var/www/html/magento/bin/magento setup:cron:run >> /var/www/html/magento/var/log/setup.cron.log
And with this, your Magento setup is up and ready to be used for your E-Commerce site.
By following the above-mentioned steps you are now ready to create your e-commerce platform with a working Magento installation. In case you have encountered something, which is not covered as a part of this tutorial, then please feel free to share those below in the comments.