Installing Magento on Ubuntu

On the test, I install Magento in Ubuntu Server 16.04 & PHP 7.

First, update the system and install the necessary components:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install apache2 php mysql-server mysql-client openssl libcurl3 php-curl php-gd php-mcrypt php-xml php-intl php-zip php-mbstring php-soap php-mysql php-cli php-json libapache2-mod-php php-xsl composer

Open the PHP configuration file in a text editor:

sudo nano /etc/php/7.0/apache2/php.ini

And install or make sure that memory_limit is at least 512M:

memory_limit = 512M

Activate the necessary modules:

sudo a2enmod rewrite
sudo phpenmod mcrypt

In the apache2 configuration, add the site or edit the standard:

sudo nano /etc/apache2/sites-enabled/000-default.conf

Add the following parameters inside the VirtualHost tags:

<Directory /var/www/html/magento_test>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>

Restart apache2 to apply the changes:

sudo service apache2 restart

Connect to the MySQL server, create the database and the user:

mysql -u root -p
CREATE DATABASE magento;
CREATE USER magento@localhost IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON magento.* TO magento@localhost IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
exit

Download the archive with the latest version of Magento and unpack it:

cd /tmp/
wget https://github.com/magento/magento2/archive/2.2.3.tar.gz
tar xzvf 2.2.3.tar.gz

Move the files to the web server directory:

sudo mv magento2-2.2.3 /var/www/html/magento_test

Execute the command:

cd /var/www/html/magento_test
sudo composer install

Install on the files of the right, the owner and the group under which the web server is running:

cd /var/www/html/magento_test
sudo find var vendor pub/static pub/media app/etc -type f -exec chmod u+w {} \;
sudo find var vendor pub/static pub/media app/etc -type d -exec chmod u+w {} \;
sudo chmod u+x bin/magento
sudo chown -R www-data:www-data /var/www/html/magento_test/

Open the browser http://SERVER/magento_test and continue the installation process by following the instructions, remember the login/password and “Magento Admin Address”, as it will open the admin panel.

After installation, let’s see where php is located to correctly specify the path in cron jobs (usually it’s in /usr/bin/php):

which php

Open crontab:

sudo crontab -u www-data -e

And add the tasks:

* * * * * /usr/bin/php /var/www/html/magento_test/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /var/www/html/magento_test/var/log/magento.cron.log
* * * * * /usr/bin/php /var/www/html/magento_test/update/cron.php >> /var/www/html/magento_test/var/log/update.cron.log
* * * * * /usr/bin/php /var/www/html/magento_test/bin/magento setup:cron:run >> /var/www/html/magento_test/var/log/setup.cron.log

This completes the installation of Magento.

See also:
Solving the “Autoload error” when installing Magento
Using and configuring CRON

Solving the “Autoload error” when installing Magento

Once installed Magento in Ubuntu and noticed in the browser the following error:

Autoload error

There were also pieces of code, depending on the open page.

In my case, the error occurred because of the uninstalled libapache2-mod-php, installed it with the command:

sudo apt-get install libapache2-mod-php

After that the error did not appear and I continued the installation of Magento.