Restarting httpd (Apache 2 web server) after a kernel panic or sudden shutdown

Type this in Terminal:

`rm /usr/local/var/run/httpd/httpd.pid`

It applies to httpd provided by [Homebrew](https://brew.sh). It seem to happen because the [pid file](https://stackoverflow.com/q/8296170/1092853) doens’t get cleaned up after a sudden shutdown. If you try to restart httpd you might get a message like `httpd (pid 103) already running` but the process with id 103 (for example) is totally unrelated.

Apache and PHP-FPM via Homebrew on macOS

I like to keep my development environment lean, running Apache and PHP-FPM on my MacBook Pro without MAMP or similar. Even tools like Vagrant, while great, for many feel more like an hassle.

I try to mimic as much as possible the staging or production environments I use, that’s why I avoid the simple way of using the PHP module for Apache. Instead, the better way to go is to setup PHP-FPM.

Since I mentioned that I’m using macOS, the best way to install system software is Homebrew. Over the years the ecosystem has routinely changed though, especially with macOS updates. Until some time ago, I was able to tap homebrew-apache and among other things install fastcgi_module, and configure PHP via a “FastCgiExternalServer” directive, but that became an unviable solution.

I’m writing down here what I believe it’s a stable solution going forward, both for personal reference and for anyone that wants to use Apache (on port 80 instead of 8080) running with PHP-FPM on macOS Sierra or higher (probably also El Capitan, I haven’t tested yet).

Instructions

1. Install Homebrew, then run $ brew tap homebrew/homebrew-php

2. $ brew install httpd
Install Apache. The caveats will tell you that DocumentRoot is /usr/local/var/www and that the default ports are 8080 and 8443, but it’s easy to use ~/Sites and port 80 and 443 if you’d prefer. Read more for details.

3. brew install php70 –with-homebrew-curl
Install PHP 7.0. Of course you can choose another version of PHP, for example PHP 7.1 or later, or PHP 5.6 or earlier if necessary. Here I advise to build from source by including curl, instead of using the pre-built bottle. curl is a requirement for mostly everybody, and unless that’s not the case for you, you can skip the parameter “–with-homebrew-curl”.

4. $ brew install php70-imagick php70-intl php70-mcrypt php70-opcache php70-xdebug # (optional step)
Just like curl above, these are some PHP modules that are generally useful but not always necessary. Feel free to skip unless you also need them.

5. Download this httpd vhost configuration file — I linked to a specific commit to avoid link breakage, check the master branch for possible updates.

In this file, right at the beginning, there are some indications about the changes to Apache configuration files and to FPM pool configuration for proper setup.
In short you need to edit the Apache configuration file /usr/local/etc/httpd/httpd.conf by adding a line with the path of configuration file linked above. Then, to keep PHP running as your user (to avoid permissions and ownership headaches) you need to change the PHP configuration file /usr/local/etc/php/7.x/php-fpm.d/www.conf (make sure you replace the x with your actual PHP version) by replacing “_www” with your username and the “staff” group name.

6. Lastly, use brew services to start Apache and PHP-FPM. This makes it super-easy to get up and running and to enable the webserver at system startup, since brew services will take care of placing the correct plist files in the right folders for launchd. NB: for httpd (Apache) perform brew services operations with sudo. This will allow you to use port 80 and 443 with your web server.
Example: $ sudo brew services restart httpd && brew services restart php70

Conclusions

The “secret” to make PHP-FPM work with Apache 2.4 is to use the following directive:

<FilesMatch .php$>
    SetHandler proxy:fcgi://localhost:9000
</FilesMatch>

Of course you need to make sure that PHP-FPM is running on that port, which is configured in the file /usr/local/etc/php/7.x/php-fpm.d/www.conf at the listen directive. Port 9000 is the default.

One bonus of using the Apache configuration file I prepared is that you get “Automatic .dev Virtual Hosts”. If you setup your ~/Sites/ folder as the web server root directory, any directory that you create in it will be treated as a website ending in the .dev TLD. To make it work you need to add lines to your /etc/hosts file, for example: 127.0.0.1    wordpress.dev. You could make it completely dynamic and automatic with the use of dnsmasq (which is also available on Homebrew) but that’s a bit too much for this post.

That’s it! Now you can rock a lean setup with close-to-stock Apache and PHP-FPM with minimal modification to core configuration files, and with the advantage of using FPM instead of the PHP Apache module.

littlebigdetails:
“ Apple - The CSS class for legal fine print on Apple product pages is “Sosumi.”
Example
More info
”
See this for reference.

littlebigdetails:

Apple - The CSS class for legal fine print on Apple product pages is “Sosumi.” 

Example

More info

See this for reference.

(via littlebigdetails)

An essential utility… avoid auto-play if on background tab and force preload of entire video. Download menu and a bunch of goodies also.

"Small plates are offered to encourage smaller portions and less waste. Fruit and water are placed at eye level but you have to bend down for sugary drinks. All of this is data driven."

Inside Google HQ: What does the future hold for the company whose visionary plans include implanting a chip in our brains? - Features - Gadgets & Tech - The Independent

Tags: Google

“ Sequel Pro is a fast, easy-to-use Mac database management application for working with MySQL databases.
”
I love it and use it, whenever I need it.

Sequel Pro is a fast, easy-to-use Mac database management application for working with MySQL databases.

I love it and use it, whenever I need it.

(via onethingwell)

I knew about `set show-all-if-ambiguous on`, but the rest really bring some magic to the good ol’ Bash.

I hope this works for you, if you bump into smb problems where the WINS workgroup and NetBIOS name are reset or disappear at reboot.