Saturday, November 21, 2009

Setting up a local Virtual Host using WAMP/Apache

Setting up a virtual host will allow you to essentially run an exact copy of your site locally.  You'll need to decide on a local domain name.  My standard is to only maintain the primary name.  So for instance if the site is http://www.domain.com then I will use http://domain/ for the local copy.  Some people decide to use http://domain.loc/.

Once you've decided, open C:\Windows\System32\drivers\etc and open the hosts file.

It should look like this when opened:

127.0.0.1       localhost
::1             localhost

Add a new line

127.0.0.1       localhost
127.0.0.1       domain
::1             localhost

Replace "domain" with "domain.loc" if you want.

Next you're going to need to locate your Apache installation. In WAMP, you're going to need to open C:\wamp\bin\apache\Apache2.2.11\conf\extra\httpd-vhosts.conf and add the line:



    ServerAdmin webmaster@localhost
    DocumentRoot "c:/wamp/www/domain"
    ServerName domain
    ErrorLog "logs/domain.log"
    CustomLog "logs/domain.log" common
    
        Options Indexes FollowSymLinks
        AllowOverride all
        Order Allow,Deny
        Allow from all
        Allow from 127.0.0.1
    

AFTER

NameVirtualHost *:80



    DocumentRoot "c:/wamp/www"
    ServerName localhost

If you're using .loc, all you should have to do is add .loc to the ServerName, NOT to the paths defining the location to load.

Friday, November 20, 2009

Regex Library

I was doing a search for some regex that I could modify to meet my specific needs for a project (I haven't learned it yet). I stumbled on this site that has tons and tons of regex examples. I figured it was a link I definitely wanted to keep so I'd post it here. Who knows, maybe you'll find it useful too.

http://www.roscripts.com/PHP_regular_expressions_examples-136.html

Wednesday, November 18, 2009

PHP Force File Download

When setting up a file download on a web site you never want to link to the file directly.  By linking to the file directly you're letting the browser determine the best action to take.  If the file is capable of being opened in the browser (.txt, .jpg, .pdf) then that's what the browser will do.  However you can easily force the browser to give a download prompt.

$file = '/home/user/public_html/file.zip';

header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Last-Modified: '.gmdate ('D, d M Y H:i:s', filemtime ($file)).' GMT');
header('Cache-Control: private',false);
header('Content-Type: application/force-download');
header('Content-Disposition: attachment; filename="'.basename($file).'"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: '.filesize($file));
header('Connection: close');

readfile($file);
exit();

Run PHP via Cron

It's simple, run the following command using an absolute path to the file.

php -q /home/user/public_html/file.php

Friday, October 2, 2009

Warning: number_format() expects parameter 1 to be double

I ran into this error when I was working on the Google Custom Search API.  I've never run into it before.  I'm passing the estimated number of search results through to a number_format() which is currently passing through the number 10.  Unfortunately it's throwing this error.  I haven't figured it out yet, if anyone knows please post the solution so others can find it as well.

Tuesday, August 4, 2009

OpenX Javascript or CSS not loading

The get.max_value_length value of your web server settings does not allow to use long URL paths. This might lead to JavaScript and CSS files not properly being included.  To fix this you have 2 options:

  1. Modify your config setting for OpenX to disable combining/compressing CSS/JS files (this only effects the admin panel).



    [ui]combineAssets=0
  2. Modify php.ini to extend the length of your GET variable values.  The default setting for PHP 5.3 is 512.


How to find the locaion of php.ini

To find the location of your php.ini file, copy and paste the below code into a php file and upload it to your server.

<?php
phpinfo();
?>

When you access the file it will look like the below image. The red arrow is pointing to the location of your php.ini file. In Linux environments this is the most common location.