Published on 2020-02-06· Updated on 2021-12-15
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/Ubuntu 18.04 server.
To install and setup Apache use the following commands:
$ sudo apt install apache2 $ sudo systemctl start apache2 $ sudo systemctl enable apache2
Create a new configuration file name magento.conf
$ sudo vim /etc/apache2/sites-available/magento.conf
Paste the following code into the newly created config file
<VirtualHost *:80> ServerAdmin [email protected] 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 ${APACHE_LOG_DIR}/magento_error.log CustomLog ${APACHE_LOG_DIR}/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
$ sudo a2ensite magento.conf $ sudo a2enmod rewrite
Use the below command to install all required PHP dependencies:
$ sudo apt install php7.2 libapache2-mod-php7.2 php7.2-common php7.2-gmp php7.2-curl php7.2-soap php7.2-bcmath php7.2-intl php7.2-mbstring php7.2-xmlrpc php7.2-mcrypt php7.2-mysql php7.2-gd php7.2-xml php7.2-cli php7.2-zip
Open the php.ini file
$ sudo vim /etc/php/7.2/apache2/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 apache2
$ sudo apt install mysql-server
- After the installation 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 this
[Note] A temporary password is generated for root@localhost: b*-rkuIR4Zasd
- Copy this password for the next step
- Enter this command
$ sudo mysql_secure_installation
- This will prompt you to validate your password enter Y
- After this, you will be prompted to set your password strength. Enter your choice between LOW, MEDIUM and STRONG.
- Enter new password
- You can say yes to all the other prompts that come after this
- You will now be prompted with multiple questions on how to set up the MySQL installation. You can set Y to all the prompts
- You will be able to login with the user root and a blank password
$ 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 using the below 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 for installation in the next step.
Enter your servers root directory
cd /var/www/html
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 these commands
$ sudo mkdir /var/www/html/magento/ $ sudo tar -zxvf ~/Downloads/Magento-CE*.tar.gz -C /var/www/html/magento/
For copying from local to the remote machine
# On local machine $ scp -r magento2-ce.zip user@<your-domain-name/ip-address>:/var/www/html/magento/magento.zip # On remote machine $ cd /var/www/html $ mkdir magento $ sudo tar -zxvf magento.zip -C magento/
Install dependencies from using composer
$ cd /var/www/html/magento/ $ composer install
After following the installation steps we can now open the Magento setup in your specified domain name or server IP address.
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 these commands
$ 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/apache2/magento_error.log $ tail -f /var/log/apache2/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.
To add these Crons follow this command.
$ cd /var/www/html/magento $ sudo php bin/magento cron:install
You can check the installed Magento Cron Jobs by using this 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.
Netcorecloud's toolkit is the solution to all your email problems.
Netcore connects & unifies your data across all sources, connects to your marketing channels and provides you with control over AI Powered automation and personalization.
Hitesh Pandey💻
Full Stack Developer, Pepipost
🥑 Developer Evangelist | 🥇Email Geek