Set Up A Local Development Environment For Mac

Posted : admin On 18.10.2019
Download
  1. Set Up A Local Development Environment For Mac 2017

Using a local dev environment is standard practice, and yet, getting a stack that is easy to set up and use is still a challenge. If you’re using a Mac, many tutorials recommend building the development environment, since Apache is bundled with macOS.

A beginner's guide to setting up a development environment on Mac OS X. Cd /usr/local $ git fetch origin $ git reset --hard origin/master. To see if any of your.

Adding a few elements seems easy, after all, a local development environment for PHP includes at minimum two things:. A web server configured to compile and run your PHP scripts on the fly and serve them to your browser.

A database server to pull data and render it in your PHP application. However, that isn’t enough in most cases. You may also want to make it easier to manage and test your application, so you would also need:.

SSH access. An email catch-all. And what about local SSL support?. Virtual hosts to easily access your works-in-progress in your browser. To set these up, even for one site, you’re looking at some detailed configuration.

If you were just managing ONE site, it wouldn’t be a problem. However, to make it easier to add and manage multiple sites, you might also want:. A way to start and stop services. Some way to manage those databases, like PHPMyAdmin. Configuring specific versions of your PHP projects. A way to manage custom environment variables. And once you starting adding all of those packages to manage these, you need some way to manage them and keep them up to date.

And what if you want to add new projects without repeating the same setup each time? This is why Docker containers have gotten more popular in the last few years. When it comes to lightweight local development. Docker containers are faster and they don’t consume a lot of resources. With Docker Compose, you can manage different packages and dependencies. For example, you can set up different PHP environments per project, or add services like Apache Solr.

The main issue with Docker? That is a lot to manage and maintain and takes considerable knowledge of Docker to set up. There have been many local development tools released which package up the tools you need, and make it work.

One of these options is. It comes with everything you need to create local development and quickly deploy to production. Here's a video tutorial showing you.

This gives you a complete PHP development environment with developer tools like:. MySQL Client (mysql) – Command-line interface for interacting with MySQL. Composer – Dependency Manager for PHP. Drush – Command-line shell and Unix scripting interface for Drupal.

WP-CLI – Command-line tools for managing WordPress installations. MailHog mail catcher for email capture and review. Read more about the.

Need any help? Post your questions tagged with.

Mac

This is an updated version of our prior OS X development series. The newly released macOS 10.14 Mojave and the accompanying updates to Brew require significant changes compared to prior releases, necessitating a thorough revamp in the process.

Since macOS 10.12 we now use Homebrew's Apache, rather than the built-in version, but this new appraoch is more flexible and should continue to work on prior OS X versions. In of this 3-part series, we covered configuring Apache on macOS to work better with your local user account, as well as the installation process for installing multiple versions of PHP. In this Part 2, we will cover installing MySQL, Virtual Hosts, APC caching, YAML, and Xdebug. After finishing this tutorial, be sure to check out. This guide is intended for experienced web developers.

Set Up A Local Development Environment For Mac

If you are a beginner developer, you will be better served using. MySQL Although not required for development of Grav, there are times you definitely need an installation of MySQL. In the original guide, we used the Oracle MySQL installation package.

However, we now have switched to which is a drop-in replacement for MySQL and is easily installed and updated with Brew. Detailed information on the HomeBrew installation process can be found on the but the essentials are as follows: Install MariaDB with Brew: $ brew update $ brew install mariadb After a successful installation, you can start the server ane ensure it autostarts in the future with: $ brew services start mariadb You should get some positive feedback on that action: Successfully started `mariadb` (label: homebrew.mxcl.mariadb) and install it. (it's awesome and free!). You should be able to automatically create a new connection via the Socket option without changing any settings. It is advisable to change the MySQL server password and secure your installation. The simplest way to do this is to use the provided script: $ /usr/local/bin/mysqlsecureinstallation Just answer the questions and fill them in as is appropriate for your environment.

If you need to stop the server, you can use the simple command: $ brew services stop mariadb Apache Virtual Hosts A very handy development option is to have multiple virtual hosts set up for you various projects. This means that you can set up names such as grav.mydomain.com which point to your Grav setup, or project-x.mydomain.com for a project-specific URL.

Apache generally performs name-based matching, so you don't need to configure multiple IP addresses. Detailed information can be found on the site. Apache already comes preconfigured to support this behavior but it is not enabled. First you will need to uncomment the following lines in your /usr/local/etc/httpd/httpd.conf file: LoadModule vhostaliasmodule lib/httpd/modules/modvhostalias.so and: # Virtual hosts Include /usr/local/etc/httpd/extra/httpd-vhosts.conf Then you can edit this referenced file and configure it to your needs: $ code /usr/local/etc/httpd/extra/httpd-vhosts.conf This file has some instructions already but the important thing to remember is that these rules are matched in order. When you set up virtual hosts, you will lose your older document root, so you will need to add back support for that first as a virtual host. DocumentRoot '/Users/youruser/Sites' ServerName localhost DocumentRoot '/Users/youruser/Sites/grav-admin' ServerName grav-admin.test As you set up your.test virtual hosts, you may receive a warning such as Warning: DocumentRoot /Users/youruser/Sites/grav-admin does not exist when restarting Apache.

This just lets you know that the source directory listed for your virtual hosts is not present on the drive. It's an issue that can be resolved by editing this file with the corrected DocumentRoot. We used to recommend using.dev domain name, but since Chrome 63 forces all.dev domains to use SSL, this guide has been updated to use.test In the example virtualhost we setup above, we defined a ServerName of grav-admin.test. This by default will not resolve to your local machine, but it's often very useful to be able to setup various virtual hosts for development purposes.

You can do this by manually adding entries to /etc/hosts ever time, or you can install and configure to automatically handle wildcard.test names and forward all of them to localhost ( 127.0.0.1). Answer any question by simply pressing Return to accept the default values Restart Apache with the standard sudo apachectl -k restart command to pick up your changes. Optional APCu Configuration This is probably enough for most people, but if you are like me and like a little more control over your settings, and also the ability to more easily enable/disable the extension, we have some extra optional steps. You will now need to remove the extension='apcu.so' entry that PECL adds to the top of your php.ini.

So edit this file and remove the top line: $ code /usr/local/etc/php/5.6/php.ini Once that line is removed, we can add a new file with a proper entry to the recently bulit apcu.so library: $ code /usr/local/etc/php/5.6/conf.d/ext-apcu.ini In this file paste the following: apcu extension='apcu.so' apc.enabled=1 apc.shmsize=64M apc.ttl=7200 apc.enablecli=1 Restart Apache with the standard sudo apachectl -k restart command to pick up your changes. APCu for other PHP versions For PHP 7.1 and above you can use the latest 5.x release of APCu, so the process is the same for all. First let's switch to PHP 7.1 and install the APCu library: $ sphp 7.1 $ pecl uninstall -r apcu $ pecl install apcu Restart Apache with the standard sudo apachectl -k restart command to pick up your changes.

Audio and video will remain synchronised and the entire process is extremely fast (depending upon the size of the file). If you have multiple files to convert this package enables you to modify them in batches ideal when a large number of documents needs to be sent to a friend or stored on an external hard drive. Any drm removal for mac high sierra.

Currently APCu is not compiling with PHP 7.3. I'll update this when that is working again. YAML With recent versions of Grav, we now make use of the native PECL YAML library that allow YAML processing to be done by highly efficient libYAML C library rather than by they Symfony PHP library. This can result in a 5X improvement in YAML processing times!

Luckily this is a simple process to install for any PHP version: Switch to PHP 5.6 mode, then run the following brew commands to install libyaml: $ sphp 5.6 $ brew install libyaml Then you can install. For PHP 5.6 we have to install the latest 1.3.x version of YAML, as this is the last version to provide PHP 5.6 support: $ pecl install yaml-1.3.1. Answer any question by simply pressing Return to accept the default values Restart Apache with the standard sudo apachectl -k restart command to pick up your changes. YAML for other PHP versions For PHP 7.1 and above you can use the latest 2.x release of YAML, so the process is the same for all. First let's switch to PHP 7.1 and install the YAML library: $ sphp 7.1 $ pecl uninstall -r yaml $ pecl install yaml Restart Apache with the standard sudo apachectl -k restart command to pick up your changes. The uninstall -r enables PECL to only remove registration, it does not actually uninstall anything. For PHP 7.2, just repeat these steps but use 7.2 instead of 7.1: $ sphp 7.2 $ pecl uninstall -r yaml $ pecl install yaml and for PHP 7.3: $ sphp 7.3 $ pecl uninstall -r yaml $ pecl install yaml Optional YAML Configuration If you are feeling adventurous, or you like to keep things uniform, you can follow the same procedure as APCu and remove the default extension-'yaml.so' entry in each PHP's php.ini and instead, create a conf.d/ext-yaml.ini file: yaml extension='yaml.so' Xdebug One of the most important aspects of any kind of development is the ability to debug and fix your code.

PHP comes with limited support to dump variables or log to a file, but for more complex situations you need something more powerful. Xdebug provides is a debugging and profiling extension for PHP that provides an HTML-friendly output for the vardump method that improves the readability of the default version. It also provides other useful dumping methods as well as displaying stack traces. One of the best features however, is the ability to remote debug your code.

This means you can set breakpoints, and step through your PHP code inspecting as you go. Contains extensive information about all the functionality available. Let's switch back to PHP 5.6 and get started. $ sphp 5.6 Then you can install. For PHP 5.6 we have to install the latest 2.5.x version of Xdebug, as this is the last version to provide PHP 5.6 support: $ pecl install xdebug-2.5.5 Required Xdebug Configuration Like the other PECL-installed modules, this will create a simple entry in the php.ini file, but you really need to configure Xdebug for it to be useful. So let's just go ahead and create our configuration file as we'll need it shortly anyway.

You will now need to remove the zendextension='xdebug.so' entry that PECL adds to the top of your php.ini. So edit this file and remove the top line: $ code /usr/local/etc/php/5.6/php.ini Once that line is removed, we can add a new file with a proper entry to the recently bulit xdebug.so library: $ code /usr/local/etc/php/5.6/conf.d/ext-xdebug.ini In this file paste the following: xdebug zendextension='xdebug.so' xdebug.remoteenable=1 xdebug.remotehost=localhost xdebug.remotehandler=dbgp xdebug.remoteport=9000 Restart Apache with the standard sudo apachectl -k restart command to pick up your changes. You should check the to ensure that Xdebug information is displayed: for quickly enabling/disabling xdebug. Install this with brew: $ curl -L /usr/local/bin/xdebug $ chmod +x /usr/local/bin/xdebug Using it is simple, you can get the current state with: $ xdebug And then turn it on or off with: $ xdebug on $ xdebug off. If Xdebug still shows up in php -v the most likely cause is you didn't remove the zendextension='xdebug.so' entry at the top of php.ini Xdebug for other PHP versions For PHP 7.1 and above you can use the latest 1.6.x release of Xdebug, so the process is the same for all. First let's switch to PHP 7.1 and install the Xdebug library: $ sphp 7.1 $ pecl uninstall -r xdebug $ pecl install xdebug Afer this just repeat the Required Xdebug Configuration steps, with /usr/local/etc/php/7.1/php.ini as the PHP configuration file to remove the existing entry, and /usr/local/etc/php/7.1/conf.d/ext-xdebug.ini for the file you will create with the new Xdebug configuration.

Set Up A Local Development Environment For Mac 2017

Restart Apache with the standard sudo apachectl -k restart command to pick up your changes. For PHP 7.2, just repeat these steps but use 7.1 instead of 7.1: $ sphp 7.2 $ pecl uninstall -r xdebug $ pecl install xdebug Again, repeat the Required Xdebug Configuration steps with the same info you used for 7.1 except use 7.2 For PHP 7.3, repeat these steps again and the latest beta of xdebug: $ sphp 7.3 $ pecl uninstall -r xdebug $ pecl install xdebug-2.7.0beta1 Advanced Techniques Here's a hot tip if you have done this before and want to speed-up the installation process. Simply install everything ( apcu, yaml, xdebug) in one shot, and then perform the other non-installation steps. This is faster but less intuitive for newbies: PHP 5.6 $ pecl install apcu-4.0.11 && pecl install yaml-1.3.1 && pecl install xdebug-2.5.5 PHP 7.1+ Repeat the following 2 steps for PHP 7.1 through PHP 7.3: $ sphp 7.1 $ pecl uninstall -r apcu && pecl install apcu && pecl uninstall -r yaml && pecl install yaml && pecl uninstall -r xdebug && pecl install xdebug Once you have created your configruation ( conf.d/ext-lbirary.ini) files, you can also easily copy the configuration files from one version of PHP to another.

$ cd /usr/local/php/5.6/conf.d $ cp ext-apcu.ini ext-xdebug.ini ext-yaml.ini././7.1/conf.d $ cp ext-apcu.ini ext-xdebug.ini ext-yaml.ini././7.2/conf.d $ cp ext-apcu.ini ext-xdebug.ini ext-yaml.ini././7.3/conf.d You should now be all set with a Rockin' PHP development environment! To find out how to enable SSL on Apache, check out. As promised, today I'm going to start covering the process of setting up a development environment utilizing GitHub to manage the code throughout the development life cycle, resulting in publishing to a live site. As I, as a web developer, the most efficient and more reliable development strategy is to develop locally, then push your local development to your production site.

If you have not ready my post on, you might want to read that first. Over the course of this two-part series, we will cover the process from start to finish, and I hope to show you that this process is one that will enable you to develop and maintain your site more efficiently. So, you’ve decided to get Grav and build a site with it. Building with Grav gives you the power and flexibility you need to realize your site but you need to develop that site first. Using an efficient development strategy will allow you to build your site faster and hassle-free. You might even have fun while doing it!

When you look at how easy it is to set Grav up and get it running on a remote server, it can be very tempting to just do development there, especially given the fact that there are no databases to migrate over, and everything is file-based. However, don't be tempted by this approach!

In this blog post I'll endeavor to explain why.