Wednesday, March 11, 2020

Sugar 9 Development on a macOS Catalina

I am going to review one possible method to setup macOS for Sugar development, this is my preferred setup. I have chosen not to leverage Vagrant, VirtualBox, Docker or other virtual machines. I develop using this configuration because I can be working on as many as 15 different clients’ Sugar customizations in addition to Sugar Add-Ons such as Sugar Messaging, Sugar Slack, Sugar Google Address Lookup and Sugar Mapping. This configuration affords me the flexibility to quickly switch between instances as well as give access to testers.

My toolbox is filled with a variety of different tools including HomeBrew, PhpStorm, BBEdit, phpMyAdmin, ngrok, Postman, as well as a number of homegrown command-line tools that we will discuss in a future blog post.

As a company, we utilize Atlassian products such as Jira, Confluence, and BitBucket. For development purposes, the most important product from Atlassian is BitBucket. This is our version control system and it leverages git as it’s the underlying technology. I can not stress enough you need to manage all your work with some type of version control system. Using version control has saved me more times than I can count.

macOS Setup

I am writing this using macOS Catalina 10.15.3. This is the most current macOS available. macOS Catalina was released on October 7, 2019. Apple includes PHP and Apache as part of macOS, but we are not going to utilize their versions. The primary reason for this is that using the stock packages that come with macOS is that Apple makes changes to the configuration of these packages while performing OS updates.

To get started we are going to need to install Xcode. Xcode will provide us with command-line tools such as git and it will include all of the developer tools required by HomeBrew. Follow the link which will open the App Store for you to download and install Xcode. Be forewarned, Xcode is a pretty big app and may take a bit of time to download and install.

Please note, I reference vi in my instructions below, but you can substitute vi with any text editor of your choosing. One thing to be aware of, some of the directories where files are installed are not visible to the Finder out of the box.

Apache, MySQL, PHP, and Elasticsearch

As mentioned previously, we want to install our own version of Apache and PHP and we also want to conform to Sugar 9.0.x Supported Platforms.

We will use Homebrew to install our software packages. Let’s get started by installing Homebrew.

Open a macOS Terminal window

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

ensure that brew is ready

brew doctor

you can find packages to install by using the command

brew search

for example

brew search php

==> Formulae
brew-php-switcher        php-code-sniffer       php@7.2        phplint       phpmyadmin       phpunit
php                      php-cs-fixer           php@7.3        phpmd         phpstan
   
==> Casks
homebrew/cask/eclipse-php                                         homebrew/cask/netbeans-php

Apache

brew install apache2

Once Apache has been installed, the configuration files are located at /usr/local/etc/httpd/. In order to ensure that SugarCRM is running correctly, we need to make some changes.

vi /usr/local/etc/httpd/httpd.conf

Uncomment
LoadModule rewrite_module libexec/mod_rewrite.so

I prefer to store my website files in the Sites directory of my user
/Users/bickart/Sites. You can make these adjustments to meet your needs.

I have changed the DocumentRoot from
DocumentRoot "/usr/local/var/www"
<Directory "/usr/local/var/www">

to be

DocumentRoot "/Users/bickart/Sites"
<Directory "/Users/bickart/Sites">

within the <Directory tag, I have also changed 
AllowOverride none to be AllowOverride All

AllowOverride All will allow the Apache to access the .htaccess file
that will be used by Sugar.

You can restart Apache with the command
apachectl restart 

MySQL

brew install mysql@5.7

now that MySQL has been installed we want to ensure we give the MySQL a password

mysql_secure_installation

be sure to make note of your root password

Sugar 9 uses utf8mb4 as the default charset; so we can adjust the mysql configuration to set this as the default

vi /usr/local/etc/my.cnf 

in the [mysqld] section we are going to add
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci

I also like to change the prompt in mysql so that I know which DB that I’m using; you can do this by

vi ~/.my.cnf 

Then add
[mysql]
prompt="mysql [\\d]> "

which will give you a prompt like
mysql [db_slack]> 

PHP 7.3

Sugar 9 supports both PHP 7.1 and PHP 7.3. In order to make our development environment last a bit longer, we are will install PHP 7.3

brew install php@7.3

As a Sugar developer, it is a great idea to also ensure that we have xdebug installed.

pecl install xdebug

We need to make some adjustments to our PHP configuration to meet the guidelines in Sugar Enterprise 9.0 Installation and Upgrade Guide. You can find all of the supported PHP timezones at https://www.php.net/manual/en/timezones.php.

vi /usr/local/etc/php/7.3/conf.d/ext-sugarcrm.ini

date.timezone=America/Los_Angeles #be sure to set to your timezone
max_execution_time=120
max_input_time=120
memory_limit=512M
post_max_size=100M
session.use_cookies=1
session.cookie_httponly=1
upload_max_filesize=100M

Now that we have PHP and Apache, we need to let Apache know how to use PHP. We are going to add a configuration for PHP

vi /usr/local/etc/httpd/extra/httpd-php.conf

LoadModule php7_module        /usr/local/Cellar/php@7.3/7.3.14/lib/httpd/modules/libphp7.so

<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

<IfModule dir_module>
   DirectoryIndex index.php index.html
</IfModule>

We also need to make an adjustment to the httpd.conf file so that Apache can find out changes.

vi /usr/local/etc/httpd/httpd.conf

There is a section in the file that has a set of extra file. We need to add our 
extra file to be included in the configuration

#PHP
Include /usr/local/etc/httpd/extra/httpd-php.conf

apachectl restart

Elasticsearch

Elasticsearch is also a required component of running and installing Sugar. As indicated in Sugar 9.0.x Supported Platforms, there are a number of different versions of Elasticearch that Sugar supports. To future proof our environment for as long as possible, we will install ElasticSearch 6.8.6 which is the default version available via brew at the time of this writing.

brew cask install homebrew/cask-versions/adoptopenjdk8
brew install elasticsearch

Summary

We have set up all of the tools needed, Xcode, HomeBrew, Apache, MySQL, and PHP for Sugar 9 development on macOS Catalina. We discussed some of the applications that I used for my daily development including PhpStorm, ngrok and git. In the future, we will talk about installing Sugar both via the browser and from the command line.

A note about xdebug, I had you install it but I didn’t explain how we are going to be using it. We will walk through using PhpStorm, Sugar command-line debugging, using Postman as well as using your browser to debug in a future post.

Until next time,

Jeff
https://www.linkedin.com/in/bickart/

About Me

I’m a Mac 😀. I have been since I worked at the University of Pittsburgh computer store and saw a Mac Plus for the first time. I have been an employee of Apple Computer, Inc. and a contractor for Apple, Inc. Over my career, I have only used Microsoft operations system computers for a couple of years.

I have been a Sugar Developer since sometime in 2005 which would be Sugar Sales Suite 3.5. I was brought into a startup as the director of engineering. True story; the company became funded based upon a drawing on a napkin. When I arrived, a proof of concept had been built by the CTO and his concept needed to be fully built out. The product launched as 360° Care viaVisitar which was a multi-tenant version of Sugar 4.0a integrated with a custom call controller with deep integrations Asterisk and OpenRules.

Acknowledgments

I want to thank Mathew Poer for helping me while writing this blog. His insight and answering all of my questions really helped shape this post.

The post Sugar 9 Development on a macOS Catalina appeared first on FayeBSG.

No comments:

Post a Comment