Tutorial: Install Magento on Ubuntu 16.04

Im Durchschnitt wird dieses Tutorial Tutorial: Install Magento on Ubuntu 16.04 mit 5 bewertet, wobei 1.0 die schlechteste und 5.0 die beste Bewertung ist. Es haben insgesamt 814 Besucher eine Bewertung abgegeben.
814 0

Tutorial: Install Magento on Ubuntu 16.04

from gridscale Team Apache CMS Ubuntu
tutorial - how to install Mangeto on ubuntu

With Magento 2 to your own online shop

With Magento 2 CE (Community Edition), it is very easy to build your own online store. There are countless extensions and prebuilt themes, which are mostly free to use.

In this tutorial I will describe you step by step how to prepare your server for Magento and then install the free Community Edition.

Create a few prerequisites

Just create a new cloud server from a vendor of your choice. For gridscale, for example, Directly select a corresponding operating system (Ubuntu 16.04 LTS or Debian 8) and start in 20 seconds.

Log on to your new Cloud Server via SSH as a user root and follow the next steps.

I’m assuming that the server is still completely empty and therefore start with the basic. Depending on how far your system is already preconfigured, you can simply skip the respective steps.

Before each installation, it is recommended to update the server. With gridscale, your server is already up to date after the installation, should not be the case with your provider, you can use the following command:

$ sudo apt-get –y update && sudo apt-get –y upgrade

Step 1 – Install a web server

First install Apache2 as a webserver:

$ sudo apt-get –y install apache2

Next, configure your Apache still. To do this, deactivate the default-config:

$ sudo a2dissite 000-default.conf

Next, create a config file for our online shop. For this you can take the default config as a template:

$ cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/magento.conf

Now edit the currently created Config as follows:

$ nano /etc/apache2/sites-available/magento.conf

Instead of Nano, you can use any other editor.

If you already own a domain for your shop and have assigned it to the server, enter it in the following places. If you want to work with the IP first, then ignore this step, I explain to you later, how you can add the domain also afterwards:

<VirtualHost mydomain.tld:80>
...
...
...
ServerName my-domain.tld
ServerAlias www.my-domain.tld

Now set the root directory for our Magento system:

DocumentRoot /var/www/magento

Magento works with mod_rewrite. So we have to add the following block to the config:

<Directory /var/www/magento/>

Options Indexes FollowSymLinks MultiViews

AllowOverride All

</Directory>

Next, you rename the log files so that later it is easier to filter which logs belong to which page.

ErrorLog ${APACHE_LOG_DIR}/error-magento.log
CostumLog ${APACHE_LOG_DIR}/access-magento.log combined

Here is the complete config:

<VirtualHost my-domain.tld:80>

ServerName my-domain.tld
ServerAlias www.my-domain.tld
ServerAdmin webmaster@localhost
DocumentRoot /var/www/magento/

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

ErrorLog ${APACHE_LOG_DIR}/error-magento.log
CustomLog ${APACHE_LOG_DIR}/access-magento.log combined
</VirtualHost>

Then save everything. Under Nano, you end the editor with Ctrl + X to the question, if you want to save the document you answer with Y.

Now just activate the newly created Config, mod_rewrite and SSL:

$ sudo a2ensite magento.conf && sudo a2enmod SSL && sudo a2enmod rewrite

Apache is already finished. For our Magento system, however, you need a bit more.

Step 2 – Database Server

For this tutorial I use MySQL, but you can of course also take another database server. MySQL can be installed easily via apt-get.

$ sudo apt-get –y install mysql-server

During installation, you will be prompted for a password. This can be left empty, but I recommend you to set a password.

Under Debian and Ubuntu, the ‘MYSQL-server’ package provides you with a small support, which allows you to easily secure the installation of your MySQL server. Do the following:

$ mysql_secure_installation

You are now prompted for your password for the MySQL administrator. Enter the password or leave the field blank if no password is set.

Now you are guided by a few options to make the MySQL server safer. The dialog should be very similar to the following:

$ mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):

OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n] n

... skipping.

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y

... Success!

Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y

... Success!

By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y

- Dropping test database...

ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist
... Failed! Not critical, keep moving...
- Removing privileges on test database...

... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y

... Success!

Cleaning up...
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

Step 3 – Create a database for Magento

Now create a new database for Magento. To do this, log in to your MySQL server using the ‘root’ user.

$ mysql -u root -p

If you have not set a password, leave the parameter ‘-p’. You should get the MySQL prompt. Here you can configure MySQL, create new users and databases and assign rights.

So create database:

$ create database magento;

When you submit a MySQL command, make sure that it ends with a ‘;’. Otherwise, MySQL does not recognize that you have sent the command for execution and waits for further input. If you should forget this, just type it in the new line. MySQL builds the right command from this.

Now you should create your own user for the new database. I usually call the users identical to the database to which a user should access. You can also create another user name. In the following I put the user with the password, my_password ‘s, best to replace this string against a secure password:

$ create user magento@localhost identified by 'mein_passwort';

Now you have a user and a database, but there are no rights assigned so that the new user can access the new database.

The easiest way is to assign all the permissions for the user ‘magento’ to the database ‘magento’. You can do this with the following command:

$ grant all privileges on magento.* to magento@localhost;

MySQL cached the rights, so you must instruct MySQL to re-read the tables. Then you leave the MySQL prompt:

$ flush privileges;
$ exit;

That’s it, it goes on with the next step.

Step 4 – Install PHP

PHP is also installed quickly via apt-get and also some extensions that Magento requires. Use the following command to install all required modules at once:

$ sudo apt-get -y install php libapache2-mod-php php-curl php-mcrypt php-intl php-mbstring php-common php-zip php-gd php-xml php-mysql

Then restart Apache once:

$ sudo service apache2 restart

Step 5 – Install Magento

To install Magento, you must first register on the official Magento site Magento.com. You will also need the login later to get access to the plug-ins.

Once you’ve registered on Magento.com, you will be taken to the “Products & Solutions” in the upper menu bar to” Products “-> “Community Edition” and then “Download Now”. For your servers you need the latest version of the “Full Release (ZIP with no sample data)”. For “Select your format”, I recommend the “Magento Community Edition 2.*.*.tar.gz”.

Unzip the file to the /var/www/magento/ directory:

$ tar -xzf magento-CE-2.*.*-****-**-**-**-**-**.tar.gz -C /var/www/

Small Tip: Write the start of the file name, e.g. “Magen” and use the Tab-button to complete the autorecompletion. This saves you the long-term filing.

Afterwards, you just have to rename the folder you just created:

$ mv /var/www/ magento-CE-2.*.*-****-**-**-**-**-**.tar.gz /var/www/magento

Now just set the right permissions for the folders. To do this, execute the following commands:

$ chown www-data:www-data –R /var/www/magento/*

$ cd /var/www/magento

$ find var vendor pub/static pub/media app/etc -type f -exec chmod g+w {} \;

$ find var vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} \;

$ chmod u+x bin/magento

Step 6 – Set up the Magento

In your browser, get your new server on http://ipordomain/setup

If everything has worked, you should see something in this direction:

get started with magento

After clicking on “Agree and Setup Magento” you will get to the check-out, if you have followed all the steps, it should look as follows:

step1: readiness check

After clicking “Next”, you can enter your database information as follows:

step2: add a database

Then click on “Next” again and direct your web addresses. If you have a domain for your server, enter this instead of the IP:

step3: web configuration

ATTENTION! In order to use HTTPS a domain and a valid certificate is necessary. As you get a free certificate, we’ll show you in the german tutorial Magento SSL encrypt with Let’s Encrypt on Ubuntu.

The next step is to define your time zone, currency and language. Then go back to “Next”:

create admin account

Now it’s time for your admin account. Enter your data here and click “Next” again.

Now you are ready to complete your installation. The actual installation may take some time, depending on the server’s performance. On the last page of the installation you will be informed about important information, such as the encryption key. Take a screenshot or save the contents of the page somewhere. Preserve the information in any case.

Once the installation is complete, your Magento Shop will be available. To work properly, you only have to create the Cron Jobs.

For the next step, switch back to the SSH console.

Step 7 – Set up Cron Jobs

To create the cron jobs change to the crontab:

$ crontab -u www-data -e

When you first open Crontab, you are asked which editor you want to take. I recommend taking Nano again [2].

Copy the following code to the end of the file and save it. Please note that the Magento path may have to be adapted here:

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

Afterwards, you run the Cron Jobs twice, the first time Magento indexed everything and the second time Magento starts to build the cache. Do not worry, this is only the first time:

$ /var/www/magento/bin/magento cron:run && /var/www/magento/bin/magento cron:run

Now you should see the following output:

Ran jobs by schedule.
Ran jobs by schedule.

If this is not the case, please check again, if you have the correct path everywhere.

Next, change to the Magento backend for the first time. To do this, you call up the path defined during the installation:

http://185.102.***.***/admin_******

After you have logged in, you will get a bar with an error message above.

One or more of the Cache Types are invalidated: Page Cache. Please go to Cache Management and refresh cache types. System Messages: 1

Just click on Cache Managment and make a refresh of the cache.

Magento is now ready for use. Click through the individual settings and set up your online shop.

How to make your online store more secure and provide it with a free SSL certificate, I’ll show you in the german tutorial Magento SSL encrypt with Let’s Encrypt on Ubuntu.

With Magento 2 to your own online shop With Magento 2 CE (Community Edition), it is very easy to build your own online store. There are countless extensions and prebuilt themes, which are mostly free to use. In this tutorial I will describe you step by step how to prepare your server for Magento and […]

Schade, dass dir der Artikel nicht gefallen hat.
Was sollten wir deiner Meinung nach besser machen?

Thank you for your feedback!
We will get back to you as soon as the article is finished.

Übrigens: kennst du schon unser Tutorial zum Thema Install Docker on Ubuntu?

×

Developer?

Get the latest gridscale developer tutorials here.
And don’t worry - we won’t spam you