Skip to content

Instantly share code, notes, and snippets.

@tylers-username
Last active September 1, 2020 08:34
Show Gist options
  • Save tylers-username/48c6ec37d45a3f96da3d6549cbc67d00 to your computer and use it in GitHub Desktop.
Save tylers-username/48c6ec37d45a3f96da3d6549cbc67d00 to your computer and use it in GitHub Desktop.
Magento 2: Quick Lando Setup
#####
# Built & Tested against: v3.0.0-rc.16
#
# The first time that this project is launched, it will take Lando a while to get past "waiting until nginx service is ready"
# This is because Magento has not yet been setup and is 302-redirecting "/" to "/setup" while Lando is hoping for a "200"
# response. One the setup has completed Lando will show a ready-state much more quickly on the next start-up.
# Give this Lando project a unique name
name: m2-community
# Start with the default LEMP recipe
recipe: lemp
proxy:
# Set Magento URL
appserver_nginx:
- magento2.lndo.site
# Configure the LEMP recipe
config:
# PHP 7.2 for Magento 2.2.3 - adjust as needed
php: '7.2'
webroot: pub
database: mysql
# Optionally activate xdebug
xdebug: false
# Optionally mix in your own config files
#
# If ommitted this will use "sane defaults" for your recipe type
config:
# Relative to Magento project root
vhosts: lando.nginx.conf
#php: config/php.ini
services:
# Provide some custom options for the database service
database:
# Make a random port available to the host machine for your MySQL connection.
# This can be a number if you want to map a specific port
portforward: true
appserver:
# This will only run the first time `lando start` is executed or on `lando rebuild`
build_as_root:
# Install Magento-required xsl extension
- apt-get update -y -q && apt-get install -y libxslt-dev && docker-php-ext-install xsl
tooling:
magento:download:
description: Initialize Magento 2 project in current directory
cmd:
# Quoted to ensure the `cut` command is properly escaped
- "wget $(curl -s https://api.github.com/repos/magento/magento2/releases/latest | grep zipball_url | cut -d '\\\"' -f 4) -O magento_latest.zip"
# Keep `&&` vs multi-line to preserve `tmp` directory when Lando has not been started
- unzip magento_latest.zip -d /tmp/magento-extract && cp --verbose -R /tmp/magento-extract/magento*/. /app
- "rm magento_latest.zip && cp auth.json.sample auth.json && touch lando\\.nginx\\.conf"
# Provide setup instructions
- "echo \"\n Magento has been downloaded! Now...\n
\n\t 1. Add your Magento credentials to auth.json
\n\t\t Magento: https://marketplace.magento.com/customer/accessKeys/
\n\t\t GitHub: https://github.com/settings/tokens
\n\t 2. Add config to `lando.nginx.conf`
\n\t\t Refer to: https://gist.github.com/tylerssn/48c6ec37d45a3f96da3d6549cbc67d00#file-lando-nginx-conf
\n\t 3. `lando start && lando composer install && lando magento:setup:quick && lando magento cache:flush`
\n\n That's it! You will then be able to access your Magento store at https://magento2.lndo.site/ \n
\n\n Run `lando` to see available shortcuts such as `lando magento`! \n
\""
service: appserver
magento:setup:quick:
description: Automated process to quickly configure Magento for Lando. This command accepts `./bin/magento setup:install` arguments
cmd: /app/bin/magento setup:install --db-host database --db-name lemp --db-user lemp --db-password lemp --magento-init-params="MAGE_MODE=developer"
service: appserver
magento:
description: Execute ./bin/magento commands
cmd: /app/bin/magento
service: appserver
magento:setup:destroy:
description: Automated process to quickly reset Magento's database to empty.
cmd: /app/bin/magento setup:uninstall
service: appserver

Lando Magento 2 Template

THIS HAS BEEN MOVED TO improper/lando-magento2-template.

THIS GIST IS NO LONGER SUPPORTED

Important notes

  1. This setup expects Lando to be installed and ready to go on your machine
  2. This setup expects Magento's stock nginx.conf.sample to exist in Magento's project root. Of course you can modify this file as needed moving forward.
  3. You may experience performance gains by adding Redis, Elasticsearch, etc.. These services can easily be added following Lando's documentation.

Quick Setup

  1. Add this Gist's .lando.yml to an empty directory
  2. Run lando magento:download
  3. Add your Magento credentials to auth.json
  4. Copy config to lando.nginx.conf
  5. Launch your new store and deploy the database: lando start && lando composer install && lando magento:setup:quick && lando magento cache:flush
    • Optionally, you can pass the ----use-sample-data to the the lando magento:setup:quick command shown in this step.

That's it! You will then be able to access your Magento store at https://magento2.lndo.site/

HINT: Run lando to see available shortcuts such as lando magento!

lando magento:setup:quick is an alias for lando magento setup:install and is pre-configured to setup the database connection.

  • Defaults to developer mode.
  • See lando magento:setup:quick --help for additional configuration options.
  • For the sake of shortcuts, lando magento:setup:destroy is also available.

If you did not pass additional arguments to lando magento:setup:quick, you will probably want to know your admin URI and to create an admin user.

  • Fetch Admin URI: lando magento info:adminuri
  • Create admin user: lando magento admin:user:create
upstream fastcgi_backend {
server fpm:9000;
}
server {
listen 443 ssl;
listen 80;
listen [::]:80 default ipv6only=on;
server_name localhost;
ssl_certificate /certs/cert.crt;
ssl_certificate_key /certs/cert.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
set $MAGE_ROOT /app;
include /app/nginx.conf.sample;
location ~ \.php$ {
fastcgi_pass fpm:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_buffers 256 128k;
fastcgi_connect_timeout 300s;
fastcgi_send_timeout 300s;
fastcgi_read_timeout 300s;
include fastcgi_params;
}
}
@tylers-username
Copy link
Author

@rhuffstedtler - I have updated the gist.

  • The .lando.yml has been made compatible with the latest version of Lando.
  • The lando.nginx.conf has been updated so that it is compatible with the latest version of Lando.
  • I have added the lando magento:download command
    • This command will download the latest version of Magento to your current working directory and create the lando.nginx.conf file (you will still have to paste the content from this Gist for now into the file)
    • Once this command completes, it outputs the next recommended steps.
  • The readme has been updated.

I've tested this a couple of times today and it seems fairly stable. Within 3 or 4 steps you should have a functional empty Luma site up and running. However, you can pass the --use-sample-data to the lando magento:setup:quick command to include the sample data while also configuring the DB to work with Lando.

lando magento:setup:quick is actually an alias for bin/magento setup:install (with a few default arguments for Lando) so you can actually pass any bin/magento setup:install argument or option to this command.

I'm going to go out on a limb and say this should now be one of the easiest ways to get up and running on Magento.

I recommend running lando destroy -y before following the steps in the readme.

Lastly, this Lando config will work with any existing code base that you may already have. You'll just want to consider removing the setup/download commands and renaming the Lando app and proxy URL.

@tylers-username
Copy link
Author

@rhuffstedtler - Also, keep in mind that the lando.nginx.conf references Magento's distributed nginx.conf.sample. If you're applying this to an existing project then you will want to consider that.

@tylers-username
Copy link
Author

For a more quick and easy setup process, this Gist has been converted to a repository: improper/lando-magento2-template

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment