Question

How I install Magento on LEMP?

  • Posted on December 12, 2012
  • rpontesAsked by rpontes

I want know, how I install magento on my Ubuntu with Nginx.

Thanks.


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

KFSys
Site Moderator
Site Moderator badge
April 25, 2023
Pinned Answer

Hello,

There are two ways to go about this now,

MarketPlace

You can either use a MarketPlace Droplet : https://marketplace.digitalocean.com/apps/magento-2-open-source

The Droplet comes with everything installed and configured for you to use on the GO as soon as you create and SSH to your Droplet.

Manual Installation

To install Magento on Ubuntu with Nginx, follow these steps:

Update and upgrade your system:

  1. sudo apt update
  2. sudo apt upgrade

Install required packages:

  1. sudo apt install nginx php-fpm php-cli php-common php-curl php-gd php-intl php-mbstring php-mysql php-soap php-xml php-xsl php-zip php-json php-opcache php-bcmath unzip

Install MySQL:

  1. sudo apt install mysql-server

After installing MySQL, run the following command to secure the installation:

  1. sudo mysql_secure_installation

Follow the prompts to set a root password and remove anonymous users, disallow remote root login, and remove the test database.

Create a Magento database and user:

Log in to the MySQL shell:

  1. sudo mysql -u root -p

Create a new database and user for Magento (replace magento_user, magento_password, and magento_database with your desired values):

CREATE DATABASE magento_database;
CREATE USER 'magento_user'@'localhost' IDENTIFIED BY 'magento_password';
GRANT ALL PRIVILEGES ON magento_database.* TO 'magento_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Install Composer:

  1. curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

Download Magento:

Download the latest Magento version from the official website or use the following command to download the latest version at the time of writing:

  1. wget https://github.com/magento/magento2/archive/refs/tags/2.4.3.zip

Unzip the downloaded file:

  1. unzip 2.4.3.zip

Move the Magento files to the desired web directory (e.g., /var/www/magento):

  1. sudo mkdir -p /var/www/magento
  2. sudo mv magento2-2.4.3/* magento2-2.4.3/.htaccess /var/www/magento

Set the correct permissions:

  1. sudo chown -R www-data:www-data /var/www/magento
  2. sudo chmod -R 755 /var/www/magento

Configure Nginx:

Create a new Nginx configuration file for Magento:

  1. sudo nano /etc/nginx/sites-available/magento

Paste the following configuration, replacing yourdomain.com with your domain name and adjusting other values as needed:

upstream fastcgi_backend {
    server  unix:/run/php/php7.4-fpm.sock;
}

server {
    listen 80;
    server_name yourdomain.com www.yourdomain.com;
    set $MAGE_ROOT /var/www/magento;
    include /var/www/magento/nginx.conf.sample;
}

Save and close the file. Create a symbolic link to enable the configuration:

  1. sudo ln -s /etc/nginx/sites-available/magento /etc/nginx/sites-enabled/
systemctl restart nginx

Then you just need to open your Droplet and start the installation process.

Magento Requires more Resources than usuall

You might need a more powerful droplet if you want to use Magento as the smallest one wouldn’t work, they won’t have enough resources.

Alternatively, you can add SWAP to your Droplet https://www.digitalocean.com/community/tutorial_collections/how-to-add-swap-space

After dealing for a while with Magento a Nginx, i find out that the key for rewrite is to include the following in the location block inside the desire virtual host config file. <br> <br>For example inside the file “sudo nano /etc/nginx/sites-available/mysite.com” <br> <br>Include this in the location block: <br> <br>location / { <br> try_files $uri $uri/ /index.php?q=$uri&$args; <br> } <br> <br> <br>Santiago

Advise 1GB minimum for magento. More if you intend to install a control panel or ispconfig etc. Would be cool if magento lamp/lemp was an application/image option

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel