Setup Prestashop + Docker

abnaceur
4 min readFeb 3, 2020

--

Prestashop + Docker

Hello everyone, in this article, we will dockerize a PrestaShop e-commerce application, let’s dive into it :

  1. Create a folder name it “myE-shop”
mkdir myE-shop

2. Download Prestashop from the official website here

3. Move the Prestashop zip to our folder “myE-shop” and unzip it

mv prestashop_1.7.6.3.zip [path]/myE-shop
unzip prestashop_1.7.6.3.zip

4. Within the myE-shop folder create a Dockerfile

touch Dockerfile

5. Setup the build in the Dockerfile

FROM ubuntu:18.04# Install.
RUN \
sed -i 's/# \(.*multiverse$\)/\1/g' /etc/apt/sources.list && \
apt-get update && \
apt-get -y upgrade && \
apt-get install -y build-essential && \
apt-get install -y software-properties-common && \
apt-get install -y byobu curl git htop man unzip vim wget && \
rm -rf /var/lib/apt/lists/*
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update
RUN apt-get upgrade
RUN apt-get install -y apache2 libapache2-mod-php
RUN apt install -y php unzip
RUN apt-get install -y php-cli php-common php-mbstring php-gd php-intl php-xml php-mysql php-zip php-curl php-xmlrpc
COPY . /var/www/html:rw
COPY ./config/presta.conf /etc/apache2/sites-available/000-default.conf
RUN a2enmod rewrite
# Define working directory.
WORKDIR /var/www/html
# Define default command.
EXPOSE 80
CMD apachectl -D FOREGROUND

6. Create the ./config/presta.conf file

mkdir config
touch config/presta.conf

7. Setup Apache server config in presta.conf

<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/html >
AllowOverride All
</Directory>
</VirtualHost>

8. Create docker-compose-template.yml

touch docker-compose-template.yml

9. Setup docker services in docker-compose-template.yml file

version: '2'services:

mysql:
image: mysql:5.7
env_file:
- .env
volumes:
- ./.docker/data/mysql/:/var/lib/mysql
- ./.docker/logs/mysql/:/var/log/mysql
ports:
- "3306:3306"
container_name: presta_mysql

phpmyadmin:
image: phpmyadmin/phpmyadmin
ports:
- 8080:80
env_file:
- .env
environment:
PMA_HOST: mysql
VIRTUAL_HOST: phpmyadmin.presta.local
container_name: presta_phpmyadmin
app_dev:
container_name: presta_app
build: .
environment:
- VIRTUAL_HOST=app.presta.local
volumes :
- ./:/var/www/html:rw
restart: always
ports:
- 80:80
links:
- "mysql:presta_mysql"

10. Create .env file for defining the environment variables

touch .env

11. Define the environment variables in .env file

MYSQL_ROOT_PASSWORD=root
MYSQL_PASSWORD=root
MYSQL_DATABASE=prestashop
USER_ID=1000

12. Now let’s build our application. Within the folder “myE-shop” start the docker-compose build.

docker-compose -f docker-compose-template.yml up --build

13. Check if all containers are up

docker ps

Now navigate to http://localhost

14. Let’s connect to our presta_app and setup permission right

docker exec -ti presta_app  bash

15. Setup permission

chown www-data:www-data -R .

Now refresh your browser page

16. Choose the language and continue.

17. Agree to the license and continue

18. Fill in the information and contiinue

19. We need to connect persta_app to mySql service, so first connect to out mySql container

docker exec -ti presta_mysql bash

then connect to mysql server

# Username: root
# Password: root
mysql -u root -p

Lastly, create the new user

CREATE USER 'ps_user'@'%' IDENTIFIED BY 'user';
GRANT ALL ON *.* TO 'ps_user'@'%';
FLUSH PRIVILEGES;
EXIT;

P.S -: If you face this error message while creating the nez user

File './mysql/user.MYD' not found (Errcode: 13 - Permission denied)

Then change the permission right as follow

chown -R mysql:mysql /var/lib/mysql

Recreate the new user again in step 19

Go back to the browser and fill the correct information and click on “test your database connection now!” if it shows “Database is connected” then we can continue to the next step

Wait for the database setup to finish

Once done

Visit http://localhost

Yaay the website is up, in order to visit admin page, we need to remove the install folder

rm -r install/

Visit http://localhost/admin

Then log in to your account with the email addresse and password seted up in the previous steps.

Congratulation your e-commerce website is set and ready to be customized and deployed.

The Github link to the source code here

Hope you found this article helpful.

--

--

abnaceur
abnaceur

Responses (2)