Restarting Apache on OSX from the Command Line

OSX Web Server Grayed Out
This managed to perplex me for some time...

For some reason, the Web Sharing checkbox which I would normally use to restart Apache under OSX became grayed out. I have since realised that I could have just clicked the lock (DOH!)… but I found a way of restarting Apache from the command line:

sudo apachectl restart

will restart Apache, reloading all php.ini/httpd.conf changes.

Getting Current Page URL with PHP

If you would like to dynamically include a Facebook “like” button on your pages, then you will need to know the pages FULL url (rather than the file name of the page). There are, of course, other uses for knowing the full URL to page other than Facebook “Like” buttons – but that was what I personally needed the URL for. ┬áThis PHP Snippet:

function pageurl() {
$prefix = "https://";
$prefix = "http://";
return $pageURL;

will return the URL of the page. The first six lines check to see if the server is communicating with the requesting machine over HTTP or HTTPS, and sets the prefix accordingly.

Line 7 then creates the URL string, combining the prefix, the server name (or the domain name), and the path to the requested files. Line 8 then returns the URL String, which can be echoed like so:

echo pageurl();