ផ្នែកទី 1៖ បង្កើតគេហទំព័រ eCommerce ដោយប្រើ PrestaShop Framework

Build an ecommerce site using PrestaShop framework

PrestaShop is an eCommerce platform that specializes in the development of e-commerce sites. Its purpose is to assist you in creating a stylish, fast online store. In this tutorial, 1Byte will show you how to deploy a LAMP-based PrestaShop store on a CentOS 7 server instance.

តម្រូវការជាមុន

ឈ្មោះដែន

Here are some reasons why you must have a ឈ្មោះដែន:

  • When purchasing Cloud Server, you need a domain name to connect to the hosting.
  • Without a domain name, you can not install វិញ្ញាបនបត្រ SSL នៅ​លើ​វា
  • When you put your website into business, how do customers know what your website’s name is to access?

→ ឈ្មោះដែនគឺត្រូវតែ

→ ប្រសិនបើអ្នកមិនមានឈ្មោះដែនទេ សូមពិចារណាទស្សនា 1Byte ដើម្បីទិញវា។

2. Cloud Server

+ ដោយសារតែអ្នកមានសិទ្ធិចូលដំណើរការជា root ពេញលេញ អ្នកអាចដំឡើងក្របខ័ណ្ឌ PrestaShop ទាំងស្រុង ចំណែកវាមិនអាចធ្វើទៅបានជាមួយការបង្ហោះចែករំលែក។

→ If you do not have one, you can buy it directly at Cloud Server

3. Deploy and logged in to your Server

To be able to install packages in the easiest and most standard way. You need to use terminal

→ Logged in to your Cloud Server

ចំណាំ:

If your Cloud Server was previously used to host a website. Then 1Byte encourages you to:

  • បម្រុងទុកទិន្នន័យទាំងអស់ (បើចាំបាច់)
  • Reinstall Cloud Server

You may ask why?

→ ដោយសារតែមានលទ្ធភាពដ៏សំខាន់ដែលកញ្ចប់ និងក្របខ័ណ្ឌដែលបានដំឡើងពីមុនអាចប៉ះទង្គិចជាមួយកញ្ចប់ និងក្របខ័ណ្ឌដែលហៀបនឹងដំឡើង។

Let’s Get Your Hands wet

ជំហានទី 1: ចូលទៅក្នុង Server របស់អ្នក។

Log in to Cloud server by terminal

ជំហានទី ២ ៈធ្វើបច្ចុប្បន្នភាពប្រព័ន្ធ

Regardless of what we decide to do, we should first make sure that all of our packages is up to date.

sudo yum update -y

Next, we need to install nano, unzip, and wget packages. We will need these commands later on

  • ណាណូ៖ a command-line-based text editor
  • ពន្លា៖ ពាក្យបញ្ជាត្រូវបានប្រើដើម្បីពន្លាឯកសារ zip
  • Wget៖ a free and open-source software package for retrieving files using HTTP, HTTPS, and FTP
sudo yum install nano -y
sudo yum install unzip -y
sudo yum install wget -y

By default, SELinux is បានបើក on a default CentOS 7 system. We recommend disabling SELinux on your system to prevent any security conflicts. You can disable SELinux by editing the /etc/selinux/config ឯកសារ

nano /etc/selinux/config
  • រកបន្ទាត់ខាងក្រោម: SELINUX=enforcing
  • Then, replace it with the following line: SELINUX=permissive
  • Next, use combined-key Clrl + O ដើម្បីរក្សាទុកនិង បញ្ជា (Ctrl) + X ដើម្បីបិទឯកសារ។
  • Finally, restart your system to apply the changes.
sudo reboot

In order for PrestaShop to function correctly, you need to set up ជង់ចង្កៀង នៅលើម៉ាស៊ីនរបស់អ្នក មុនពេលអ្នកអាចដាក់ពង្រាយ និងប្រើប្រាស់ PrestaShop ។ នៅក្នុងជំហានខាងក្រោម ខ្ញុំនឹងបង្ហាញអ្នកពីរបៀបដំឡើង និងកំណត់រចនាសម្ព័ន្ធ Apache, MariaDB និង PHP ។

ចំណាំ:

LAMP stands for Linux, Apache, MySQL, and PHP. Together, they provide a proven set of software for delivering high-performance web applications

ជំហានទី 3: ដំឡើង និងកំណត់រចនាសម្ព័ន្ធ Apache

sudo yum -y install httpd

ចំណាំ:

In case you cannot install httpd as shown below

Don’t worry, This could be because the repository package of HTTP has been excluded to another place. This leads to you not being able to run “សូមដំឡើង httpd"

(If you did not run into a problem like this, please skip)

To fix this, please do as follow:

nano /etc/yum.conf
  • As you can see, you cannot install the “httpd"កញ្ចប់ដោយសារតែ បច្ចុប្បន្នវាត្រូវបានដកចេញ
  • Ok we know the reason, now we just need to remove “httpdពី“ដកចេញ"បន្ទាត់
  • By the way, we also have to remove “mariadb"និង"កម្មវិធី PHPពី“ដកចេញ"បន្ទាត់ផងដែរ។

→ Because later on, we need to install PHP and MariaDB

Please make sure that the file yum.conf ត្រូវ​បាន​កែប្រែ​យ៉ាង​ត្រឹមត្រូវ​ដូច​បង្ហាញ​ខាង​ក្រោម

(មិនមាន php, httpd, និង mariadb ទៀតទេនៅក្នុងផ្នែកដកចេញ) 
  • As always, use combined-key Clrl + O ដើម្បីរក្សាទុកនិង បញ្ជា (Ctrl) + X ដើម្បីបិទឯកសារ។
  • Ok let’s install httpd package again by running this command  
yum clean all && yum update -y && yum install httpd -y

បញ្ចប់​ការ​ជួសជុល​ដំឡើង HTTPD ពេល​ទទួល​បាន​កំហុស!!!

Back to the road, if there is no error when installing httpd, please follow the steps below:

sudo systemctl start httpd
sudo systemctl enable httpd
sudo systemctl status httpd
(Please make sure that Apache HTTP Server is running )

Modify the current firewall rules so that visitors can access your online store:

sudo firewall-cmd --zone=public --permanent --add-service=http
sudo firewall-cmd --reload
sudo firewall-cmd --list-services
(បន្ថែមសេវាកម្ម http ដោយជោគជ័យ)

ជំហានទី 4៖ ដំឡើង និងកំណត់រចនាសម្ព័ន្ធ MariaDB

Install MariaDB and set it to automatically start after the system reboot:

sudo yum install mariadb mariadb-server -y
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service
sudo systemctl status mariadb.service
(សូមប្រាកដថាម៉ាស៊ីនមេមូលដ្ឋានទិន្នន័យ MariaDB កំពុងដំណើរការ)  

Execute the secure MySQL installation process:

sudo /usr/bin/mysql_secure_installation

Go through the process in accordance with the instructions below:

Enter current password for root (enter for none): Press the Enter key
Set root password? [Y/n]: Input Y, then press the Enter key
New password: Input a new root password, then press the Enter key
Re-enter new password: Input the same password again, then press the Enter key
Remove anonymous users? [Y/n]: Input Y, then press the Enter key
Disallow root login remotely? [Y/n]: Input Y, then press the Enter key
Remove test database and access to it? [Y/n]: Input Y, then press the Enter key
Reload privilege tables now? [Y/n]: Input Y, then press the Enter key

ចំណាំ:

  • In these steps above, you must remember the root user’s password in order to access the database.
  • Current password for root = password of root to connect to your server
  • Set root password = password of root to connect to your database

ចុងបញ្ចប់នៃការជូនដំណឹង

Now, log into the MySQL shell so that you can create a dedicated database for PrestaShop:

mysql -u root -p
(បញ្ចូលពាក្យសម្ងាត់ឫស MariaDB ដែលអ្នកបានកំណត់ពីមុនដើម្បីចូល)

Then setup the PrestaShop database using the following commands

CREATE DATABASE prestashop;
GRANT ALL PRIVILEGES ON prestashop.* TO 'prestashopuser'@'localhost' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;
 (ត្រូវប្រាកដថាជំនួសឈ្មោះមូលដ្ឋានទិន្នន័យ "prestashop" ឈ្មោះអ្នកប្រើមូលដ្ឋានទិន្នន័យ "prestashopuser" និងពាក្យសម្ងាត់អ្នកប្រើមូលដ្ឋានទិន្នន័យ "yourpassword" នៅក្នុងពាក្យបញ្ជានីមួយៗជាមួយនឹងរបស់អ្នកផ្ទាល់។ )  

ជំហានទី 5: ដំឡើង PHP និងផ្នែកបន្ថែមដែលត្រូវការ

Install PHP and required extensions using the yum command:

sudo yum install httpd mariadb-server php php-cli php-bcmath php-mysqli php-gd php-pdo php-xmlrpc php-intl php-posix php-json php-curl php-zip unzip -y

After installing all the required packages, edit the php.ini file and change some default settings:

nano /etc/php.ini

Change the following lines corresponding to the values in the figure below:

TIP BEFORE EDITING:

When working with nano, to find navigate to a certain keyword, use បញ្ជា (Ctrl) + Wបន្ទាប់មកវាយអក្សរ ពាក្យគន្លឹះ to find, and finally just press បញ្ចូល (ជាមូលដ្ឋាន វាដំណើរការដូចអ្នកចុច បញ្ជា (Ctrl) + F ដើម្បីដាក់ពាក្យគន្លឹះនៅក្នុងកម្មវិធីរុករករបស់អ្នក ឬនៅក្នុង Microsoft Word Office)

