July 04, 2015

Yosemite Eclipsed?!

♬ Total Eclipse of Yosemite  . To quote an old Pink Floyd song. Or was that total eclipse of the moon? Anyway, now that we have PHP, Apache, and SVN installed, it's time we setup a programming IDE that can utilise these tools.

Download Eclipse PHP Edition, more specifically the Mac tarball. Extract it to your applications folder:

# tar -xzvf ~/Downloads/eclipse-php-mars-R-macosx-cocoa-x86_64.tar.gz -C /applications/

This will install the Eclipse IDE in your Application folder, making it clickable using F4 to select the applications. To get xdebug rolling follow this guide.

July 02, 2015

SVN in Yosemite

If you intend to code in Yosemite, you're bound to need a source control system. I'm using svn, its old and i know it, but I'm quite fond of the old chap. The easiest way to get it there is by using MacPorts.

# sudo port selfupdate
# sudo port install sqlite3 apr-util neon subversion

It's verified by issuing:

# svn 

in you terminal. You're now ready to use the source control system for your own programming projects.

MySQL in Yosemite



This is the second article on marvellous Yosemite. This time we're installing and configuring MySQL.

Download MySQL and run the pkg installer, there's an issue the MySQL LaunchDeamon script, so if the installation fails it's ok the files are there, but the MySQL deamon could not be added. To add the MySQL deamon to launchctl the LaunceDeamon file needs to be created.

# echo "<!--?xml version="1.0" encoding="UTF-8"?-->
<plist version="1.0">
  <dict>
    <key>KeepAlive</key>
    <true />
    <key>Label</key>
    <string>com.mysql.mysqld</string>
    <key>ProgramArguments</key>
    <array>
      <string>/usr/local/mysql/bin/mysqld_safe</string>
      <string>--user=mysql</string>
    </array>        
  </dict>
</plist>" | sudo tee /Library/LaunchDaemons/com.mysql.mysql.plist 

Once you have your file created, you'll need to set the file premissions, like we did for apache, and add the file to the launch deamon.

# sudo chown root:wheel /Library/LaunchDaemons/com.mysql.mysql.plist 
# sudo chmod 644 /Library/LaunchDaemons/com.mysql.mysql.plist 
# sudo launchctl -w /Library/LaunchDaemons/com.mysql.mysql.plist 

There are some socket logging issues that needs to be fixed, apparently a file is missing the /var folder. 

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

Next, you'll need to add the MySQL to your bash environment

# echo 'export PATH="/usr/local/mysql/bin:$PATH"' > ~/.bash_profile

Or you could add it to your bashrc file using >> ~/.bashrc its up to you. Then source the MySQL environment into your environment. This environment should be set at every log on via your .bash_profile file. To verify the environment type:

# mysql -v

You quit the MySQL shell using \q (escaped q). To setup the MTSQL root users password type:

# mysqladmin -u root password 'thepasswordyoulike'

You should now be able to run MySQL from your command line.

Apache in Yosemite?

Sounds like a cool trip to those ginormous trees dosen't it? And you may even see a native american while you're there. Well it is some kinda field trip, except you dont get to go to Yosemite. But you get to update your Mac to Yosemite.

So, if you haven't already updated your MacBook Pro to the latest OSX, get on with it lad. The following describes how to setup apache in a freshly baked OS-X 10.10.xx setup.

The apache webserver and php is already installed in Yosemite, it's just not setup to support 'users' sites. The webserver root directory of apache is present at:

# ls /Library/WebServer/Documents/

If you want to know your apache version type: 

# apachectl -v

To start, restart or stop, apache you use the apachectl command, i.e. 

# apachectl start
# apachectl restart
# apachectl stop

But prior to starting the web server you should configure the server for user Sites. We'd like to setup the 'old' Sites folder support, which now no longer can be done from the GUI, unless you view the shell as a GUI (I know I do).

You'll need to create a folder called 'Sites' in your home directory. This folder will serve as the web root for your source code, and allow you to access your files in a browser or eclipse, using the http://localhost/~username/ URL.

# mkdir ~/Sites
# echo "<Directory \"/Users/$USER/Sites\">
AllowOverride All
Options Indexes MultiViews FollowSymLinks
Require all granted
</Directory>" | tee sudo /etc/apache2/users/`whoami`.conf
# sudo chown root:wheel /etc/apache2/users/`whoami`.conf
# sudo chmod 644 /etc/apache2/users/`whoami`.conf

The above commands gives you a folder named 'Sites' in our user accounts home directory, and adds the 'users' configuration to the apache server. Next, we'll configure the apache to use the 'users' folder when it runs.

Open the apache configuration file in an editor as superuser (root) and uncomment the following configuration lines. I use emacs, but pico, nano or any other editor is just as good.

# sudo emacs /etc/apache/httpd.conf  

LoadModule authz_user_module libexec/apache2/mod_authz_user.so
LoadModule authz_host_module libexec/apache2/mod_authz_host.so
LoadModule userdir_module libexec/apache2/mod_userdir.so
LoadModule php5_module libexec/apache2/libphp5.so
Include /private/etc/apache2/extra/httpd-userdir.conf

Save the file and exit the editor. Then, open the apaches 'users' configuration file and uncomment the line 

Include /private/etc/apache2/users/*.conf

Save and exit, and your apache server will be ready to rock, with user dir and php support. To verify that the changes work you'll need to restart the apache http deamon.

# sudo apachectl restart
# curl http://localhost

the curl command should echo the contents of the apache servers index.html file, so after the command has run you should see:

<html><body><h1>It works!</h1></body></html>

To verify the userdir configuration you'll need the curl redirect option and an index.html file to check against.

# echo "<html><body><h1>$USER</h1></body></html>" > ~/Sites/index.html
# curl -L http://localhost/~`whoami`

The curl command should dump the file you created above, where $USER has been replaced with your user account name. 

To verify that PHP runs, you can create a simple php file in your ~/Sites folder:

# echo "<?php echo phpversion(); ?>" > ~/Sites/index.php
curl -L http://localhost/~`whoami`/index.php

The output should be the version number, if you prefer you can use the phpinfo() function instead but it will flood your terminal with info.

Finally, you'll need to add appache to the launch deamon to get it started every time you reboot.

# sudo launchctl load -w /System/Library/LaunchDeamons/org.apache.httpd.plist