Skip to content

Instantly share code, notes, and snippets.

@grafikchaos
Last active August 23, 2018 21:53
Show Gist options
  • Save grafikchaos/923cec6d8587f286ca46fbb755207055 to your computer and use it in GitHub Desktop.
Save grafikchaos/923cec6d8587f286ca46fbb755207055 to your computer and use it in GitHub Desktop.
Magento 2 Installation via command line

Install Magento 2 Community Edition (CE)

Via Composer

You can use the Magento integrator instructions to install download/install Magento 2 via composer

Get the Magento CE metapackage

To get started:

  1. If you haven’t done so already, get your authentication keys.
  2. Log in to your Magento server as, or switch to, the Magento file system owner.
  3. Change to the web server docroot directory, or to a directory you’ve configured as a virtual host docroot.
  4. Enter the following command:
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition <INSTALLATION_DIRECTORY>

When prompted, enter your authentication keys. Your public key is your username; your private key is your password.

This command creates the project and downloads dependencies for it. The project is in a directory named if you provided the parameter or project-community-edition if you did not.

Install/setup via the command line

/usr/bin/env php ~/code/<CLIENT_CODE>/magento2/bin/magento setup:install --language='en_US' \
  --db-host='localhost' \
  --db-name='<CLIENT_CODE>_dev_magento2' \
  --db-user='developer' \
  --db-password='<DB_PASSWORD>' \
  --base-url='http://<CLIENT_CODE>.dev/' \
  --base-url-secure='https://<CLIENT_CODE>.dev/' \
  --admin-user='augustash' \
  --admin-password='<PASSWORD>' \
  --admin-firstname='August' \
  --admin-lastname='Ash' \
  --admin-email='josh@augustash.com'\
  --timezone='America/Chicago' \
  --use-rewrites='1' \
  --use-secure='0' \
  --use-secure-admin='0' \
  --session-save='files' \
  --backend-frontname='manage' \
  --currency='USD'

Change Magento mode to developer

$ n98-magerun2 deploy:mode:set developer

Deploy static assets for themes

The below command will deploy assets for the following themes:

  • Magento/blank
  • Magento/luma
  • Magento/backend
$ n98-magerun2 setup:static-content:deploy

Configure Magento 2 cron tasks

############################
##
##  Magento 2 project crons
##
############################

# <CLIENT_CODE> Magento 2 Project
* * * * * /usr/local/bin/php /path/to/Magento_2_Root/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /path/to/Magento_2_Root/var/log/magento.cron.log
* * * * * /usr/local/bin/php /path/to/Magento_2_Root/update/cron.php >> /path/to/Magento_2_Root/var/log/update.cron.log
* * * * * /usr/local/bin/php /path/to/Magento_2_Root/bin/magento setup:cron:run >> /path/to/Magento_2_Root/var/log/setup.cron.log

NGINX vhost/configuration

You can refer to the sample files for reference of how this was setup on my MacOS Sierra laptop with nginx, percona-server, php56, php70, php71 and dnsmasq installed via homebrew.

# NGINX
# FILE: /usr/local/etc/nginx/conf.d/magento2.conf
#############
# AAI HACK:
# Found it necessary to comment this part out and
# set the $MAGE_ROOT variable in my vhost files
#############
# root $MAGE_ROOT/pub;
index index.php;
autoindex off;
charset UTF-8;
error_page 404 403 = /errors/404.php;
#add_header "X-UA-Compatible" "IE=Edge";
# PHP entry point for setup application
location ~* ^/setup($|/) {
root $MAGE_ROOT;
location ~ ^/setup/index.php {
fastcgi_pass phpfpm;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /usr/local/etc/nginx/fastcgi_params;
}
location ~ ^/setup/(?!pub/). {
deny all;
}
location ~ ^/setup/pub/ {
add_header X-Frame-Options "SAMEORIGIN";
}
}
# PHP entry point for update application
location ~* ^/update($|/) {
root $MAGE_ROOT;
location ~ ^/update/index.php {
fastcgi_split_path_info ^(/update/index.php)(/.+)$;
fastcgi_pass phpfpm;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
include /usr/local/etc/nginx/fastcgi_params;
}
# Deny everything but index.php
location ~ ^/update/(?!pub/). {
deny all;
}
location ~ ^/update/pub/ {
add_header X-Frame-Options "SAMEORIGIN";
}
}
location / {
try_files $uri $uri/ /index.php?$args;
}
location /pub/ {
location ~ ^/pub/media/(downloadable|customer|import|theme_customization/.*\.xml) {
deny all;
}
alias $MAGE_ROOT/pub/;
add_header X-Frame-Options "SAMEORIGIN";
}
location /static/ {
# Uncomment the following line in production mode
# expires max;
# Remove signature of the static files that is used to overcome the browser cache
location ~ ^/static/version {
rewrite ^/static/(version\d*/)?(.*)$ /static/$2 last;
}
location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
add_header Cache-Control "public";
add_header X-Frame-Options "SAMEORIGIN";
expires +1y;
if (!-f $request_filename) {
rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
}
}
location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
add_header Cache-Control "no-store";
add_header X-Frame-Options "SAMEORIGIN";
expires off;
if (!-f $request_filename) {
rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
}
}
if (!-f $request_filename) {
rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
}
add_header X-Frame-Options "SAMEORIGIN";
}
location /media/ {
try_files $uri $uri/ /get.php?$args;
location ~ ^/media/theme_customization/.*\.xml {
deny all;
}
location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
add_header Cache-Control "public";
add_header X-Frame-Options "SAMEORIGIN";
expires +1y;
try_files $uri $uri/ /get.php?$args;
}
location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
add_header Cache-Control "no-store";
add_header X-Frame-Options "SAMEORIGIN";
expires off;
try_files $uri $uri/ /get.php?$args;
}
add_header X-Frame-Options "SAMEORIGIN";
}
location /media/customer/ {
deny all;
}
location /media/downloadable/ {
deny all;
}
location /media/import/ {
deny all;
}
# PHP entry point for main application
location ~ (index|get|static|report|404|503)\.php$ {
try_files $uri =404;
fastcgi_pass phpfpm;
fastcgi_buffers 1024 4k;
fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off";
fastcgi_param PHP_VALUE "memory_limit=768M \n max_execution_time=600";
fastcgi_read_timeout 600s;
fastcgi_connect_timeout 600s;
# Magento variables
fastcgi_param MAGE_RUN_TYPE $MAGE_RUN_TYPE;
fastcgi_param MAGE_RUN_CODE $MAGE_RUN_CODE;
fastcgi_param MAGE_MODE $MAGE_MODE;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /usr/local/etc/nginx/fastcgi_params;
}
# Banned locations (only reached if the earlier PHP entry point regexes don't match)
location ~* (\.php$|\.htaccess$|\.git) {
deny all;
}
# NGINX
# FILE: /usr/local/etc/nginx/conf.d/magento2_nested_wordpress.conf
# ==============================================================================
# Nested WordPress
# ==============================================================================
location @wp {
rewrite ^/wp(.*) /wp/index.php?q=$1;
}
location ^~ /wp {
# assumes it will be in the pub/wp directory
root $MAGE_ROOT;
index index.php index.html index.htm;
try_files $uri $uri/ @wp;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass phpfpm;
fastcgi_buffers 1024 4k;
fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off";
fastcgi_param PHP_VALUE "memory_limit=768M \n max_execution_time=600";
fastcgi_read_timeout 600s;
fastcgi_connect_timeout 600s;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /usr/local/etc/nginx/fastcgi_params;
}
}
# ==========================================
# <PROJECT_CODE> - <STORE_CODE> Multisite 1
# ==========================================
server {
# Server settings
listen 80;
server_name <STORE_CODE>-<PROJECT_CODE>.dev;
# Magento 2 Variables
set $MAGE_ROOT /path/to/code/<PROJECT_CODE>/magento2/pub;
set $MAGE_MODE developer;
set $MAGE_RUN_TYPE store; # or use 'website'
set $MAGE_RUN_CODE <STORE_CODE>; # or use the website code if $MAGE_RUN_TYPE is 'website'
# Project location
root $MAGE_ROOT;
index index.html index.htm index.php;
# Logging
access_log off;
error_log /usr/local/var/log/nginx/<STORE_CODE>-<PROJECT_CODE>-error.log warn;
# Routes
include /usr/local/etc/nginx/conf.d/security.conf;
include /usr/local/etc/nginx/conf.d/assets.conf;
# Uncomment the desired platform
#include /usr/local/etc/nginx/conf.d/magento1.conf;
include /usr/local/etc/nginx/conf.d/magento2.conf;
include /usr/local/etc/nginx/conf.d/magento2_nested_wordpress.conf;
#include /usr/local/etc/nginx/conf.d/drupal7.conf;
#include /usr/local/etc/nginx/conf.d/drupal8.conf;
#include /usr/local/etc/nginx/conf.d/wordpress.conf;
}
# ==========================================
# <PROJECT_CODE> - <STORE_CODE> Multisite 2
# ==========================================
server {
# Server settings
listen 80;
server_name <STORE_CODE>-<PROJECT_CODE>.dev;
# Magento 2 Variables
set $MAGE_ROOT /path/to/code/<PROJECT_CODE>/magento2/pub;
set $MAGE_MODE developer;
set $MAGE_RUN_TYPE store; # or use 'website'
set $MAGE_RUN_CODE <STORE_CODE>; # or use the website code if $MAGE_RUN_TYPE is 'website'
# Project location
root $MAGE_ROOT;
index index.html index.htm index.php;
# Logging
access_log off;
error_log /usr/local/var/log/nginx/<STORE_CODE>-<PROJECT_CODE>-error.log warn;
# Routes
include /usr/local/etc/nginx/conf.d/security.conf;
include /usr/local/etc/nginx/conf.d/assets.conf;
# Uncomment the desired platform
#include /usr/local/etc/nginx/conf.d/magento1.conf;
include /usr/local/etc/nginx/conf.d/magento2.conf;
#include /usr/local/etc/nginx/conf.d/drupal7.conf;
#include /usr/local/etc/nginx/conf.d/drupal8.conf;
#include /usr/local/etc/nginx/conf.d/wordpress.conf;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment