{"id":3376,"date":"2024-01-24T07:30:35","date_gmt":"2024-01-24T07:30:35","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/install-magento-2-on-ubuntu\/"},"modified":"2025-12-10T10:50:19","modified_gmt":"2025-12-10T05:20:19","slug":"install-magento-2-on-ubuntu","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/install-magento-2-on-ubuntu\/","title":{"rendered":"How to Install Magento 2 on Ubuntu: Step-by-step [2026]"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Hey, Magento Geeks!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You&#8217;ve already made a great choice to install Magento 2 on Ubuntu.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Ubuntu is a preferred OS for installing Magento 2 for many developers and merchants. It is a feature-rich, reliable, and secure Linux-based system that Adobe recommends for full capacity and compatibility.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this post, find the complete steps to install Magento 2 on Ubuntu.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"steps-to-install-magento2-on-ubuntu\">How to Install Magento 2 on Ubuntu?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before starting the Ubuntu Magento installation process\u2013check the <a href=\"https:\/\/meetanshi.com\/blog\/magento-2-system-requirements\/\">Magento 2 system requirements<\/a>. Double-check the required hardware setup for the Magento version you&#8217;re installing.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Follow these steps to install Magento 2 on Ubuntu:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"step1-install-configure-apache2-php\">Step 1: Install &amp; Configure Apache2 Server &amp; PHP Extensions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Install &amp; Configure Apache2 Server<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Apache is an open-source web server software that you&#8217;ll need to install Magento 2 on Ubuntu.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Run the following commands to install Apache in Ubuntu:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code data-enlighter-language=\"html\" class=\"EnlighterJSRAW\">sudo apt update\nsudo apt install apache2<\/code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To auto-run Apache2 during system startup, use the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl enable apache2.service<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Create a <code>magento2.conf<\/code> file using the following command to declare Magento 2 site configuration for Apache2:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano \/etc\/apache2\/sites-available\/magento2.conf<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now, open the created file. Copy and paste the following configuration into it:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">    ServerAdmin webmaster@localhost\n    DocumentRoot \/var\/www\/html\n    ErrorLog ${APACHE_LOG_DIR}\/error.log\n    CustomLog ${APACHE_LOG_DIR}\/access.log combined\n\n\n    ServerName your-magento-2-store-url.com\n    DocumentRoot \/var\/www\/html\/magento2\/pub<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Remember to replace the server address from &#8220;your-magento-2-store-url.com&#8221; to your actual Magento 2 store URL.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If installing Magento 2 on Ubuntu locally, you can change it to localhost.com.&nbsp;You&#8217;ll also need to update the <code>hosts<\/code> file at \/etc\/hosts with<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>127.0.0.1 your-magento-2-store-url.com<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Run the following command to enable mod rewrite:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo a2ensite magento2.conf\nsudo a2enmod rewrite<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Install PHP 8.2 &amp; Required Extensions<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You&#8217;ll also need to install PHP 8.2 and its extensions required for installing Magento 2 in Ubuntu. You can run the following single command to do that:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install php8.2 libapache2-mod-php8.2 php8.2-common php8.2-gmp php8.2-curl php8.2-soap php8.2-bcmath php8.2-intl php8.2-mbstring php8.2-xmlrpc php8.2-mysql php8.2-gd php8.2-xml php8.2-cli php8.2-zip<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now, open the<code>php.ini<\/code>file and configure it as following:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">file_uploads = On\nallow_url_fopen = On\nshort_open_tag = On\nmemory_limit = 512M\nupload_max_filesize = 128M\nmax_execution_time = 3600<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Save the file and restart the Apache2 server using the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl restart apache2.service<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"step2-install-database-server\">Step 2: Install Database Server<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">MariaDB is a preferred database server for Magento 2 and Adobe Commerce. To install MariaDB server and client in Ubuntu, run the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt-get install mariadb-server mariadb-client<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To auto-start the database server on system startup, run the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl restart mariadb.service\nsudo systemctl enable mariadb.service<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now, run the following command to set up a MariaDB server in Ubuntu:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mysql_secure_installation<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Select the following options when prompted:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Enter current password for root (enter for none): <em>Press Enter<\/em><\/li>\n\n\n\n<li>Set root password? [Y\/n]: <em>Y<\/em><\/li>\n\n\n\n<li>New password:<em> Type your password<\/em><\/li>\n\n\n\n<li>Re-enter new password: <em>Type your password<\/em><\/li>\n\n\n\n<li>Remove anonymous users? [Y\/n]: <em>Y<\/em><\/li>\n\n\n\n<li>Disallow root login remotely? [Y\/n]: <em>Y<\/em><\/li>\n\n\n\n<li>Remove the test database and access it. [Y\/n]: <em>Y<\/em><\/li>\n\n\n\n<li>Reload privilege tables now? [Y\/n]: <em>Y<\/em><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"step3-create-mysql-user\">Step 3: Create MySQL User<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Magento 2 can not be installed to the default <code>root<\/code> user. You&#8217;ll need to create a new database user.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Run the following command to log into MariDB:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mysql -u root -p<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now, run the following command to create a new database:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE DATABASE magento2<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Create a new user called &#8216;Meetanshi&#8217; using the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE USER 'meetanshi'@'localhost' IDENTIFIED BY 'YOUR_PASSWORD';<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Grant <code>meetanshi<\/code> user to magento2 database:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>GRANT ALL ON magento2.* TO 'meetanshi'@'localhost' IDENTIFIED BY 'YOUR_PASSWORD' WITH GRANT OPTION;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Finally, flush the privileges and exit.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">FLUSH PRIVILEGES;\nEXIT;<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"step4-install-composer\">Step 4: Install Composer<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Magento 2 requires Composer for dependency management. You can either <a href=\"https:\/\/getcomposer.org\/download\/\" target=\"_blank\" rel=\"noopener\">download and install Composer<\/a> in Ubuntu manually or run the following command to do that:<\/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\">To check if the Composer has been successfully installed, run the following version check command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>composer -v<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"step5-download-install-magento2\">Step 5: Download &amp; Install Magento 2 in Ubuntu<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Download Latest Magento 2 Package<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Go to one of these resources and download the zip file of the latest Magento 2 version:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/meetanshi.com\/blog\/download-magento\/\">Magento 2 Download<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/github.com\/magento\/magento2\/releases\" target=\"_blank\" rel=\"noopener\">Magento 2 Releases on GitHub<\/a><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Now, extract the zip file to the <code>\/var\/www\/html\/<\/code> folder.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Run the following command to set the permissions:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo chown -R www-data:www-data \/var\/www\/html\/magento2\/\nsudo chmod -R 755 \/var\/www\/html\/magento2\/<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Install Magento 2 on Ubuntu<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Open the <code>\/var\/www\/html\/magento2<\/code> folder and run the following command:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">php bin\/magento setup:install &#8211;base-url=https:\/\/magento2.com\/ &#8211;db-host=127.0.0.1 &#8211;db-name=magento2 &#8211;db-user=meetanshi &#8211;db-password=password &#8211;admin-firstname=admin &#8211;admin-lastname=admin &#8211;admin-email=admin@admin.com &#8211;admin-user=admin &#8211;admin-password=admin123 &#8211;languag e=en_US &#8211;currency=USD &#8211;timezone=America\/Chicago &#8211;use-rewrites=1 \u2013backend-frontname=\u201dadmin\u201d \u2013search-engine=elasticsearch7<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The above command installs the Magento 2 on Ubuntu using with preset configuration. You can adjust the values of these parameters to install Magento 2 as per your needs. For e.g., you can modify the login username and password.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Once the command has executed successfully, you can access the Magento 2 in the local server.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Frontend URL:<\/strong> https:\/\/magento2.com\/<\/li>\n\n\n\n<li><strong>Admin Login URL:&nbsp;<\/strong>https:\/\/magento2.com\/admin<\/li>\n\n\n\n<li><strong>Admin Username:&nbsp;<\/strong>admin<\/li>\n\n\n\n<li><strong>Admin Password:&nbsp;<\/strong>admin123<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">That&#8217;s it! Congratulate yourself on successfully setting up Magento 2 store on Ubuntu.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you&#8217;ve any doubts regarding how to install Magento 2 on Ubuntu or if you face any problems, feel free to reach out through comments. I will be happy to help you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Magento Geeks! You&#8217;ve already made a great choice to install Magento 2 on Ubuntu. Ubuntu is a preferred OS for installing Magento 2 for&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-3376","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/3376","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=3376"}],"version-history":[{"count":3,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/3376\/revisions"}],"predecessor-version":[{"id":24819,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/3376\/revisions\/24819"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=3376"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=3376"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=3376"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}