Wednesday, November 19, 2014

Tech: Quick Start Apache Server w/ PHP on OSX Mavericks

1. Set up the built-in Apache server to enable PHP
$ sudo cp /private/etc/apache2/httpd.conf /private/etc/apache2/httpd.conf.pre-php-enable
$ sudo sed -e 's/^#\(LoadModule php5_module.*\)/\1/' /private/etc/apache2/httpd.conf.pre-php-enable > /private/etc/apache2/httpd.conf
2. Create a useable version of the PHP ini file
$ sudo cp /private/etc/php.ini.default /private/etc/php.ini
3. Create a user-specific Apache config file
$ sudo echo '
<Directory "/Users/$LOGNAME/Sites/">
Options Indexes Multiviews
AllowOverride AuthConfig Limit
Order allow,deny
Allow from all
</Directory>
' > /etc/apache2/users/$LOGNAME.conf
4. Start the server
$ sudo apachectl start
5. Create a test file
$ echo 'echo "Hello World!";?>' > $HOME/Sites/hw.php
6. Validate everything is working
$ curl http://localhost/~$LOGNAME/hw.php
Hello World!
7. Launch Xcode to do more interesting edits
$ open -a /Applications/Xcode.app $HOME/Sites/hw.php

 Biblio: