Tutorial-9122023

How to Install Prestashop on Ubuntu 22.04

1 install apache 2

How to Install Prestashop on Ubuntu 22.04

Prestashop is a free and open-source e-commerce solution written in PHP. It allows you to self-hosted and create online stores and grow your online business. Prestashop is a fully-customizable and feature-rich e-commerce solution for building comprehensive eCommerce websites. In the meantime, Prestashop is used by more than 250.000 online stores around the globe and is available in 65 languages.

In this tutorial, we are going to explain how to install an open-source eCommerce solution – Prestashop using the LAMP Stack (Linux, Apache, MySQL/MariaDB, and PHP) on the Ubuntu 22.04 server. This tutorial also includes the basic configuations of LAMP Stack for PHP web applications.

Prerequisite

Here’s what you need to complete this tutorial:

  • An Ubuntu 22.04 server – This tutorial uses an ubuntu server with the hostname ‘server-ubuntu’ and the IP address is ‘192.168.5.100’.
  • A non-root user with root administrative privileges.
  • A domain name pointed to the Ubuntu Server IP address.

Installing Apache Web Server

In the following step, you will install the Apache web server on your Ubuntu system. The Prestashop eCommerce requires at least the Apache web server v2.2. For this installation, you will install Apache v2.4, which is available by default on the Ubuntu repositories.

We always recommend updating and refreshing your repositories before installing any packages. So, run the apt command to update Ubuntu repositories.

sudo apt update

Install the Apache web server using the following apt command. When prompted to confirm the installation, input Y to accept and press ENTER.

sudo apt install apache2

Once the Apache web server is installed, you need to check and verify the ‘apache2‘ service and make sure it’s running. You can use the following systemctl command to check and verify the ‘apache2‘ service.

You will receive an output about the ‘apache2‘ service enabled, which means it will be running automatically at system startup. And the current status of the ‘apache2‘ service is running.

sudo systemctl is-enabled apache2
sudo systemctl status apache2

Lastly, you also need to add the HTTP and HTTPS ports to the UFW firewall. Use the following ufw command to add the custom rule “Apache Full” to the UFW firewall. Then, verify the list of enabled UFW rules.

You will receive an output that the rule “Apache Full” is added to the UFW firewall.

sudo ufw allow "Apache Full"
sudo ufw status

Installing MariaDB Database Server

Since Prestashop only supports the MySQL/MariaDB database, you will now install this database server on your Ubuntu machine. In this example, you will install and use MariaDB as the database for your Prestashop installation.

Use the following apt command to install the MariaDB database server. Input Y when prompted to confirm the installation, then press ENTER.

sudo apt install mariadb-server

After the MariaDB server is installed, check and verify the ‘mariadb‘ service using the following systemctl command. You should receive an output that the ‘mariadb‘ service is enabled, which means it will be automatically running at system boot. And the status of the ‘mariadb‘ service is ‘running‘.

sudo systemctl is-enabled mariadb
sudo systemctl status mariadb

Lastly, you will also need to secure the MariaDB deployment. You can do this via the command-line ‘mysql_secure_installation‘ that is provided by MariaDB server packages.

Run the following ‘mysql_secure_installation‘ to start configuring and securing your MariaDB server deployment.

sudo mysql_secure_installation

You will be prompted with the following questions about the MariaDB server deployment:

  • Switch to unix_socket authentication?. Input n and press ENTER. The default MariaDB root user is already protected. optionally, you can also enable it by typing y for yes.
  • Change the root password?. Input y to confirm and set up your new MariaDB root password.
  • Remove anonymous user?. Input y to confirm.
  • Disallow root login remotely? Input y to confirm. Only local connection will be allowed if you are using the MariaDB root user.
  • Remove test database and access to it?. Input y to confirm and remove the default database ‘test‘.
  • Lastly, input y again to reload all tables privileges on your MariaDB server and apply new changes.

Installing PHP

For the latest version of Prestashop installation, it’s recommended to use at least PHP v7.1. In this demo, you will use PHP 7.4 for the Prestashop, and you can install PHP 7.4 on the latest Ubuntu 22.04 system via third-party repository.

Before installing PHP, run the following apt command to install the basic packages dpendencies for managing repositories.

sudo apt install software-properties-common apt-transport-https -y

Picture

Now add the PHP 7.4 PPA repository to your Ubuntu system via the ‘add-apt-repository’ command below. Also, the following command will automatically update and refresh your Ubuntu repositories.

sudo add-apt-repository ppa:ondrej/php -y

Next, use the following apt command to install PHP packages with some extensions for the Prestashop. When prompted to confirm the installation, input Y to agree and press ENTER.

sudo apt install php7.4 php7.4-curl php7.4-xmlrpc php7.4-soap php7.4-intl php7.4-zip php7.4-cli php7.4-mysql php7.4-common php7.4-opcache php7.4-memcached php7.4-bcmath php7.4-gd php7.4-mbstring php7.4-xml php7.4-gmp php7.4-imagick

After PHP is installed, open the PHP config file ‘/etc/php/7.4/apache2/php.ini’ using your text editor. In this example, we will use nano.

sudo nano /etc/php/7.4/apache2/php.ini

Change details PHP configurations as below. Be sure to change the option ‘date.timezone‘ and ‘memory_limit‘ options with your current server environment.

date.timezone = Europe/Paris
max_execution_time = 130
memory_limit = 256M
allow_url_fopen = On
allow_url_include = Off
post_max_size = 128M
upload_max_filesize = 128M
max_input_vars = 5000

Save your changes and close the file when you are finished.

Next, run the following systemctl command below to restart the ‘apache2‘ service. Also, this will apply any changes to the PHP config file ‘php.ini‘.

sudo systemctl restart apache2

Now the Apache web server and PHP should be running. You can verify that by creating the phpinfo file and testing it via the web browser.

Run the following command to create a new phpinfo file ‘/var/www/html/info.php‘. This file should now be accessible via the URL path ‘/info.php’.

cat <<EOF | sudo tee /var/www/html/info.php
<?php
phpinfo();
?>
EOF

Open the web browser and access the phpinfo file via your server IP address followed by the path of the file ‘/info.php’ (http://192.168.5.100/info.php). You should get a page with detailed information about your PHP installation.

Installing Prestashop System Checker

Before installing Prestashop, let’s install the Prestashop Checker on your current server. This is the PHP script that checks your server environment for the Prestashop installation.

Run the following command to download the Prestashop Checker script to the directory ‘/var/www/html‘.

cd /var/www/html/
wget https://github.com/PrestaShop/php-ps-info/archive/refs/tags/v1.1.tar.gz

Extract the Prestashop Checker source and rename the directory to ‘check-ps‘.

tar -xzvf v1.1.tar.gz
mv php-ps-info-1.1 check-ps

Back to the web browser and visit your server IP address followed by the URL path ‘check-ps’ (i.e: http://192.168.5.100/check-ps/phppsinfo.php).

Log in with the default user and password ‘prestashop‘.

Now ensure all of your LAMP Stack configurations are met with the Prestashop requirements.

If some settings missing, you can edit the PHP config file ‘/etc/php/8.1/apache2/php.ini‘. Also, you can install PHP extensions if there is an extension missing.

Creating MariaDB Database and User

Before you start installing Prestashop, you will need to create a new MariaDB database and user.

Run the following ‘mysql’ command to log in to the MariaDB shell as the MariaDB ‘root‘ user. When prompted for a password, input your password or you can just press ENTER.

sudo mysql -u root -p

Next, run the following queries to create a new database and user for Prestashop. In this example, the database for Prestashop will be ‘prestashopdb‘ with the MariaDB user ‘prestashop‘. You can change the password here with the strong password.

CREATE DATABASE prestashopdb;
GRANT ALL PRIVILEGES ON prestashopdb.* TO 'prestashop'@'localhost' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;

Now run the following queries to verify the privileges for the MariaDB user ‘prestashop@localhost‘. Then, log out from the MariaDB shell. You should receive information about the ‘prestasho@localhost‘ user having privileges for the database ‘prestashopdb‘.

SHOW GRANTS FOR prestashop@localhost;
quit

Downloading Prestashop Source Code

After created the MariaDB database and user, you will download the Prestashop source code and setup the correct permission and ownership of the prestashp installation directory.

Now run the apt command below to install the ‘unzip‘ package. This will be used to extract the Prestashop source code.

sudo apt install unzip -y

Move the working directory to ‘/var/www/‘ and download the Prestashop source code using the wget command below.

cd /var/www/
wget https://download.prestashop.com/download/releases/prestashop_1.7.8.7.zip

Extract the Prestashop source code to the new directory ‘/var/www/prestashop‘ via the ‘unzip‘ command below.

unzip prestashop_1.7.8.7.zip -d /var/www/prestashop

Now change the ownership of the Prestashop installation directory ‘/var/www/prestashop‘ and change its permission. The ownership should be the user ‘www-data‘and permission is ‘u+rw‘ (owner/user can write to the directory).

chown -R www-data:www-data /var/www/prestashop
chmod u+rw /var/www/prestashop

Setting Up Apache Virtual Host

All of your dependencies and configurations are ready, and the Prestashop source code is downloaded. Now you will set up the Apache virtual host for your Prestashop installation.

Before you start, ensure you have the domain name pointed to your Ubuntu server IP address and the SSL certificates generated. Also, you must enable some of the Apache2 modules for your Prestashop.

Use the following command to enable Aapche2 modules.

sudo a2enmod ssl rewrite headers

Create a new virtual host configuration for Prestashop ‘prestashop.conf‘ using the following command. All Apache2 virtual host files must be located at the ‘/etc/apache2/sites-available/‘ directory.

sudo nano /etc/apache2/sites-available/prestashop.conf

Add the following virtual host configurations for the prestashop. Be sure to change the domain name and the path of SSL certificates.

<VirtualHost *:80>
    ServerName hwdomain.io
    Redirect permanent / https://hwdomain.io/
</VirtualHost>

<VirtualHost *:443>
    ServerAdmin [email protected]
    DocumentRoot /var/www/prestashop
    ServerName hwdomain.io

    Protocols h2 http/1.1

    SSLEngine On
    SSLCertificateFile /etc/letsencrypt/live/hwdomain.io/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/hwdomain.io/privkey.pem

    <Directory /var/www/prestashop>
        Options +FollowSymlinks
        AllowOverride All
        Require all granted
    </Directory>

     ErrorLog /var/log/apache2/prestashop_error.log
     CustomLog /var/log/apache2/prestashop_access.log combined
</VirtualHost>

Save the configuration file when you are finished and close the file.

Next, run the following command to enable the virtual host file ‘prestashop.conf’. Then, verify your configurations.

You should receive an output message such as “Syntax OK” when your configurations have no error.

sudo a2ensite prestashop.conf
sudo apachectl configtest

Now run the following systemctl command to restart the ‘apache2‘ service and apply new changes. And you can start the installation wizard for Prestashop via the web browser.

sudo systemctl restart apache2

Installing Prestashop via Web Installer

Back to your web browser and browse the domain name of your Prestashop installation (i.e: https://hwdomain.io/). You should see the web installer is starting the Prestashop installation.

Select the default language for your PrestaShop installation and click Next. The default installation language for PrestaShop is ‘English‘.

Click agree when showed the Prestashop License agreement page.

Now create a new admin user for your Prestashop installation. Input details admin user, email, and password. Then, click Next to continue to the database configurations.

For the store content, you can select ‘No” and click ‘Next‘.

For the Prestashop database configuration. Input details database user, database name, and the password that you have created. Then, click Next and the Prestashop installation will be starting.

Below you can see the installation is processed.

When the Prestashop installation is finished, you will see the page that informs you about your Prestashop installation. Also, there is an additional change that you should do, which is deleting the ‘install‘ directory on your Prestashop document root.

Back to your terminal server and run the following command to make some of the Prestashop directory writable and delete the Prestashop ‘install‘ directory.

chmod u+rw /var/www/prestashop/var/cache
chmod u+rw /var/www/prestashop/var/logs
chmod u+rw /var/www/prestashop/img
chmod u+rw /var/www/prestashop/mails
chmod u+rw /var/www/prestashop/modules
chmod u+rw /var/www/prestashop/translations
chmod u+rw /var/www/prestashop/upload
chmod u+rw /var/www/prestashop/download
chmod u+rw /var/www/prestashop/app/config
chmod u+rw /var/www/prestashop/app/Resources/translations

rm -rf /var/www/prestashop/install

Back to the web browser and click the button ‘Manage your store‘ to access the Prestashop administration login. You will be redirected to the new Prestashop login page, and be sure to copy the path of your Prestashop admin URL.

Input the admin user and password for your Prestashop and click ‘LOG IN‘.

You will get the administration dashboard of Prestashop.

At this point, you have finished the installation of the open-source eCommerce solution Prestashop on Ubuntu 22.04.

Conclusion

Throughout this tutorial, you have learned how to install the eCommerce solution Prestashop on an Ubuntu 22.04 server. You have also learned the basic installation and configuration of the LAMP Stack (Apache, MariaDB, and PHP) on the Ubuntu system and learned the how to secure MariaDB server and setup Apache virtual host.

Ultimately, you have the Prestashop eCommerce solution running with LAMP Stack on an Ubuntu server and secured via SSL certificates. You can now add your themes for your customization and add plugins to extend your eCommerce website. Then, you can add your products.

Đăng ký liền tay Nhận Ngay Bài Mới

Subscribe ngay

Cám ơn bạn đã đăng ký !

Lỗi đăng ký !

Add Comment

Click here to post a comment

Đăng ký liền tay
Nhận Ngay Bài Mới

Subscribe ngay

Cám ơn bạn đã đăng ký !

Lỗi đăng ký !