Configure OpenCart with Facebook Business Extension on FreeBSD 12

Updated on July 25, 2024
Configure OpenCart with Facebook Business Extension on FreeBSD 12 header image

Introduction

This tutorial shows how to perform the end-to-end installation of Opencart 3.0.3 with the FaceBook BE plugin. Opencart is one of the most popular e-commerce solutions and has thousands of plugins and extensions available. This tutorial uses the FAMP stack, consisting of FreeBSD 12.2, Apache 2.4, MySQL 5.7, and PHP 7.4. All components of the FAMP stack are available in the FreeBSD-12.2-RELEASE packages. This guide assumes you have a DNS record for yourhostname.example.com that resolves your FreeBSD server's IP address.

1. Install the FAMP Stack and OpenCart

You must have root privileges to install the packages, and we recommend using sudo for security.

Install Apache.

$ sudo pkg install -y apache24

Enable Apache in /etc/rc.conf.

$ sudo service apache24 enable

Start the Apache web-server.

$ sudo /usr/local/etc/rc.d/apache24 start

Install MySQL.

$ sudo pkg install -y mysql57-server

Install PHP 7.4 and the required dependencies for OpenCart.

$ sudo pkg install -y php74 mod_php74 php74-json php74-dom

Install Opencart.

$ sudo pkg install -y opencart

PHPMyAdmin is optional, but it's useful for MySQL administration.

$ sudo pkg install -y phpMyAdmin-php74

2. Configure the Software

Configure Apache

Verify that the PHP module is loaded in /usr/local/etc/apache24/httpd.conf. It should look exactly like this:

$ sudo cat /usr/local/etc/apache24/httpd.conf | grep php
LoadModule php7_module        libexec/apache24/libphp7.so

Open /usr/local/etc/apache24/httpd.conf in an editor.

$ sudo ee /usr/local/etc/apache24/httpd.conf

Add the following lines to enable PHP in Apache.

#PHP Configuration
DirectoryIndex index.php
<FilesMatch "\.php$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>

Add the following lines to create the OpenCart alias. The example shown sets the OpenCart URL to http://yourhostname.example.com/opencart.

#OpenCart Alias
Alias /opencart /usr/local/www/opencart/
AcceptPathInfo On
<Directory /usr/local/www/opencart>
  AllowOverride None
  Require all granted
</Directory>

Save the file and exit the editor.

Configure PHP

Change to the /usr/local/etc/ directory.

$ cd /usr/local/etc/

Copy the production template to php.ini.

$ sudo cp php.ini-production php.ini

Edit php.ini.

$ sudo ee /usr/local/etc/php.ini

Change the upload_max_filesize default value of 2M to 999M.

upload_max_filesize = 999M

Save the file and exit the editor.

Configure MySQL

Configure the root password for MySQL. Start the server without authentication.

$ sudo sysrc mysql_args="--skip-grant-tables"
$ sudo service mysql-server enable
$ sudo service mysql-server start
$ mysql -u root

Set the root password.

> FLUSH PRIVILEGES;
> ALTER USER 'root'@'localhost' IDENTIFIED BY 'insertrootpasswordhere';

Exit MySQL and remove the --skip-grant-tables argument to re-enable authentication.

> exit
$ sudo service mysql-server stop
$ sudo sysrc -x mysql_args
$ sudo service mysql-server start

Create a dedicated user to manage the Opencart database. The example database is mystoredb, and managed by the mysql user:

$ mysql -u root -p
> CREATE USER 'mysql'@'localhost' IDENTIFIED BY 'mysqluserpassword';
> create database mystoredb;
> GRANT ALL ON mystoredb.* TO 'mysql'@'localhost' IDENTIFIED BY 'mysqluserpassword';
> exit

This fulfills all the dependencies for OpenCart. Restart Apache to test the configuration.

$ sudo /usr/local/etc/rc.d/apache24 restart

The output should look like this:

Performing sanity check on apache24 configuration:
Syntax OK
Stopping apache24.
Waiting for PIDS: 1313.
Performing sanity check on apache24 configuration:
Syntax OK
Starting apache24.

3. Configure OpenCart

Log in to the Opencart URL, for example, http://yourhostname.example.com/opencart. Check that folders are writable and all the requirements are fulfilled as shown in the images below:

Opencart1

Opencart2

Opencart3

Configure the MySQL data with mysql user, mysqluserpassword password, and mystoredb database defined in Section 2.1.

Opencart4

Configure the admin user and opencartadminpasswd that will be used for accessing the Opencart administration section, also configure the contact email address for the store.

Opencart5

The configuration part for Opencart is complete. The next section will focus on additional steps required to run Opencart securely and properly on FreeBSD-12.2.

Opencart6

4. Secure the OpenCart Directories

Change the owner of the OpenCart web directory to the user and group www.

$ sudo chown -R www:www /usr/local/www/opencart

Remove the /usr/local/www/opencart/install directory.

$ sudo rm -rf /usr/local/www/opencart/install

Move the location of /usr/local/www/opencart/system/storage sub-directory to /usr/local.

$ cd /usr/local/www/opencart/system
$ sudo cp -R storage /usr/local/
$ sudo rm -rf storage

Make sure /usr/local/storage is owned by the www user and group as well.

$ sudo chown -R www:www /usr/local/storage

Edit /usr/local/www/opencart/config.php.

$ sudo ee /usr/local/www/opencart/config.php

Change the line containing the DIR_STORAGE directive to the one shown below.

define('DIR_STORAGE', '/usr/local/storage/');

Perform the same changes in /usr/local/www/opencart/admin/config.php.

$ sudo ee /usr/local/www/opencart/admin/config.php
define('DIR_STORAGE', '/usr/local/storage/');

5. Configure Facebook for OpenCart

Obtain the Facebook Business Extension Plugin

Download the FaceBook Business Extension for OpenCart plugin here Link1 or here Link2. Registration is required.

5.2 Install the Facebook Plugin

Log in to the Openart URL. In this example, we have called it http://yourhostname.example.com/opencart/admin/ with admin user and opencartadminpasswd configured in Section 3. Locate the Extensions/Install sub-menu, and proceed to upload the facebookadsextension.ocmod.zip file.

Opencart7

After uploading the file, enter the **Extensions/Modifications **sub-menu.

Opencart7

Press the Refresh button, the Facebook Business Extension should now be visible in the Navigation Bar.

Opencart8

Go to System/Users/User Groups, select the Administrator group

Opencart9

Now proceed to select the permissions to access and modify the Facebook-related extensions.

Opencart10

Once the permssions have been modified, go to the Facebook Business Extension Menu and press the Get Started button, log in with your Facebook account.

Opencart11

Conclusion

Congratulations! You have sucessfully installed Opencart+ Facebook Business extension plugin in FreeBSD-12.2.

Further Steps

Before putting your e-commerce site into operation, it is highly recommended to enable HTTPS with a valid SSL certificate. In this way, all the communication will be encrypted, and customers will feel safe when they shop in your e-store.

References