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
- Update your system packages:
Runsudo apt update && sudo apt upgrade -yto ensure all packages are current. - 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 - Secure MariaDB:
Runsudo mysql_secure_installationand follow prompts to set root password, remove anonymous users, and disable remote root login. - Create a database for PrestaShop:
Login to MariaDB withsudo mysql -u root -pand 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;
- 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.zipand unzip it in your web directory, e.g.,/var/www/prestashop. - Configure permissions:
Set ownership to www-data and correct permissions:
sudo chown -R www-data:www-data /var/www/prestashopand
sudo chmod -R 755 /var/www/prestashop - Create an Nginx server block:
Create a new file in/etc/nginx/sites-available/prestashopwith 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.comwith your actual domain. - Enable the site and restart Nginx:
sudo ln -s /etc/nginx/sites-available/prestashop /etc/nginx/sites-enabled/and then
sudo nginx -tto test configuration, followed bysudo systemctl reload nginx. - 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. - Complete the installation via web interface:
Open your browser and navigate tohttp://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. - 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.comand 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.phpfile 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-dataand 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 Hide the Meet Section in Gmail on a Laptop or Desktop
- How to Hide the Mouse Pointer While Typing in Windows 11
- How to Hide the Home Button in Microsoft Edge