How to install Magento 2 without any errors

As we are experienced before, Magento is a hard-core e-commerce platform in installation process. But, I think Magento 2 is a big change that leverage Magento into the next level. So, the installation process is also easier than ever, but we still have to follow quite closely to any incident situations and I have some experiences in this angles and want to share in this post. Let’s me guide your through the dark and install Magento 2 without errors even though who you are!

Environment Installation

Magento 2 based on Apache 2 or Nginx web server, PHP and MySQL Server. So let’s start with 3 basic objects

Apache 2 & MySQL installation

sudo apt update
sudo apt install -y apache2 mysql-server

PHP installation

For compatible with all Magento 2.2 and 2.3, we will use PHP 7.1.xx for this, it’s very easy to find and install
sudo add-apt-repository ppa:ondrej/php
Enter if you have to answer question in adding steps
sudo apt install -y php7.1 libapache2-mod-php7.1 php7.1-mcrypt php7.1-cli php7.1-xml php7.1-zip php7.1-mysql php7.1-gd php7.1-imagick php7.1-recode php7.1-tidy php7.1-xmlrpc php7.1-mbstring php7.1-intl php7.1-soap php7.1-curl php7.1-bcmath php7.1-ctype

Environment Configuration

The easiest way is to install into the default folder of Apache 2 or Nginx is /var/www/html. But, we have to change a little bit about this to make every thing working together

PHP configuration

Access to /etc/php/7.1/apache2 to edit file php.ini with sudo permission.
sudo nano /etc/php/7.1/apache2/php.ini
Change some parameters like below:
memory_limit = 2048
upload_max_filesize = 200M
max_execution_time = 360
max_input_time = 600
So, we are completely finish configurations for PHP

Apache 2 configuration

Edit /etc/apache2/sites-enabled/000-default.conf file
sudo nano /etc/apache2/sites-enabled/000-default.conf
After line that contain DocumentRoot /var/www/html. Insert this block into it

<Directory “/var/www/html”>
     Options Indexes FollowSymLinks MultiViews
     AllowOverride All
     Order deny,allow
     Require all granted

Prepare Magento 2 source code and store it into /var/www for easy remember.
Thanks Mars has summarize some Magento version in here: Magento Download
Example: wget

Next, we will extract all the content of gz file into html folder.
sudo tar -xf 2.3.2_sample_data.tar.gz -C html

Next step, change the permission like Magento suggestions. In this step, we are still in folder /var/www
sudo chown www-data:www-data html/ -R
sudo chmod u+x html/bin/magento
sudo chmod 777 html/var html/generated html/vendor html/pub
cd /var/www/html/ && find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} + && find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} + && chown -R :apache . && chmod u+x bin/magento

Finally, enable rewrite mode: sudo a2enmod rewrite

MySQL configuration

Access through MySQL Cli to create user and database for your own
sudo mysql -u root
When we are access to this, run some command like below
create user 'magento'@'localhost' identified by 'password';
grant all privileges on *.* to 'magento'@'localhost';
flush privileges;
Press Ctrl + D to sign out from CLI

Access again through the account we just have created above:
mysql -u magento -p
Enter your password that you have created above
create database magento;

In here, we are completely finish with preparing environments for Magento 2 installation
Let open browser and fill address with the IP of your server or localhost to start GUI installation. Just read and next, fill information like you have setup above.

Good luck! You can ask me when you have troubles through here or slack account @walter