Mets Minor League Blog

Music theory, instruments and musicians

Mets Minor League Blog

Music theory, instruments and musicians

How to Install PrestaShop with Nginx on Ubuntu 24.04

How to Install PrestaShop with Nginx on Ubuntu 24.04

Setting up an e-commerce store with PrestaShop on an Ubuntu 24.04 server using Nginx provides a lightweight, high-performance environment ideal for hosting online shops. This guide walks you through the process of installing and configuring PrestaShop with Nginx, ensuring your store runs efficiently and securely. Before starting, ensure you have a fresh Ubuntu 24.04 server and root or sudo access. You’ll also need a domain name pointing to your server’s IP address, a basic understanding of Linux commands, and a stable internet connection.

What You’ll Need

  • Ubuntu 24.04 server with root or sudo privileges
  • A domain name pointed to your server’s IP
  • Basic knowledge of Linux command line
  • Optional: SSL certificate for HTTPS (recommended)

Step-by-Step

  1. Update your system packages:
    Run sudo apt update && sudo apt upgrade -y to ensure all packages are current.
  2. Install necessary dependencies:
    Install PHP, MariaDB, Nginx, and other required modules:
    sudo apt install nginx mariadb-server php-fpm php-mysql php-xml php-mbstring php-zip php-gd php-curl unzip wget -y
  3. Secure MariaDB:
    Run sudo mysql_secure_installation and follow prompts to set root password, remove anonymous users, and disable remote root login.
  4. Create a database for PrestaShop:
    Login to MariaDB with sudo mysql -u root -p and execute:
    CREATE DATABASE prestashop_db DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
    CREATE USER 'prestashop_user'@'localhost' IDENTIFIED BY 'your_secure_password';
    GRANT ALL PRIVILEGES ON prestashop_db.* TO 'prestashop_user'@'localhost';
    FLUSH PRIVILEGES;
    EXIT;
  5. Download PrestaShop:
    Visit the official website to get the latest version or use wget:
    wget https://www.prestashop.com/download/old/prestashop_1.7.8.9.zip and unzip it in your web directory, e.g., /var/www/prestashop.
  6. Configure permissions:
    Set ownership to www-data and correct permissions:
    sudo chown -R www-data:www-data /var/www/prestashop and
    sudo chmod -R 755 /var/www/prestashop
  7. Create an Nginx server block:
    Create a new file in /etc/nginx/sites-available/prestashop with the following configuration:
    server {
        listen 80;
        server_name yourdomain.com;
    
        root /var/www/prestashop;
        index index.php index.html index.htm;
    
        location / {
            try_files $uri $uri/ /index.php?$args;
        }
    
        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
        }
    
        location ~ /\.ht {
            deny all;
        }
    }
    

    Replace yourdomain.com with your actual domain.

  8. Enable the site and restart Nginx:
    sudo ln -s /etc/nginx/sites-available/prestashop /etc/nginx/sites-enabled/ and then
    sudo nginx -t to test configuration, followed by sudo systemctl reload nginx.
  9. Configure PHP settings:
    Edit /etc/php/8.1/fpm/php.ini (or your PHP version) to increase memory limit, max execution time, and upload size, e.g.:
    memory_limit = 256M
    max_execution_time = 300
    upload_max_filesize = 100M
    post_max_size = 100M

    Then restart PHP-FPM:
    sudo systemctl restart php8.1-fpm.

  10. Complete the installation via web interface:
    Open your browser and navigate to http://yourdomain.com. Follow the on-screen instructions to select language, connect to your database, and configure your store. Set admin credentials and finish the setup.
  11. Secure your site with SSL (optional but recommended):
    Use Certbot to obtain free SSL certificates:
    sudo apt install certbot python3-certbot-nginx
    Then run:
    sudo certbot --nginx -d yourdomain.com and follow prompts to enable HTTPS.

Common Mistakes

  • Not updating system packages before starting.
  • Forgetting to set correct permissions on the PrestaShop files and directories.
  • Using incorrect PHP-FPM socket path or PHP version mismatch in configuration.
  • Failing to create or properly configure the database and user for PrestaShop.
  • Not enabling the site in Nginx or testing the configuration before reload.
  • Skipping SSL setup, leaving the site vulnerable.

Tips

  • Always keep your system and software up to date for security and performance.
  • Use strong, unique passwords for your database and admin accounts.
  • Configure automatic backups of your database and files.
  • Regularly update PrestaShop and its modules for security patches.
  • Monitor server logs for errors and suspicious activity.
  • Use a firewall and fail2ban to protect your server from attacks.

Troubleshooting

If your PrestaShop site is not loading correctly or you encounter errors, follow these steps:

  • Check Nginx error logs:
    sudo tail -f /var/log/nginx/error.log. Look for clues about misconfiguration or permission issues.
  • Test PHP processing: Create a simple info.php file in your web root with <?php phpinfo(); ?>. Access it via browser to verify PHP is working properly.
  • Verify database connection: Ensure your database user has correct privileges and credentials are accurate in the PrestaShop setup.
  • Check permissions: Ensure files are owned by www-data and permissions are correct.
  • Review firewall settings: Confirm ports 80 and 443 are open and accessible.

If issues persist, consult the official PrestaShop forums or Nginx documentation for specific error messages.

Frequently Asked Questions

Can I install PrestaShop without SSL?

Yes, but it’s highly recommended to secure your store with SSL to protect customer data and improve trust.

How do I migrate an existing PrestaShop site to Nginx?

Backup your files and database, then reconfigure your server with Nginx following this guide. Adjust database connection details as needed.

What PHP version should I use with PrestaShop on Ubuntu 24.04?

PrestaShop 1.7.x is compatible with PHP 7.2 to 8.1. Ubuntu 24.04 typically includes PHP 8.1, which is suitable.

How do I enable friendly URLs in PrestaShop?

In the back office, go to Shop Parameters > Traffic & SEO, then enable Friendly URL and regenerate the .htaccess file. For Nginx, ensure URL rewriting rules are correctly configured.

Is it necessary to use MariaDB or MySQL?

PrestaShop supports both, but MariaDB is recommended for better performance and open-source licensing. Ensure the database server is running and accessible.

How often should I update PrestaShop?

Regularly update PrestaShop and its modules to benefit from security patches and new features. Always backup before upgrades.

Related

How to Install PrestaShop with Nginx on Ubuntu 24.04
Scroll to top