当前位置: 首页>>技术教程>>正文


如何在Debian 9上安装OroCRM

OroCRM是一个基于Symfony2的框架,用PHP编程语言开发的灵活的开源客户关系管理(CRM)平台。 OroCRM可由多渠道电子商务市场团队使用,它能够管理客户和联系信息,并跟踪市场营销活动的绩效。 OroCRM还可以轻松地与流行的电商平台集成,例如Magento,MailChimp或Zendesk。 OroCRM通常部署在Linux下的Apache /Nginx Web服务器,PHP和MySQL /MariaDB数据库下,也称为LAMP或LEMP技术栈。

本教程向您展示如何在Debian 9上安装和配置最新版本的OroCRM。

要求

  • 在虚拟专用服务器或裸机上安装Debian 9轻量级服务器。(注:裸机是指无操作系统的计算机)
  • 服务器应至少具有2GB的RAM。
  • 服务器上的root访问权限。
  • 服务器应具有手动配置或使用DHCP的静态IP地址。
  • 指向服务器的域名或子域名。
  • 邮件服务器或可以对公用邮件服务器服务进行访问,例如“Gmail”,“Yahoo!”,“Outlook”。

准备服务器

在第一步中,使用root帐户或具有root用户权限的帐户登录到服务器控制台。

配置主机名

通过执行以下命令来配置您的计算机主机名。您应该用自己的域名替换本示例(www.mycrm.com)中使用的主机名变量。

hostnamectl set-hostname www.mycrm.com

更改计算机名称后,通过执行以下命令来验证计算机主机名。请注意,目前机器主机名处于临时状态,并不会立即生效。重新启动计算机后,它才会实际应用。

host –s 
host –f

安装Debian更新

在重启机器之前,请确保Debian系统版本是最新的,其中包含最新的软件更新,安全补丁和新的内核。运行以下命令以安装更新。

apt update 
apt upgrage

更新过程完成后,您需要通过执行以下命令来重启Debian服务器,以应用内核更新和主机名更改。

systemctl reboot

安装LAMP栈

在接下来的步骤中,我们将在Debian 9中安装LAMP软件包。OroCrm平台主要是用PHP 服务器端编程语言开发的,因此我们将必须安装PHP解释器和Apache HTTP服务器。使用以下命令安装Apache和PHP:

apt install apache2 libapache2-mod-php7.0 php7.0 php7.0-gd php7.0-opcache php7.0-json php7.0-mbstring php7.0-xml php7.0-mcrypt php7.0-cli php7.0- curl php7.0-zip php7.0-intl php7.0-soap php7.0-tidy

如果要检查所有已安装的PHP模块是否处于活动状态,请执行以下命令。

php –m

为了存储不同的配置,例如用户,会话,联系人和其他数据,OroCRM需要一个关系数据库作为后端。在本指南中,我们将使用MariaDB数据库部署OroCRM。为了安装MariaDB和用于访问MariaDB数据库的PHP模块,请在服务器控制台中执行以下命令。

apt install mariadb-server php7.0-mysql mariadb-client

如果您无法使用公共邮件服务器连接OroCRM,则应通过执行以下命令在系统上安装Postfix MTA服务器。

apt install postfix

下一步,通过执行以下命令,确保在系统中安装Node.js javascript引擎。 OroCRM需要Node.js。

apt-get install nodejs

在此步骤中,我们将调整一些PHP设置。首先,备份php.ini文件。

cp /etc/php/7.0/apache2/php.ini{,.backup}

【注:上述命令等价于:cp /etc/php/7.0/apache2/php.ini, cp /etc/php/7.0/apache2/php.ini.backup】

然后使用文本编辑器打开/etc/php/7.0/apache2/php.ini,并按如下方式更改行。另外再次强调,务必先请备份PHP配置文件。

nano /etc/php/7.0/apache2/php.ini

【注:nano是超简单的Linux文本编辑器。当然,这里用其他的编辑器也可以。】

在php.ini文件中搜索,编辑和更改以下变量:

file_uploads = On
default_charset = UTF-8
memory_limit = 512M
date.timezone = Europe/London>

要支持大文件附件,您应该搜索并增加upload_max_file_sizepost_max_filesize,根据您自己的要求设置变量值。您还应确保date.timezone变量配置为与服务器的物理位置匹配。可以通过在以下链接中查询PHP文档提供的时区列表来找到PHP时区列表。

http://php.net/manual/en/timezones.php

保存php.ini文件。

接下来,启用PHP 7的OPCache插件,以提高OroCRM的加载速度。在文件底部[opcache]声明的下方添加或更改以下行,如下所示:

nano /etc/php/7.0/apache2/conf.d/10-opcache.ini

[opcache]
opcache.enable=1 
opcache.enable_cli=1 
opcache.interned_strings_buffer=8 
opcache.max_accelerated_files=11000 
opcache.memory_consumption=256 
opcache.fast_shutdown=1
opcache.load_comments=1
opcache.save_comments=1

保存并关闭文件。为了应用到目前为止所做的所有更改,请通过执行以下命令来重新启动Apache服务。

systemctl restart apache2

接下来,通过执行以下命令为Apache启用重写模块。需要通过重写模块通过服务器Webroot路径中的.htaccess文件来修改Apache运行时环境。

a2enmod rewrite 
 systemctl restart apache2

为了通过HTTPS协议安全地安装和访问OroCRM,请通过执行以下命令来启用SSL模块和SSL站点配置文件。

a2enmod ssl
a2ensite default-ssl.conf

使用文本编辑器打开Apache默认的SSL站点配置文件,并在DocumentRoot指令后面添加以下代码行来启用URL重写规则,如以下示例所示。确保将webroot路径更改为在/var/www/html/web

nano /etc/apache2/sites-enabled/default-ssl.conf

SSL站点配置文件摘录:

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

然后打开/etc/apache2/sites-enabled/000-default.conf文件进行编辑,并添加与SSL配置文件相同的URL重写规则。在DocumentRoot语句后面插入如下例所示的代码行。另外,将DocumentRoot路径更改为在/var /www /html/web

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

最后,创建/var /www/html/web目录并重新启动Apache守护程序,以应用到目前为止的所有更改。

mkdir -p /var/www/html/web

systemctl restart apache2

通过HTTP协议访问您的域名或服务器IP地址。由于您使用的是自动生成的Self-Signed证书,因此浏览器中将显示警告。忽略警告以接受不受信任的证书,您将被重定向到Apache默认网页,如下图所示。

HTTPS://yourdomain.tld

Apache default web page will show up

Apache default web page will show up

在Debian系统上启用防火墙(例如UFW防火墙)后,您可能无法访问Apache Web服务器。确保添加新规则以允许HTTP和HTTPS通信能通过防火墙。以下命令用于UFW防火墙:

ufw allow  http
ufw allow https

如果您使用iptables管理Debian服务器上防火墙的原始规则,那么添加以下规则以,允许防火墙上的端口80和443的入站通信,以便客户端可以浏览OroCrm应用程序。保存iptables规则,然后重新启动并启用该服务。

apt-get install -y iptables-persistent

iptables -I INPUT -p tcp –destination-port 80 -j ACCEPT
iptables -I INPUT -p tcp –destination-port 443 -j ACCEPT

netfilter-persistent  save

systemctl restart netfilter-persistent
systemctl status netfilter-persistent
systemctl enable netfilter-persistent.service

最后,通过执行以下命令,在您的应用程序webroot路径中创建一个PHP信息文件。

echo '<?php phpinfo();?>' | tee /var/www/html/web/info.php

通过HTTPS协议用以下URL上从浏览器访问PHP信息脚本文件,并检查PHP服务器环境配置。向下滚动到日期设置以检查PHP时区配置。

HTTPS://domain.tld/info.php

下一步,通过登录数据库控制台并向空白root帐户插件发出以下命令, 以保护MariaDB root帐户。请注意,MariaDB根(root)帐户与Linux系统根帐户不同。这些根帐户是两个不同的帐户。 Linux超级用户用于管理系统,MySQL超级用户用于管理MariaDB数据库。

mysql -h localhost

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 2

Server version: 10.1.26-MariaDB-0+deb9u1 Debian 9.1

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

MariaDB [(none)]> use mysql;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

MariaDB [mysql]> update user set plugin=” where user=’root’;

Query OK, 1 row affected (0.00 sec)

Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [mysql]> flush privileges;

Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> exit

Bye

通过执行脚本mysql_secure_installation进一步保护MariaDB。该脚本将询问一系列旨在保护MariaDB数据库的问题,例如:更改MySQL根密码,删除匿名用户,禁用远程root登录并删除测试数据库。确保您对所有问题回答,并为数据库根帐户提供一个强密码,以完全保护MySQL守护程序,如下面的脚本输出摘录所示。

mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we’ll need the current
password for the root user.  If you’ve just installed MariaDB, and
you haven’t set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on…
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
You already have a root password set, so you can safely answer ‘n’.

Change the root password? [Y/n] y

New password:
Re-enter new password:
Password updated successfully!

Reloading privilege tables..
… Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y

 … Success!

Normally, root should only be allowed to connect from ‘localhost’.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y

 … Success!

By default, MariaDB comes with a database named ‘test’ that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y

 – Dropping test database…

 … Success!

 – Removing privileges on test database…

 … Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y

 … Success!

Cleaning up…

All done!  If you’ve completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB! 

为了测试MariaDB安全性,请尝试通过控制台登录数据库,而不要输入root帐户密码。如果没有为根帐户提供密码,则应拒绝对数据库的访问,如以下命令摘录所示:

mysql -h localhost -u root

ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: NO)

如果提供了密码,则应该授予登录过程,并且您应该能够登录到MySQL控制台,如以下命令示例所示。键入退出为了离开数据库。

mysql -h localhost -u root -p

Enter password:

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 15
Server version: 10.1.26-MariaDB-0+deb9u1 Debian 9.1
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

MariaDB [(none)]> exit

Bye

安装OroCRM

在实际开始安装OroCRM之前,我们将安装一些实用程序,从Internet下载文件并解压缩zip存档。

apt install wget zip unzip curl

访问GitHub上的OroCRM下载页面并获取最新的zip存档。我将在此处使用OroCRM 2.6。在wget命令,下载OroCRM:

cd /tmp
wget https://github.com/oroinc/crm-application/archive/2.6.0.zip

压缩文件下载完成后,将归档文件提取到当前工作目录中,并通过以下命令列出提取的文件。另外,将Apache Web服务器安装到webroot路径的默认index.html文件删除,并删除之前创建的info.php文件。

解压缩zip归档文件:

unzip 2.6.0.zip

列出解压缩的文件:

ls

删除默认的索引文件和info.php文件。

rm /var/www/html/index.html


 rm /var/www/html/web/info.php

OroCRM的安装文件位于您当前的工作目录中,也就是crm-application-2.6.0/的子目录。通过执行以下命令,将子目录中的文件和文件夹复制到Web服务器文档的根路径。

cp -rf crm-application-2.6.0 /* /var /www /html/

接下来,转到webroot路径,并通过执行以下命令为PHP安装Composer依赖性管理器。

cd /var/www/html/

curl -sS https://getcomposer.org/installer | PHP

All settings correct for using Composer
Downloading…
….
Composer (version 1.5.5) successfully installed to: /var/www/html/composer.phar

Use it: php composer.phar 

在服务器上安装Composer之后,通过执行以下命令,通过Composer脚本安装OroCRM依赖项。

php7.0 composer.phar install –prefer-dist –no-dev

该脚本将要求输入应用程序的配置参数,以引导OroCRM。只需按[enter]键继续即可(使用默认值)。

接下来,通过执行以下命令,确保将Composer $ HOME路径行插入.htaccess托管应用程序的Web目录中。

echo ‘SetEnv COMPOSER_HOME “/var/www/html” ‘ >> /var/www/html/web/.htaccess

现在执行以下命令,以向Apache运行时用户授予对应用程序Web、应用程序、缓存目录的完全写权限。


chown -R www-data:www-data /var /www /html /web /
chown -R www-data:www-data /var /www /html /app /
chown -R www-data:www-data /var /www /html /cache /

该应用程序的配置文件是parameters.yml在/var /www /html/app/config/路径下。

登录到MariaDB数据库控制台,并为oroCRM和具有密码的用户创建一个数据库来管理OroCRM数据库。相应地替换数据库名称,用户和密码。

mysql –u root -p

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 2

Server version: 10.1.26-MariaDB-0+deb9u1 Debian 9.1

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

MariaDB [(none)]> create database mycrm_db;

Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> grant all privileges on mycrm_db.* to ‘crm_user’@’localhost’ identified by ‘password1234’;

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> exit

Bye

现在,让我们通过网络界面开始OroCRM安装过程。打开浏览器,然后通过HTTPS协议导航到您的域名或服务器IP地址。

 

在第一个安装屏幕上,OroCRM安装程序向导将显示一个欢迎屏幕。点击开始安装 按钮以启动设置过程。

Start the OroCRM installation

Start the OroCRM installation

在下一个屏幕上,安装程序将检查您的系统要求。如果通过了所有系统和PHP要求,如下图所示,请单击“下一步”按钮转到下一步。

Check system requirements

Check system requirements

System requirements - part 2

System requirements - part 2

在下一个屏幕上,添加数据库连接设置。选择MySQL驱动程序,为数据库主机输入127.0.0.1,为MySQL端口输入3306,然后添加先前配置的数据库名称,用户和密码设置。为“删除数据库”选项选择“无”。

然后,转到Mailer设置并添加您自己的邮件服务器SMTP配置。如果在同一节点上运行本地邮件服务器,请在SMTP服务器主机字段中添加127.0.0.1。

然后,转到“系统设置”,为OroCRM选择“语言环境”设置,并将“Secret”保留为应用程序安装程序生成的默认密钥。最后,将WebSocket连接保留为默认设置,然后单击“下一步”按钮继续安装过程。

Database and system configuration

Database and system configuration

在下一个屏幕上,等待MySQL数据库架构初始化,然后单击下一个按钮移至下一步。

Database initialization

Database initialization

接下来,在OroCRM组织名称中设置一个名称,提供您的应用程序URL地址和具有强密码的管理员帐户。另外,添加管理员帐户的电子邮件地址以及管理员帐户的名字和姓氏。最后,取消选中加载样品数据,并点击“安装”按钮以开始OroCRM安装过程。

Administration setup

Administration setup

等待安装过程完成并继续下一个按钮以完成安装过程,并移至最后一个向导屏幕。

Installation finished

Installation finished

安装过程完成后,安装程序将显示最终安装屏幕,并通知您安装过程已完成。在这里,只需单击启动应用程序按钮即可重定向到OroCRM登录屏幕。

Launch OroCRM application

Launch OroCRM application

为了登录到OroCRM平台,请在安装过程中使用为admin帐户配置的凭据,如以下屏幕截图所示。

Login to OroCRM

Login to OroCRM

您将被重定向到OroCRM默认仪表板,如下图所示。现在,您可以开始管理您的CRM平台了。

OroCRM Dashboard

OroCRM Dashboard

最后,为了迫使访问者通过HTTPS协议安全地访问CRM应用,请返回服务器的终端并通过发出以下命令编辑OroCRM的.htaccess,将其放置在您的网站文档根路径中的文件。

nano /var/www/html/web/.htaccess

在这里,在RewriteEgine On下面添加以下行自动将应用程序客户端重定向到HTTPS。

# Redirect to HTTPS
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L]

您还可以在.htaccess文件的末尾添加一些新行,以修改本机PHP服务器设置on-fly,例如文件上传大小。确保下面显示的PHP设置与您自己的服务器资源匹配。

# PHP settings alteration
php_value upload_max_filesize 100M
php_value post_max_size 100M

为了自动执行OroCRM管理任务,请添加以下cron作业拥有的Apache运行时用户。

crontab –u www-data –e

crontab文件摘录:

*/5 * *  *  *  /usr/bin/php7.0   /var/www/html/app/console oro:cron --env=prod > /dev/null
# Run maintenance tasks by executing MessageQueueComponent and MessageQueueBundle asynchronously.
*/5 * *  *  *  /usr/bin/php7.0   /var/www/html/app/console oro:message-queue:consume --env=prod > /dev/null

恭喜! OroCRM平台已成功部署在您的Debian 9服务器上。请在以下地址查阅OroCRM文档页面:https://oroinc.com/orocrm/doc/current,为了进一步配置您的CRM平台。

参考资料

本文由《纯净天空》出品。文章地址: https://vimsky.com/article/4223.html,未经允许,请勿转载。