Ora

How do I access Magento files?

Published in Magento File Management 5 mins read

Accessing Magento files involves different methods depending on the type of file you need to work with, ranging from managing website content within the admin panel to directly accessing code and media assets on your server.

Navigating Magento Files: An Overview

Magento's file system is extensive, separating content management from its core code and themes. Understanding these distinctions is key to efficiently accessing the files you need. You'll typically use the Magento Admin Panel for content-related files and SFTP/SSH for deeper access to theme, module, and core application files.

Accessing Content Pages and Media via Magento Admin Panel

For managing the static content and media assets that appear on your storefront, the Magento Admin Panel offers a user-friendly interface.

Managing Website Pages

To access and modify the more important static pages of your website, such as "About Us," "Contact Us," or custom landing pages, navigate to the Content section of your Magento admin panel and click on Pages. From this screen, you can easily edit existing pages, create new ones, and manage their content using the built-in WYSIWYG editor. This allows you to update text, images, and other elements without needing server-level access.

Handling Media Files

For images, videos, and other media used across your store (e.g., product images, banners, category icons), go to Content > Media Gallery. This powerful, built-in file browser allows you to upload, organize, and manage your media assets. You can create folders, move files, and easily integrate them into your pages, products, or blocks. While these files are physically stored on the server in the pub/media directory, the Media Gallery provides a convenient interface for daily management.

Direct Server Access for Theme, Module, and Core Files

To access the underlying code, themes, custom modules, and other critical application files, you'll need direct access to your Magento hosting server. This is typically achieved using SFTP (Secure File Transfer Protocol) or SSH (Secure Shell).

Using SFTP for File Transfer

SFTP is ideal for securely transferring files and folders between your local computer and the Magento server. It's often used for uploading themes, extensions, or making direct edits to theme files.

  • Tools: Popular SFTP clients include FileZilla (for all operating systems) and WinSCP (for Windows).

  • Steps to Connect:

    1. Obtain your SFTP credentials (hostname, username, password, port) from your hosting provider.
    2. Open your SFTP client and enter these credentials to establish a connection.
    3. Once connected, you'll see a directory tree representing your server's file system.
  • Key Magento Directories You'll Access via SFTP:

    • app/code: Contains custom modules and third-party extensions.
    • app/design: Holds your store's themes (e.g., frontend/Vendor/theme_name).
    • pub/static: Stores generated static view files like CSS, JavaScript, and images that are served to the browser.
    • pub/media: Where user-uploaded media (product images, blog images, etc.) are physically stored.
    • var: Contains cache files, logs, session data, and generated files.
    • vendor: Composer-managed dependencies, including the Magento core framework and third-party libraries. Avoid direct edits here.

Utilizing SSH for Command-Line Access

SSH provides a command-line interface for more advanced server operations, offering greater control and efficiency. It's essential for running Magento CLI commands, managing file permissions, and performing complex file operations.

  • Tools:
    • macOS/Linux: Use the built-in Terminal application.
    • Windows: Use clients like PuTTY or Windows Subsystem for Linux (WSL).
  • Connecting: You'll use your SSH username and password (or an SSH key) to connect via the command line.
  • Common SSH Commands for File Management:
    • ls -l: Lists files and directories with detailed information (permissions, owner, size, date).
    • cd [directory]: Changes the current directory.
    • pwd: Prints the current working directory.
    • mkdir [new_directory]: Creates a new directory.
    • rm [filename]: Removes (deletes) a file. Use rm -rf [directory] to remove a directory and its contents (use with extreme caution!).
    • cp [source] [destination]: Copies files or directories.
    • mv [source] [destination]: Moves or renames files or directories.
    • php bin/magento [command]: Runs Magento command-line interface tools, such as php bin/magento cache:clean to clear the cache.

When to Use Which Method

The choice of access method depends entirely on your task.

File Type / Content Access Method Primary Use Case
Static Pages (CMS Pages) Magento Admin Panel (Content > Pages) Editing "About Us," "Contact Us" pages, store policy pages, or custom content
Media Assets (Images/Video) Magento Admin Panel (Content > Media Gallery) Uploading product images, banner images, or any visual content
Theme Files (PHTML, CSS, JS) SFTP / SSH Customizing your store's design, modifying layouts, or adding custom scripts
Module Files (PHP, XML) SFTP / SSH Developing custom features, installing third-party extensions, or debugging
Core Magento Files SFTP / SSH (read-only recommended) Advanced debugging or troubleshooting (direct modification is generally discouraged)
Database Data (Products, Customers) phpMyAdmin / SSH CLI (MySQL client) Direct management of product data, customer information, or order details

Best Practices for File Management

When accessing and modifying Magento files, adhere to these best practices to ensure stability, security, and maintainability:

  • Always Backup: Before making any significant changes, create a complete backup of both your Magento files and database.
  • Understand Permissions: Correct file and directory permissions are crucial for Magento's functionality and security. Typically, directories should be 755 and files 644, but consult your hosting provider or Magento documentation for specific recommendations.
  • Use a Development Environment: Never make direct changes on a live production site. Always develop and test in a local, staging, or development environment first.
  • Version Control: Utilize Git or similar version control systems, especially for code-level changes, to track modifications and facilitate rollbacks.
  • Security: Always use SFTP over plain FTP and ensure your SSH connection is secure. Use strong, unique passwords for all server access credentials.
  • Avoid Core Edits: Do not modify Magento core files directly. Instead, extend functionality through themes, modules, and plugins.