Currently Browsing: Apache

Limit Apache gzip deflate to certain files

Particularly useful if you have some other server-side process that already compresses files and/or are using nginx or similar to compress some files, this technique can be used to pick up any one-offs or static files that you want to compress prior to caching, e.g., via Varnish, which supports gzip’d files but doesn’t do the compression.

1
2
3
<Directory "/PATH/TO/STATIC/ASSETS">
	AddOutputFilterByType DEFLATE text/css text/javascript application/javascript
</Directory>

Post-Mac Mavericks install tasks

stuff I needed to do in order to restore some functionality once updating to Mavericks.

(Uses native apache/php with homebrew supplements, no MAMP or similar packages required.)

here we go:


* update .bash_profile in ~/
# Set architecture flags
export ARCHFLAGS="-arch x86_64"
# Ensure user-installed binaries take precedence
export PATH=/usr/local/bin:$PATH
# Load .bashrc if it exists
test -f ~/.bashrc && source ~/.bashrc

$ xcode-select --install

* You will then be asked whether you want to install Xcode or 
    the command line developer tools, with the latter being the default.

* install Homebrew:
$ ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go/install)"

* install some utils:
$ brew install bash-completion ssh-copy-id wget

* install mysq
$ brew install mysql --enable-local-infile

# To have launchd start mysql at login:
#    $ ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
# Then to load mysql now:
#   $ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
# Or, if you don't want/need launchctl, you can just run:
#   $ mysql.server start
#
#   $ mysql_secure_installation

$ sudo mkdir /var/mysql
$ sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

* php myadmin:
$ brew tap homebrew/dupes
$ brew tap josegonzalez/homebrew-php
$ brew install phpmyadmin

$ sudo cp /usr/local/share/phpmyadmin/config.sample.inc.php \ 
    /usr/local/share/phpmyadmin/config.inc.php

* PHP
#  no problems as of yet. was able to compile extensions with brew and link those
#  to the native Apache/PHP setup via php.ini
$ sudo cp /etc/php.ini.default /etc/php.ini
    # and merge previous php.ini
# Zend Opcache seems to be more stable than APC:
$ brew install php54-opcache
    # copy/link .so file and update php.ini

* redis:
$ brew install redis
* phpredis:
$ brew install php54-redis
    # copy/link .so file and update php.ini

* Apache
#  was generally fine, might need to change some perms, particularly if
#  putting web directories under your home folder, e.g., Dropbox.
#  this fixed that: (you could update your groups theoretically to avoid
#  setting the search (+x) permission for "other".
$ sudo chmod -R g+x Dropbox/
$ sudo chmod -R o+x Dropbox/

Fix apache www root permissions on mac users’ directories

If you put a web directory within your home directory on a mac (“/Users/name”) you can often run into permission problems that can be a bit mysterious. To fix this w/out compromising security, try:

For each parent directory leading to your web root (e.g. ~/my, ~/my/web, ~/my/web/root):

chmod go-rwx DIR (nobody other than owner can access content)
chmod go+x DIR (to allow "users" including _www to "enter" the dir)
sudo chgrp -R _www ~/my/web/root (all web content is now group _www)
chmod -R go-rwx ~/my/web/root (nobody other than owner can access web content)
chmod -R g+rx ~/my/web/root (all web content is now readable/executable/enterable by _www)

(thanks @dkamins)

Prevent extension version issues using PECL with multiple PHP installs

Simply calling phpize, config and make to compile a new extension, even if you point directly to your php binary can still compile with the wrong version as can installing via PECL, even if you reference the pecl binary directly. Using the peclcmd.php script, however, you should be able to get it to load the correct libraries and install in the right place.

For instance, I recently installed PHP 5.4 in /usr/local/php5 to use instead of the native Mac PHP 5.3 install (via http://php-osx.liip.ch/) but I wanted to leave the Mac PHP in place so now I have multiple versions of PHP and can use either one, which is great for dev but can cause compile issues.

On one machine I was eventually able to manually download the extension via pecl download and then phpize and install by passing: ./configure --with-php-config=/usr/local/php5/bin/php-config to the build config but wasn’t able to figure out how to do this directly via pecl. When I next tried the same update to another machine, I remembered the peclcmd file and was able to simply use a single command: /usr/local/php5/bin/php /usr/local/php5/lib/php/peclcmd.php install {extension-name} and done.

Ymmv :)

While I’m comfortable compiling from scratch, it definitely can save a lot of headaches to use a packager if it gives you what you need and make updates a lot easier.

Set timezone in Tomcat

in bin/catalina.sh set:

CATALINA_OPTS=-Duser.timezone=America/New_York

catalina.sh file does say to use a setenv.sh script instead of editing the file, but I just put the above command at the top of the catalina.sh file and it was fine.

see java timezone names here

« Previous Entries Next Entries »