### setup:upgrade examples Source: https://docs.magento-opensource.com/developer/guide-reference-cli-command-reference.html Examples of setup:upgrade with various options: standard, dry-run, safe-mode, and keep-generated. ```bash # Standard upgrade bin/magento setup:upgrade # Dry run to preview changes bin/magento setup:upgrade --dry-run=1 # Safe mode with backup bin/magento setup:upgrade --safe-mode=1 # Fast upgrade keeping generated code (not recommended) bin/magento setup:upgrade --keep-generated ``` -------------------------------- ### setup:di:compile examples Source: https://docs.magento-opensource.com/developer/guide-reference-cli-command-reference.html Examples of setup:di:compile, including standard compilation and monitoring memory usage. ```bash # Standard compilation bin/magento setup:di:compile # Compilation for multi-tenant setup bin/magento setup:di:compile --ansi # Parallel terminal: Monitor memory usage watch -n 1 'ps aux | grep php | grep -v grep' ``` -------------------------------- ### cron:install examples Source: https://docs.magento-opensource.com/developer/guide-reference-cli-command-reference.html Examples of installing cron jobs: standard, force reinstall, and with custom path. ```bash # Standard install bin/magento cron:install # Force reinstall bin/magento cron:install --force # Install with custom path bin/magento cron:install -d /var/www/html ``` -------------------------------- ### Basic deployment examples for setup:static-content:deploy Source: https://docs.magento-opensource.com/developer/guide-reference-cli-command-reference.html Various command examples for deploying static content, including specific locales, force deploy, area, theme, strategy, and skipping JavaScript. ```bash # Deploy all themes and locales bin/magento setup:static-content:deploy ``` ```bash # Deploy specific locales bin/magento setup:static-content:deploy en_US de_DE fr_FR ``` ```bash # Force deploy with parallel jobs bin/magento setup:static-content:deploy -f -j 8 en_US ``` ```bash # Deploy frontend only bin/magento setup:static-content:deploy --area=frontend ``` ```bash # Deploy specific theme bin/magento setup:static-content:deploy --theme=Magento/luma ``` ```bash # Quick deployment for development bin/magento setup:static-content:deploy --strategy=quick -f ``` ```bash # Production deployment with all optimizations bin/magento setup:static-content:deploy -f --strategy=standard -j 8 en_US ``` ```bash # Skip JavaScript bundling (faster) bin/magento setup:static-content:deploy --no-javascript ``` -------------------------------- ### Expected output from setup:static-content:deploy Source: https://docs.magento-opensource.com/developer/guide-reference-cli-command-reference.html Example output showing successful deployment with file counts and execution time. ```text Requested languages: en_US === frontend -> Magento/luma -> en_US === Successful: 2389 files; errors: 0 --- === adminhtml -> Magento/backend -> en_US === Successful: 3214 files; errors: 0 --- Execution time: 342.123456789 ``` -------------------------------- ### Install Magento with setup:install Source: https://docs.magento-opensource.com/developer/guide-tutorial-docker-development-environment.html Runs the Magento installer with database, admin, Redis, Elasticsearch, RabbitMQ, and other configuration options. This command sets up the Magento 2.4.7 instance with the specified parameters. ```bash bin/magento setup:install \ --base-url=http://magento2.local/ \ --db-host=mysql \ --db-name=magento2 \ --db-user=magento2 \ --db-password=magento2 \ --admin-firstname=Admin \ --admin-lastname=User \ --admin-email=admin@example.com \ --admin-user=admin \ --admin-password=Admin123! \ --language=en_US \ --currency=USD \ --timezone=America/Chicago \ --use-rewrites=1 \ --search-engine=elasticsearch8 \ --elasticsearch-host=elasticsearch \ --elasticsearch-port=9200 \ --elasticsearch-index-prefix=magento2 \ --session-save=redis \ --session-save-redis-host=redis \ --session-save-redis-port=6379 \ --session-save-redis-db=2 \ --cache-backend=redis \ --cache-backend-redis-server=redis \ --cache-backend-redis-port=6379 \ --cache-backend-redis-db=0 \ --page-cache=redis \ --page-cache-redis-server=redis \ --page-cache-redis-port=6379 \ --page-cache-redis-db=1 \ --amqp-host=rabbitmq \ --amqp-port=5672 \ --amqp-user=magento2 \ --amqp-password=magento2 \ --consumers-wait-for-messages=0 ``` -------------------------------- ### setup:upgrade syntax Source: https://docs.magento-opensource.com/developer/guide-reference-cli-command-reference.html Shows the basic syntax for the setup:upgrade command. ```bash bin/magento setup:upgrade [options] ``` -------------------------------- ### config:show examples Source: https://docs.magento-opensource.com/developer/guide-reference-cli-command-reference.html Examples of showing all configuration, specific paths, and filtering with grep. ```bash # Show all configuration bin/magento config:show # Show specific path bin/magento config:show web/secure/base_url # Show all web configuration bin/magento config:show | grep "web/" # Show all paths containing "base_url" bin/magento config:show | grep base_url # Check search engine config bin/magento config:show catalog/search/engine ``` -------------------------------- ### Install OpenSearch 2.x and configure service Source: https://docs.magento-opensource.com/developer/guide-reference-upgrade-guide-247-248.html Commands to install OpenSearch 2.x via apt, start the service, and enable it on boot. This is the first step in migrating from Elasticsearch. ```bash # 1. Install OpenSearch 2.x curl -o- https://artifacts.opensearch.org/publickeys/opensearch.pgp | sudo gpg --dearmor --batch --yes -o /usr/share/keyrings/opensearch-keyring echo "deb [signed-by=/usr/share/keyrings/opensearch-keyring] https://artifacts.opensearch.org/releases/bundle/opensearch/2.x/apt stable main" | sudo tee /etc/apt/sources.list.d/opensearch-2.list sudo apt-get update sudo apt-get install opensearch # 2. Configure OpenSearch sudo systemctl start opensearch sudo systemctl enable opensearch ``` -------------------------------- ### indexer:set-mode examples Source: https://docs.magento-opensource.com/developer/guide-reference-cli-command-reference.html Examples of setting indexer modes: all to schedule, specific to realtime, and a production setup with cron. ```bash # Set all indexers to schedule mode (recommended for production) bin/magento indexer:set-mode schedule # Set specific indexers to realtime bin/magento indexer:set-mode realtime catalog_product_price # Production setup: Schedule mode + cron bin/magento indexer:set-mode schedule bin/magento cron:install ``` -------------------------------- ### Install Magento 2 Sample Data Commands Source: https://docs.magento-opensource.com/developer/guide-tutorial-docker-development-environment.html Run these commands inside the PHP container to deploy sample data and update the Magento setup. Sample data installation takes 10-15 minutes. ```bash bin/magento sampledata:deploy bin/magento setup:upgrade bin/magento indexer:reindex bin/magento cache:flush ``` -------------------------------- ### app:config:dump examples Source: https://docs.magento-opensource.com/developer/guide-reference-cli-command-reference.html Examples of dumping all configuration, only system config, or scopes. ```bash # Dump all configuration bin/magento app:config:dump # Dump only system config bin/magento app:config:dump system # Dump scopes (for multi-store setup) bin/magento app:config:dump scopes ``` -------------------------------- ### cache:enable / cache:disable examples Source: https://docs.magento-opensource.com/developer/guide-reference-cli-command-reference.html Examples of enabling all caches, enabling specific caches, disabling full page cache for development, and a common dev setup. ```bash # Enable all caches bin/magento cache:enable # Enable specific caches bin/magento cache:enable config layout # Disable full page cache for development bin/magento cache:disable full_page block_html # Common dev setup: disable all except config/layout bin/magento cache:disable bin/magento cache:enable config layout ``` -------------------------------- ### Legacy InstallData.php install method Source: https://docs.magento-opensource.com/developer/guide-tutorial-declarative-schema-data-patches.html Legacy data installation script that inserts initial status rows using InstallData.php. This is the 'before' example that will be replaced by a data patch. ```php public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) { $setup->startSetup(); $data = [ ['status_id' => 1, 'label' => 'Pending'], ['status_id' => 2, 'label' => 'Approved'], ]; $setup->getConnection()->insertMultiple( $setup->getTable('vendor_review_status'), $data ); $setup->endSetup(); } ``` -------------------------------- ### config:set examples Source: https://docs.magento-opensource.com/developer/guide-reference-cli-command-reference.html Examples of setting global, scoped, locked, and common configuration values. ```bash # Set global configuration bin/magento config:set web/unsecure/base_url "https://example.com/" # Set for specific website bin/magento config:set --scope=websites --scope-code=base web/secure/base_url "https://example.com/" # Set for specific store view bin/magento config:set --scope=stores --scope-code=default general/locale/timezone "America/New_York" # Lock configuration value bin/magento config:set --lock dev/debug/debug_logging 1 # Common settings bin/magento config:set web/secure/use_in_frontend 1 bin/magento config:set web/secure/use_in_adminhtml 1 bin/magento config:set dev/static/sign 0 bin/magento config:set admin/security/session_lifetime 86400 # Disable modules via config bin/magento config:set dev/debug/template_hints_storefront 1 bin/magento config:set dev/debug/template_hints_admin 1 ``` -------------------------------- ### setup:di:compile syntax Source: https://docs.magento-opensource.com/developer/guide-reference-cli-command-reference.html Shows the basic syntax for the setup:di:compile command. ```bash bin/magento setup:di:compile ``` -------------------------------- ### customer:hash:upgrade example Source: https://docs.magento-opensource.com/developer/guide-reference-cli-command-reference.html Example of upgrading all customer password hashes. ```bash # Upgrade all customer password hashes bin/magento customer:hash:upgrade ``` -------------------------------- ### admin:user:create example Source: https://docs.magento-opensource.com/developer/guide-reference-cli-command-reference.html Example command to create an admin user with specified credentials. ```bash bin/magento admin:user:create \ --admin-user="john.doe" \ --admin-password="SecurePass123!" \ --admin-email="john.doe@example.com" \ --admin-firstname="John" \ --admin-lastname="Doe" ``` -------------------------------- ### cron:install syntax Source: https://docs.magento-opensource.com/developer/guide-reference-cli-command-reference.html Shows the basic syntax for the cron:install command, which installs cron jobs in the system crontab. ```bash bin/magento cron:install [options] ``` -------------------------------- ### Syntax for setup:static-content:deploy Source: https://docs.magento-opensource.com/developer/guide-reference-cli-command-reference.html Shows the command syntax with options and language arguments. ```bash bin/magento setup:static-content:deploy [options] [languages] ``` -------------------------------- ### ProductRepositoryInterface PHP Example Source: https://docs.magento-opensource.com/developer/guide-explanation-service-contracts-repositories.html Example of the Magento\Catalog\Api\ProductRepositoryInterface with methods save, get, getById, getList, delete, and deleteById. Note that get($sku) and getById($productId) handle composite identities, and parameters like $editMode, $storeId, and $forceReload control caching and scope. ```php namespace Magento\Catalog\Api; /** * @api */ interface ProductRepositoryInterface { /** * @param \Magento\Catalog\Api\Data\ProductInterface $product * @param bool $saveOptions * @return \Magento\Catalog\Api\Data\ProductInterface * @throws \Magento\Framework\Exception\InputException * @throws \Magento\Framework\Exception\StateException * @throws \Magento\Framework\Exception\CouldNotSaveException */ public function save( \Magento\Catalog\Api\Data\ProductInterface $product, $saveOptions = false ); /** * @param string $sku * @param bool $editMode * @param int|null $storeId * @param bool $forceReload * @return \Magento\Catalog\Api\Data\ProductInterface * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function get($sku, $editMode = false, $storeId = null, $forceReload = false); /** * @param int $productId * @param bool $editMode * @param int|null $storeId * @param bool $forceReload * @return \Magento\Catalog\Api\Data\ProductInterface * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function getById($productId, $editMode = false, $storeId = null, $forceReload = false); /** * @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria * @return \Magento\Catalog\Api\Data\ProductSearchResultsInterface */ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria); /** * @param \Magento\Catalog\Api\Data\ProductInterface $product * @return bool * @throws \Magento\Framework\Exception\StateException */ public function delete(\Magento\Catalog\Api\Data\ProductInterface $product); /** * @param string $sku * @return bool * @throws \Magento\Framework\Exception\NoSuchEntityException * @throws \Magento\Framework\Exception\StateException */ public function deleteById($sku); } ``` -------------------------------- ### crontab setup for Magento cron Source: https://docs.magento-opensource.com/developer/guide-reference-cli-command-reference.html Commands to install and verify the Magento cron crontab entry, including expected output and a note that setup:cron:run does not exist. ```bash # Install Magento cron bin/magento cron:install # Verify crontab entry crontab -l # Expected output: # * * * * * /usr/bin/php /var/www/html/bin/magento cron:run 2>&1 | grep -v "Ran jobs by schedule" >> /var/www/html/var/log/magento.cron.log # * * * * * /usr/bin/php /var/www/html/update/cron.php >> /var/www/html/var/log/update.cron.log # Note: setup:cron:run does not exist. The correct command is cron:run (shown above). ``` -------------------------------- ### module:enable examples Source: https://docs.magento-opensource.com/developer/guide-reference-cli-command-reference.html Examples of enabling single, multiple, all, and with static content cleanup, plus the full workflow after enabling. ```bash # Enable single module bin/magento module:enable Vendor_Module # Enable multiple modules bin/magento module:enable Vendor_ModuleOne Vendor_ModuleTwo # Enable all disabled modules bin/magento module:enable --all # Enable with static content cleanup bin/magento module:enable Vendor_Module --clear-static-content # Full workflow after enabling module bin/magento module:enable Vendor_Module bin/magento setup:upgrade bin/magento setup:di:compile bin/magento cache:flush ``` -------------------------------- ### Upgrade Guide from 0.9.x to 1.0.0 Source: https://docs.magento-opensource.com/developer/guide-tutorial-declarative-schema-data-patches.html Markdown upgrade guide detailing breaking changes, including the removal of the old_field column, and migration steps with backup and setup commands. ```markdown ## Upgrading from 0.9.x to 1.0.0 **Breaking Changes:** - Removed `old_field` column from `vendor_customer` table. Applications must use `new_field`. **Migration Steps:** 1. Backup database: `mysqldump magento2 > backup.sql` 2. Run: `bin/magento setup:upgrade` 3. Verify data integrity in `vendor_customer` table 4. Update custom code to use `new_field` ``` -------------------------------- ### Module README Database Schema Documentation Source: https://docs.magento-opensource.com/developer/guide-tutorial-declarative-schema-data-patches.html Markdown documentation for the module README describing the database tables added by the module and installation steps using bin/magento setup:upgrade and setup:db-declaration:generate-whitelist. ```markdown ## Database Schema This module adds the following tables: - `vendor_product_review`: Product reviews - `vendor_review_status`: Review status types - `vendor_review_tag`: Many-to-many review-tag relation To install schema: 1. `bin/magento setup:upgrade` 2. `bin/magento setup:db-declaration:generate-whitelist --module-name=Vendor_Module` ``` -------------------------------- ### deploy:mode:show example output Source: https://docs.magento-opensource.com/developer/guide-reference-cli-command-reference.html Example output of deploy:mode:show, showing the current application mode. ```bash Current application mode: production ``` -------------------------------- ### Common issues and solutions for setup:static-content:deploy Source: https://docs.magento-opensource.com/developer/guide-reference-cli-command-reference.html Commands to resolve common issues like out of memory, slow deployment, and missing files. ```bash # Issue: Out of memory during deployment # Solution: Increase PHP memory limit php -d memory_limit=4G bin/magento setup:static-content:deploy ``` ```bash # Issue: Slow deployment # Solution: Use more jobs and quick strategy bin/magento setup:static-content:deploy -f --strategy=quick -j 8 ``` ```bash # Issue: Missing files after deployment # Solution: Clear pub/static and var/view_preprocessed first rm -rf pub/static/* var/view_preprocessed/* bin/magento setup:static-content:deploy -f ``` -------------------------------- ### deploy:mode:set examples Source: https://docs.magento-opensource.com/developer/guide-reference-cli-command-reference.html Examples of switching deployment modes: developer, production, production with skip-compilation, and a full production deployment sequence. ```bash # Switch to developer mode bin/magento deploy:mode:set developer # Switch to production mode bin/magento deploy:mode:set production # Switch to production, skip compilation bin/magento deploy:mode:set production --skip-compilation # Full production deployment bin/magento deploy:mode:set production bin/magento setup:di:compile bin/magento setup:static-content:deploy -f bin/magento cache:flush ``` -------------------------------- ### Module Installation Workflow Source: https://docs.magento-opensource.com/developer/guide-reference-cli-command-reference.html Commands to install and enable a Magento module: require via Composer, enable module, run setup upgrade, compile DI, deploy static content if needed, clear cache, and verify module status. ```bash # 1. Install module via Composer composer require vendor/module-name # 2. Enable module bin/magento module:enable Vendor_ModuleName # 3. Run setup upgrade bin/magento setup:upgrade # 4. Compile DI bin/magento setup:di:compile # 5. Deploy static content (if module has frontend assets) bin/magento setup:static-content:deploy -f # 6. Clear cache bin/magento cache:flush # 7. Verify module is enabled bin/magento module:status | grep Vendor_ModuleName ``` -------------------------------- ### Verify Magento Customer Module Installation Source: https://docs.magento-opensource.com/developer/module-customer-overview.html Commands to check if the Magento_Customer module is enabled, then run setup:upgrade and cache:flush. ```bash bin/magento module:status Magento_Customer # Should show: "Module is enabled" bin/magento setup:upgrade bin/magento cache:flush ``` -------------------------------- ### setup:upgrade expected output Source: https://docs.magento-opensource.com/developer/guide-reference-cli-command-reference.html Expected output from running setup:upgrade, showing cache clearing, file system cleanup, and module updates. ```text Cache cleared successfully File system cleanup: /var/www/html/var/cache /var/www/html/var/page_cache /var/www/html/generated/code ... Updating modules: Schema creation/updates: Module 'Magento_Store': Module 'Magento_AdvancedPricingImportExport': ... Data install/update: Module 'Magento_Store': Module 'Magento_User': ... ``` -------------------------------- ### Blue-green deployment setup (Nginx config) Source: https://docs.magento-opensource.com/developer/guide-reference-upgrade-guide-247-248.html Shows the Nginx upstream configuration for blue-green deployment, with two parallel installations (blue and green) and commented lines for switching. ```nginx upstream magento { server unix:/var/run/php/magento-blue.sock; # Current # server unix:/var/run/php/magento-green.sock; # Swap to this after upgrade } ``` -------------------------------- ### config:show expected output Source: https://docs.magento-opensource.com/developer/guide-reference-cli-command-reference.html Example output from config:show showing configuration paths and values. ```bash web/unsecure/base_url - https://example.com/ web/secure/base_url - https://example.com/ ``` -------------------------------- ### Use Repository Caching for Quote Loading Source: https://docs.magento-opensource.com/developer/module-quote-execution-flows.html Demonstrates the performance impact of loading the same quote multiple times (BAD) versus reusing a single loaded instance (GOOD). The BAD example calls get() twice, causing a database reload, while the GOOD example loads once and reuses the instance for subsequent operations. ```php // BAD: Load quote multiple times $quote1 = $this->quoteRepository->get($quoteId); $quote1->addProduct($product); $quote2 = $this->quoteRepository->get($quoteId); // Reload from DB $quote2->collectTotals(); // GOOD: Load once, reuse $quote = $this->quoteRepository->get($quoteId); $quote->addProduct($product); $quote->collectTotals(); $this->quoteRepository->save($quote); ``` -------------------------------- ### Configure Magento to use Redis for sessions Source: https://docs.magento-opensource.com/developer/module-customer-performance.html Install the Redis PHP extension and set Magento's session storage to Redis with the provided bin/magento setup:config:set command. This addresses slow session access by moving from database to Redis storage. ```bash # Install Redis PHP extension pecl install redis # Configure Magento to use Redis for sessions bin/magento setup:config:set \ --session-save=redis \ --session-save-redis-host=127.0.0.1 \ --session-save-redis-port=6379 \ --session-save-redis-db=2 \ --session-save-redis-max-concurrency=20 \ --session-save-redis-compression-threshold=2048 ```