Introduction
Magento is a powerful open-source eCommerce platform that provides a flexible shopping cart system and a wide range of features for online businesses. In this guide, we will walk you through the installation of Magento on Ubuntu 22.04, configured with Nginx as the web server and Elasticsearch for search capabilities. This setup is particularly beneficial when using a Windows VPS UK to ensure reliable performance for your online store.
Prerequisites
- An Ubuntu 22.04 server with root access
- A domain name pointing to your server (optional but recommended)
- Basic knowledge of Linux commands
Step 1: Update Your System
Start by updating your system packages:
sudo apt update && sudo apt upgrade -y
Step 2: Install Required Packages
Install Nginx, PHP, and other necessary dependencies:
sudo apt install -y nginx php-fpm php-mysql php-xml php-mbstring php-curl php-zip php-gd php-intl php-bcmath php-json
Step 3: Install Elasticsearch
Magento requires Elasticsearch for search functionality. Install Elasticsearch by following these commands:
curl -fsSL https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor -o /usr/share/keyrings/elastic.gpg
echo "deb [signed-by=/usr/share/keyrings/elastic.gpg] https://artifacts.elastic.co/packages/7.x/apt/ stable main" | sudo tee /etc/apt/sources.list.d/elastic-7.x.list
sudo apt update
sudo apt install elasticsearch -y
Start and enable the Elasticsearch service:
sudo systemctl start elasticsearch
sudo systemctl enable elasticsearch
Step 4: Download Magento
Navigate to the web root directory and download the latest version of Magento:
cd /var/www
sudo curl -O https://magento.mirrors.pair.com/archives/magento-2.4.5.tar.gz
sudo tar -xvzf magento-2.4.5.tar.gz
sudo mv magento2-* magento
Step 5: Set Permissions
Set the correct permissions for the Magento directory:
sudo chown -R www-data:www-data /var/www/magento
sudo find /var/www/magento -type d -exec chmod 770 {} \;
sudo find /var/www/magento -type f -exec chmod 660 {} \;
Step 6: Configure Nginx
Create a new Nginx configuration file for Magento:
sudo nano /etc/nginx/sites-available/magento
Add the following configuration, replacing your_domain.com
with your actual domain:
server {
listen 80;
server_name your_domain.com;
set $MAGE_ROOT /var/www/magento;
include /var/www/magento/nginx.conf;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ ^/index\.php {
fastcgi_pass unix:/run/php/php8.1-fpm.sock; # Adjust PHP version if necessary
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi.conf;
}
location ~* \.(jpg|jpeg|gif|png|css|js|ico|svg)$ {
expires 30d;
access_log off;
}
}
Enable the new Nginx configuration:
sudo ln -s /etc/nginx/sites-available/magento /etc/nginx/sites-enabled/
Test the Nginx configuration:
sudo nginx -t
If there are no errors, restart Nginx:
sudo systemctl restart nginx
Step 7: Install Magento
Navigate to your domain in a web browser to start the Magento installation wizard. Follow the on-screen instructions to complete the setup.
Step 8: Conclusion
Congratulations! You have successfully installed Magento eCommerce on Ubuntu 22.04 with Nginx and Elasticsearch. This setup provides a powerful platform for your online store. For those considering reliable hosting options, look into a Windows VPS. Explore various options, including VPS UK Windows, Windows Virtual Private Server Hosting, and Windows VPS Hosting UK for optimal performance.