→ The nano will automatically move the mouse pointer to the location containing that keyword 

max_input_vars = 3000
post_max_size = 64M
upload_max_filesize = 64M
max_execution_time = 600
memory_limit = 256M
(The original value of max_input_vars is 1000, now change to 3000) 
(The original value of post_max_size is 8M, now increase to 64M)
(តម្លៃដើមនៃ upload_max_filesize គឺ 2M ឥឡូវនេះកើនឡើងដល់ 64M)
(តម្លៃដើមនៃ max_execution_time គឺ 30 ឥឡូវនេះប្តូរទៅ 600)
(តម្លៃដើមនៃ memory_limit គឺ 128M ឥឡូវនេះកើនឡើងដល់ 256M) 

ចំណាំ:

Please make sure to press បញ្ជា (Ctrl) + O ដើម្បីរក្សាទុកនិង បញ្ជា (Ctrl) + X ចាក់ចេញ

ចុងបញ្ចប់នៃការកត់សម្គាល់

Put all of the configuration changes into effect:

sudo systemctl restart httpd mariadb

ជំហានទី 6៖ បង្កើត web root ហើយទាញយកប័ណ្ណសារ PrestaShop

Create web root “prestashop”

mkdir /var/www/html/prestashop
cd /var/www/html/prestashop

→ After this, all website-related data such as plugins, themes, files, …etc will be put in this directory

Download the latest stable version of PrestaShop, which is 1.7.8.3 ដូចជាការសរសេរ៖

sudo wget https://www.prestashop.com/download/releases/prestashop_1.7.8.3.zip
ls -l
(Successfully downloaded prestashop version 1.7.8.3)
  • For future reference, you can always find the URL of the latest download from the គេហទំព័រផ្លូវការរបស់ PrestaShop.
  • ឥឡូវនេះយើងត្រូវការ unzip ដើម្បីពន្លាប័ណ្ណសារ
unzip prestashop_1.7.8.3.zip
ls -la
(Here we can see, after we unzip the file “prestashop_1.7.8.3.zip”, we get another file “prestashop.zip” )

ចំណាំ:

Please do not delete or unzip the file “prestashop.zip“. Because this file will be used when installing PrestaShop in the browser (ផ្នែកទី 2) 

ចុងបញ្ចប់នៃការកត់សម្គាល់

Setup the proper ownership for all of the files and directories in the archive, then move them to the web root directory:

chown -R apache:apache /var/www/html/prestashop

Step 7: Remove the default page and configure apache to accept PrestaShop site

nano /etc/httpd/conf.d/prestashop.conf

After running the above command, please paste the following lines into prestashop.conf

<VirtualHost *:80>
    ServerAdmin admin@hobbykh.fun
    ServerName hobbykh.fun
    ServerAlias *.hobbykh.fun
    DocumentRoot /var/www/html/prestashop

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

    ErrorLog /var/log/httpd/prestashop-error_log
    CustomLog /var/log/httpd/prestashop-access_log common
</VirtualHost>

ចំណាំ:

ចងចាំថាការផ្លាស់ប្តូរតម្លៃនៅ:

  • ServerAdmin into your webmaster email
  • ServerName to your domain name

ចុងបញ្ចប់នៃការកត់សម្គាល់

Step 8: Visit your server from a web browser

http://[your-server-IP]/
(As you can see, the server’s PHP seems to be outdated. So we will update PHP to the latest version as below)

8.1 – Let’s start by installing yum-utils

yum install yum-utils -y

8.2 – Let’s download Remi repo

yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y

8.3 – We will now run the commands to install PHP version 7.4

yum-config-manager --enable remi-php74

8.4 – Refresh the repository and restart the httpd service

yum update -y
systemctl restart httpd

8.5 - តោះពិនិត្យមើលកំណែ PHP របស់យើង។

php --version
(សូមអបអរសាទរ យើងបានធ្វើបច្ចុប្បន្នភាពកំណែ PHP ដោយជោគជ័យពី 5.4 ទៅ 7.4)

8.6 – Visit your server again via a web browser

http://[your-server-IP]/
(Hic hic, one more error. But don’t worry because 1Byte is here to help you overcome all difficulties ^^)

Ok now we just need to back our terminal and install the so-called PHP zip បន្ថែម

yum install php-zip -y
systemctl restart httpd

8.7 – Comeback our server in the web browser again

As you can see, everything turned out perfectly. The PrestaShop wizard will automatically install it on your server. All you need to do now is enjoy a cup of tea.

Once the installation is done, we’ll be… well, the post is already too long. Therefore, I would like to pause here and see you in ជាផ្នែកមួយ 2