首页 > 外贸 > magento 2 安装教程 以及安装测试数据
2016
04-09

magento 2 安装教程 以及安装测试数据

 

花了2天来研究这个问题,最终成功安装。参考了大量资料,软件比较新,可以查看的资料非常少。不停的google去查找资源。经过反复尝试,最终实验成功。

先后尝试过LNMP 最新1.3版 用php7,但是试过了很多次,都不成功。

Magneto is an open source e-commerce application owned by eBay. It operates using a LAMP stack on most Linux distributions. This guide will focus on how to setup Magento on Ubuntu 15.04 – but the steps here should work for other versions as well.

Please note that Magento is a very resource-heavy application. For a test server, PHP requires a minimum of 512MB of RAM, but you should use at least 1GB for a small store and 4GB for a medium to large store with hundreds of products.

This tutorial assumes that you are using a freshly created VPS with no installed packages.

Installing

LAMP Stack

First, ensure that the apt-get package library is up to date by running the command below. This will ensure that the latest version of the packages are installed.

$ apt-get update

After this has completed, it is time to install the LAMP components that powers Magento (Linux, Apache, MySQL, PHP). Run the following command with sudo to install all 3 packages in one go. Alternatively, you may install these packages separately using this tutorial.

$ sudo apt-get install lamp-server^

You will need to specify a password for the MySQL root user. Make sure this password is secure and note it down as it will be needed later.

Apache Setup

Before Magneto is installed, we need to configure Apache to properly redirect and rewrite the incoming traffic. Create a virtual host file for Apache using the following command. Here, we use the nano editor, however any text editor could be used.

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

Inside this file, copy and paste our setup options into the nano interface.

<VirtualHost *:80>
    DocumentRoot /var/www/public
    <Directory /var/www/public/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
    </Directory>
</VirtualHost>

It should look similar to the screenshot below.

Save and close the file using Control + O 然后回车一下 ,然后Control + X. Next, we have to tell Apache to use the new config file, and to ignore the default config file. Execute the following commands below (in order):

$ sudo a2ensite magento.conf

$ sudo a2dissite 000-default.conf

Then, reload Apache using the command.

$ sudo service apache2 reload

PHP Setup

PHP also needs to be configured to properly handle the Magento application. As it is an extremely resource heavy application, we need to increase the memory allocation given to PHP. In this case, I will allocate 512MB as this will only be running a test store, however most stores require 1-4GB of memory.

First, open the php.ini config file with a text editor.

$ sudo nano /etc/php5/apache2/php.ini

Find the line which declares the memory limit for PHP and change it to your desired number (in this case, 512MB).

memory_limit = 512M

Save and close the file using Control + O 记得每次都要回车一下and Control + X.

Magento also needs some additional PHP modules which can be installed using apt-get. Execute the following command.

$ sudo apt-get install php5-mcrypt php5-curl php5-gd libcurl3 php5-intl php5-xsl

Once the install finishes, run the following commands.

$ sudo a2enmod rewrite
$ sudo php5enmod mcrypt

Finally, restart Apache.

$ sudo service apache2 restart

MySQL Setup

Magento uses MySQL to store almost all the data associated with the site. We need to create a database for the application to use. Start the MySQL commandline using the command below, using the password from the LAMP setup earlier.

$ mysql -u root -p

Next, execute the command below to create the database.

CREATE DATABASE magento;

Leave the MySQL commandline using Control + C.

Installing Magento

Install composer with the following command:

$ curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

We need to generate a keypair to clone the Magento repo. Since this requires authentication, see the Magento developer documentation for the latest instructions.

Next, place these keys in the auth file for composer using the command below.

$ sudo nano /root/.composer/auth.json

Copy and paste the contents below into the file.下面要获得magento 官方的key,官方有教程。 然后更改下面的 对应的两个key。

{
"http-basic": {
      "repo.magento.com": {
         "username": "<your public key>",
         "password": "<your private key>"
      }
   }
}

CD to the web directory.

$ cd /var/www

Clone the Magento Github repo.

$ git clone -b 2.0 https://github.com/magento/magento2.git public

CD into the cloned folder.

$ cd public

Run composer install to update the dependencies.

 $ composer install

至此安装完成,在浏览器输入域名或者ip,加上 、setup执行在线安装,这个一步一步地操作就行了。

期间可能会遇到一些问题,拿着问题去google一下就可以搞定。

权限

根据你的系统,执行以下命令

Typical examples:

  • CentOS: chown -R :apache .
  • Ubuntu: chown -R :www-data .

记得后面有个点 要加上。

然后执行下面一段命令

find . -type d -exec chmod 770 {} \; && find . -type f -exec chmod 660 {} \; && chmod u+x bin/magento

安装magento 2 simple data

这个是有难度的,看了几个教程,尝试过很多次才搞定。

我们用的是composer安装

执行这个命令,自动下载数据。记得把括号内更换成你的目录

php <your Magento install dir>/bin/magento sampledata:deploy

上面的过程中会让你输入magento key的。记得别忘记了。

 

下载完成以后执行下面命令安装 ,记得把括号内更改成你的目录

php <your Magento install dir>/bin/magento setup:upgrade

上面执行完了以后,可能有一个小错误提示,Please re-run Magento compile command 这个是可以忽略的。

全部执行以后,返回看你的网站,发现网站打不开了,这个时候搜索过很多,都没找到原因。

后来发现,重新执行了下权限命令,网站可以访问了。

我的用系统

  • Ubuntu: chown -R :www-data .

 

后记:

不吃不喝研究了两天,痛苦的过程。先后使用了linode vultr等vps。


 

参考:https://www.vultr.com/docs/installing-magento-2-on-ubuntu

安装magento 2 测试数据参考 http://devdocs.magento.com/guides/v2.0/install-gde/install/sample-data-after-composer.html

 

最后编辑:
作者:ning
这个作者貌似有点懒,什么都没有留下。