{"id":786,"date":"2025-01-14T21:35:51","date_gmt":"2025-01-14T21:35:51","guid":{"rendered":"https:\/\/blog.eu.enginyr.ing\/?p=786"},"modified":"2025-01-14T21:35:52","modified_gmt":"2025-01-14T21:35:52","slug":"how-to-install-and-optimize-magento-for-speed-on-your-linux-vps-debian-ubuntu","status":"publish","type":"post","link":"https:\/\/www.serverspan.com\/en\/blog\/how-to-install-and-optimize-magento-for-speed-on-your-linux-vps-debian-ubuntu\/","title":{"rendered":"How to Install and Optimize Magento for Speed on Your Linux VPS (Debian\/Ubuntu)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Setting up Magento on a VPS can seem daunting, especially when you&#8217;re aiming for optimal performance. As an e-commerce platform, Magento&#8217;s performance directly impacts your store&#8217;s success &#8211; from customer experience to search engine rankings. At ENGINYRING, we&#8217;ve helped numerous businesses optimize their Magento installations, and we&#8217;ll guide you through this process step by step, explaining not just what to do, but why each step matters for your store&#8217;s performance.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Understanding Your VPS Environment<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before we begin installing Magento, it&#8217;s crucial to understand what makes a VPS environment suitable for e-commerce. Think of your VPS as the foundation of a house &#8211; the stronger it is, the more stable your store will be. The key components we&#8217;ll work with are your server&#8217;s operating system (Linux), web server (Apache), database (MySQL), and programming language (PHP). Each of these components needs specific configuration to work optimally with Magento.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Preparing Your Server<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The first step is updating your system. This ensures you have the latest security patches and performance improvements. Open your terminal and execute these commands:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update\nsudo apt upgrade -y<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Next, we&#8217;ll install the required system packages. These are like the basic tools you need before starting any construction project:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install -y software-properties-common curl wget git<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Installing the LAMP Stack<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Magento requires a LAMP stack (Linux, Apache, MySQL, PHP). We&#8217;ll install each component with performance in mind. First, let&#8217;s set up Apache, your web server:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install -y apache2<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now, we&#8217;ll install PHP. Magento requires specific PHP versions and extensions. We&#8217;ll use PHP 8.1, which offers excellent performance improvements:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo add-apt-repository ppa:ondrej\/php\nsudo apt update\nsudo apt install -y php8.1 php8.1-cli php8.1-common php8.1-curl \\\n    php8.1-gd php8.1-intl php8.1-mbstring php8.1-mysql \\\n    php8.1-soap php8.1-xml php8.1-zip php8.1-bcmath<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Each of these PHP extensions serves a specific purpose. For example, php8.1-intl handles internationalization, crucial if you&#8217;re planning to serve customers in different countries. The php8.1-opcache extension, which we&#8217;ll configure later, dramatically improves PHP performance by storing precompiled script bytecode in memory.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Configuring MySQL for Performance<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">MySQL configuration significantly impacts your store&#8217;s performance. Let&#8217;s install MySQL and optimize it specifically for Magento:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install -y mysql-server mysql-client<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">After installation, we&#8217;ll create a configuration file optimized for Magento. Create a new file at \/etc\/mysql\/conf.d\/magento.cnf:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;mysqld]\ninnodb_buffer_pool_size = 1G\ninnodb_buffer_pool_instances = 4\ninnodb_file_per_table = 1\ninnodb_flush_method = O_DIRECT\ninnodb_log_file_size = 256M\ninnodb_read_io_threads = 4\ninnodb_write_io_threads = 4\ninnodb_stats_on_metadata = 0\nmax_connections = 1000<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s understand what these settings do. The innodb_buffer_pool_size is particularly important &#8211; it&#8217;s like MySQL&#8217;s RAM. Setting it to 1GB (adjustable based on your VPS memory) ensures frequently accessed data stays in memory, reducing disk I\/O. The innodb_file_per_table setting improves table management and optimization capabilities.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">PHP Optimization for Magento<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">PHP&#8217;s default settings aren&#8217;t optimized for Magento. We&#8217;ll create a custom configuration that significantly improves performance. Create a new file at \/etc\/php\/8.1\/apache2\/conf.d\/magento.ini:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>memory_limit = 2G\nmax_execution_time = 1800\nzlib.output_compression = On\nopcache.enable = 1\nopcache.enable_cli = 1\nopcache.memory_consumption = 512\nopcache.max_accelerated_files = 60000\nopcache.validate_timestamps = 0\nopcache.save_comments = 1\nmax_input_vars = 10000<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">These settings are crucial for Magento&#8217;s performance. The memory_limit of 2GB ensures PHP has enough memory to handle large product catalogs and complex operations. The opcache settings create a bytecode cache that dramatically speeds up PHP execution by storing compiled PHP code in memory.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">[Previous sections remain the same through PHP Optimization, then continuing with:]<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Installing Magento<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Now that we have our environment properly configured, we can proceed with installing Magento itself. We&#8217;ll use Composer, PHP&#8217;s package manager, which ensures we get all the correct dependencies. Think of Composer as a skilled assistant who knows exactly which tools and materials we need for our project.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">First, let&#8217;s install Composer:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>curl -sS https:\/\/getcomposer.org\/installer | sudo php -- --install-dir=\/usr\/local\/bin --filename=composer<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Next, we&#8217;ll create the directory where Magento will live and set the correct permissions. This is like preparing the specific room in our house where our store will operate:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mkdir -p \/var\/www\/magento\nsudo chown -R $USER:$USER \/var\/www\/magento\ncd \/var\/www\/magento<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now we can download and install Magento. This step might take several minutes, as Composer needs to download and arrange all the necessary components:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>composer create-project --repository-url=https:\/\/repo.magento.com\/ magento\/project-community-edition .<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Implementing Redis for Advanced Caching<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Redis acts like a high-speed memory cache for your store, significantly improving performance by storing frequently accessed data in memory rather than reading from disk every time. Let&#8217;s implement Redis for both session storage and page caching.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">First, install Redis:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install -y redis-server<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We&#8217;ll optimize Redis&#8217;s configuration for Magento. Create a new configuration file at \/etc\/redis\/redis.conf:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>maxmemory 2gb\nmaxmemory-policy allkeys-lru\nappendonly yes\nappendfsync everysec<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">These settings deserve explanation. The maxmemory setting reserves 2GB for Redis (adjust based on your VPS resources). The maxmemory-policy determines how Redis handles memory when it&#8217;s full &#8211; allkeys-lru means it will remove the least recently used items first, which is ideal for a cache.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now, configure Magento to use Redis. This involves modifying Magento&#8217;s environment configuration:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>bin\/magento setup:config:set --cache-backend=redis \\\n    --cache-backend-redis-server=127.0.0.1 \\\n    --cache-backend-redis-port=6379 \\\n    --cache-backend-redis-db=0\n\nbin\/magento setup:config:set --page-cache=redis \\\n    --page-cache-redis-server=127.0.0.1 \\\n    --page-cache-redis-port=6379 \\\n    --page-cache-redis-db=1\n\nbin\/magento setup:config:set --session-save=redis \\\n    --session-save-redis-host=127.0.0.1 \\\n    --session-save-redis-port=6379 \\\n    --session-save-redis-db=2<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Apache Optimization for Maximum Performance<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Apache&#8217;s default configuration isn&#8217;t optimized for Magento&#8217;s needs. We&#8217;ll create a custom virtual host configuration that implements several performance enhancements. This is like fine-tuning your store&#8217;s entrance to handle customer traffic more efficiently.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create a new Apache configuration file at \/etc\/apache2\/sites-available\/magento.conf:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;VirtualHost *:80&gt;\n    ServerAdmin webmaster@your-domain.com\n    DocumentRoot \/var\/www\/magento\/pub\n    ServerName your-domain.com\n\n    &lt;Directory \/var\/www\/magento\/pub&gt;\n        Options Indexes FollowSymLinks MultiViews\n        AllowOverride All\n        Order allow,deny\n        allow from all\n        &lt;IfModule mod_expires.c&gt;\n            ExpiresActive On\n            ExpiresByType image\/jpg \"access plus 1 year\"\n            ExpiresByType image\/jpeg \"access plus 1 year\"\n            ExpiresByType image\/gif \"access plus 1 year\"\n            ExpiresByType image\/png \"access plus 1 year\"\n            ExpiresByType text\/css \"access plus 1 month\"\n            ExpiresByType application\/javascript \"access plus 1 month\"\n        &lt;\/IfModule&gt;\n\n        &lt;IfModule mod_deflate.c&gt;\n            AddOutputFilterByType DEFLATE text\/html text\/plain text\/xml text\/css text\/javascript application\/javascript\n        &lt;\/IfModule&gt;\n    &lt;\/Directory&gt;\n\n    ErrorLog ${APACHE_LOG_DIR}\/magento_error.log\n    CustomLog ${APACHE_LOG_DIR}\/magento_access.log combined\n&lt;\/VirtualHost&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This configuration includes several important optimizations. The expires headers tell browsers to cache static content like images and CSS files, reducing server load. The DEFLATE compression reduces the size of transmitted data, making your store faster for customers with slower connections.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Final Performance Tuning<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">With all components in place, we can now implement Magento&#8217;s built-in optimization features. These are like the final adjustments that bring all our previous optimizations together:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Enable production mode\nbin\/magento deploy:mode:set production\n\n# Generate optimized class configurations\nbin\/magento setup:di:compile\n\n# Deploy static content efficiently\nbin\/magento setup:static-content:deploy -f\n\n# Enable all caches\nbin\/magento cache:enable<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Each of these commands serves a specific purpose. Production mode disables debugging features and enables code compilation, significantly improving performance. The di:compile command pre-generates code that Magento would otherwise need to generate on the fly, and static content deployment optimizes your store&#8217;s assets.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Monitoring and Maintenance<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Setting up monitoring helps you maintain optimal performance over time. It&#8217;s like having a health monitoring system for your store. We recommend setting up these basic monitoring tools:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install -y htop iotop nethogs<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Regular maintenance tasks should include:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Regularly clean logs\nbin\/magento log:clean\n\n# Reindex data when needed\nbin\/magento indexer:reindex\n\n# Check system status\nbin\/magento system:status<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Professional Support and Implementation<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">At ENGINYRING, we understand that setting up and optimizing Magento can be complex. Our <a href=\"https:\/\/www.enginyring.com\/en\/virtual-servers\">VPS hosting solutions<\/a> are specifically optimized for Magento performance, ensuring your e-commerce store runs at its best.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We provide comprehensive management solutions including:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.enginyring.com\/en\/cpanel-management\">cPanel management<\/a> for easy administration<\/li>\n\n\n\n<li><a href=\"https:\/\/www.enginyring.com\/en\/directadmin-management\">DirectAdmin management<\/a> for efficient server control<\/li>\n\n\n\n<li><a href=\"https:\/\/www.enginyring.com\/en\/proxmox-management\">Proxmox management<\/a> for advanced virtualization needs<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Need expert assistance with your Magento installation? <a href=\"https:\/\/www.enginyring.com\/en\/contact\">Contact us<\/a> today to discuss how we can help optimize your e-commerce platform.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Setting up Magento on a VPS can seem daunting, especially when you&#8217;re aiming for optimal performance. As an e-commerce platform, Magento&#8217;s performance directly impacts your store&#8217;s success &#8211; from customer experience to search engine rankings. At ENGINYRING, we&#8217;ve helped numerous businesses optimize their Magento installations, and we&#8217;ll guide you through this process step by step, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":787,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[4044,4040,352,4035,4031,4034,4037,4032,4033,4039,4045,4042,4041,4043,350,447,4036,3876,4038],"class_list":["post-786","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-apache-configuration","tag-cache-configuration","tag-database-optimization","tag-debian-setup","tag-ecommerce-optimization","tag-linux-server","tag-magento-cache","tag-magento-installation","tag-magento-performance","tag-magento-setup","tag-magento-speed","tag-mysql-optimization","tag-php-optimization","tag-redis-cache","tag-server-configuration","tag-server-performance","tag-ubuntu-configuration","tag-vps-optimization","tag-web-server-setup"],"_links":{"self":[{"href":"https:\/\/www.serverspan.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/786","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.serverspan.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.serverspan.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.serverspan.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.serverspan.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=786"}],"version-history":[{"count":0,"href":"https:\/\/www.serverspan.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/786\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.serverspan.com\/blog\/index.php?rest_route=\/wp\/v2\/media\/787"}],"wp:attachment":[{"href":"https:\/\/www.serverspan.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=786"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.serverspan.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=786"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.serverspan.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=786"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}