How do I create a javascript variable from a php variable using External JavaScript and PH?

My script so far:

PHP Code:
<?php 
$url 
"http://localhost";

header('Content-type: text/javascript');

echo 
'var url = <?php echo $url; ?>';

echo 
'alert(url);';


?>