Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

bLaZ3n

macrumors regular
Original poster
Jul 9, 2010
143
0
First things first, I know it isn't Java, C or Xcode.. but I'm new to programing on a MAC OS. I'm used to a windows environment. But, how do I run a php/html based program in Text Wrangler?

I get his error:
PHP:
This file doesn’t appear to contain a valid ‘shebang’ line (application error code: 13304)
 
I guess I’m not totally clear on what you’re doing. If you’re trying to run PHP on your Mac, you’ll need a web server that will handle PHP.

If you’re just starting out, I’d recommend MAMP, which is a Mac AMP stack (Apache [Web], MySQL [DB], PHP [extension for Apache to handle PHP]).

Then with TextWrangler (great text editor BTW), you’ll edit your code, then browse it with Safari/Chrome/etc., on the MAMP configured IP/port (example: http://127.0.0.1:8000)

If you’re just trying to use the RUN command from the TW menu, that’s just trying to invoke a shell script (hence the “shebang" error, i.e., the #! expected when invoking a shell). TextWrangler is _just_ a text editor (not a full IDE like Visual Studio), it doesn’t have a compiler, debugger, web services or anything like that.

Conceptually, it’s not that much different if you’re familiar with Windows based web platforms like .NET - you still need a local web server with .NET extensions. It just happens to be bundled into VS, so the RUN command in VS, creates an instance of a web server, with your application as the root, then points your default browser to it, so it’s very automagic (though when I’m working in .NET, I have an IIS instance running non-stop, and generally just swap out to my browser vs. letting VS fire up an instance each time).

AMP stack download for OSX:

http://www.mamp.info/en/
 
Last edited:
I guess I’m not totally clear on what you’re doing. If you’re trying to run PHP on your Mac, you’ll need a web server that will handle PHP.

If you’re just starting out, I’d recommend MAMP, which is a Mac AMP stack (Apache [Web], MySQL [DB], PHP [extension for Apache to handle PHP]).

Then with TextWrangler (great text editor BTW), you’ll edit your code, then browse it with Safari/Chrome/etc., on the MAMP configured IP/port (example: http://127.0.0.1:8000)

It’s not much different if you’re familiar with Windows based web platforms like .NET (you still need a local web server with .NET extensions, it just happens to be bundled into VS).

Okay I'll try.. I slightly understand and I already have MAMP installed and running

----------

I guess I’m not totally clear on what you’re doing. If you’re trying to run PHP on your Mac, you’ll need a web server that will handle PHP.

If you’re just starting out, I’d recommend MAMP, which is a Mac AMP stack (Apache [Web], MySQL [DB], PHP [extension for Apache to handle PHP]).

Then with TextWrangler (great text editor BTW), you’ll edit your code, then browse it with Safari/Chrome/etc., on the MAMP configured IP/port (example: http://127.0.0.1:8000)

If you’re just trying to use the RUN command from the TW menu, that’s just trying to invoke a shell script (hence the “shebang" error, i.e., the #! expected when invoking a shell). TextWrangler is _just_ a text editor (not a full IDE like Visual Studio), it doesn’t have a compiler, debugger, web services or anything like that.

It’s not that much different if you’re familiar with Windows based web platforms like .NET - you still need a local web server with .NET extensions. It just happens to be bundled into VS, so the RUN command in VS, creates an instance of a web server, with your application as the root, then points your default browser to it, so it’s very automagic (though when I’m working in .NET, I have an IIS instance running non-stop, and generally just swap out to my browser vs. letting VS fire up an instance each time).

Okay, where do I put my .php files so I can browse through chrome? I looked through the MAMP folder and I don't see a root or www directory
 
When you run MAMP there’s a small UI that fires up (in addition to the AMP admin page you’re directed to). In that UI, go to Prefs, Apache, and that will define the document root:
 

Attachments

  • Screen Shot 2014-03-05 at 10.40.51 PM.png
    Screen Shot 2014-03-05 at 10.40.51 PM.png
    66.4 KB · Views: 429
... and that same UI/config will show you the port the web server is running on, so in this example, it’s http://localhost:8888

I have it set to default.. but for some reason I can't browse to the file through chrome.. can you help me construct the URL?
 

Attachments

  • documentRoot.png
    documentRoot.png
    81.7 KB · Views: 285
OK, so you’ve got your webroot, easy enough, and your port should be on that PORT tab in the screenie you posted. Since it’s local, if you haven’t done any custom hosts or anything, you can use localhost:<port>, or 127.0.0.1:<port> (where port = the value on your port tab, that I believe is 8888 as a default).

If you point a browser to that URL what do you get? Some browser message like a nonexistent URL, or a PHP error? If directly browsing is on, you should see the root of your web server and the files, or if you’ve got a default document (index.htm, index.php), you should see that file.

If you’re getting _some_ kind of response, then maybe try a static HTML file at the root and go directly to it. If you’re getting a PHP related error, you can always toss in an test page like:

PHP:
<?php

phpinfo();

?>

Which will dump your PHP environment when you browse that page.


Slightly off topic: PHP is _evil_ :D
 
OK, so you’ve got your webroot, easy enough, and your port should be on that PORT tab in the screenie you posted. Since it’s local, if you haven’t done any custom hosts or anything, you can use localhost:<port>, or 127.0.0.1:<port> (where port = the value on your port tab, that I believe is 8888 as a default).

If you point a browser to that URL what do you get? Some browser message like a nonexistent URL, or a PHP error? If directly browsing is on, you should see the root of your web server and the files, or if you’ve got a default document (index.htm, index.php), you should see that file.

If you’re getting _some_ kind of response, then maybe try a static HTML file at the root and go directly to it. If you’re getting a PHP related error, you can always toss in an test page like:

PHP:
<?php

phpinfo();

?>

Which will dump your PHP environment when you browse that page.


Slightly off topic: PHP is _evil_ :D

I got it.. silly me.. I was using the wrong ports. I did "localhost:<Apache port>" .

Thanks for your help
 
Awesome. Yeah, sometimes it's something painfully obvious.

BTW, if you're just getting into PHP you might want to consider a good MVC framework - it'll reinforce some good dev behaviors and ultimately speed up development. CakePHP, Yii, there's several great options.
 
Awesome. Yeah, sometimes it's something painfully obvious.

BTW, if you're just getting into PHP you might want to consider a good MVC framework - it'll reinforce some good dev behaviors and ultimately speed up development. CakePHP, Yii, there's several great options.

Just wondering are those programs you recommended applications to build php programs? Sort of like Eclipse for Java?
 
Just wondering are those programs you recommended applications to build php programs? Sort of like Eclipse for Java?

Those products I recommended are actually frameworks (not as IDE like Eclipse, Visual Studio, etc.) A framework sits “on top” of a language and extends the functionality - some frameworks extend languages to make them very web friendly (Ruby > Rails, Python > Django), but some just provide a whole slew of helper functions, wrappers, etc., to simplify things things which is the case here.

PHP is easy to write sloppy, to not use an MVC pattern, so there’s data access in controllers, and code strewn all through markup (views), etc. Plus, there’s a ton of repetitive chores in dealing with things like databases, lists/tables of data and whatnot. These PHP frameworks try to provide most of this.

BTW, I just realized this section says “not for web programming” since I guess that’s not necessarily mac related.
 
First things first, I know it isn't Java, C or Xcode.. but I'm new to programing on a MAC OS. I'm used to a windows environment. But, how do I run a php/html based program in Text Wrangler?

I get his error:
PHP:
This file doesn’t appear to contain a valid ‘shebang’ line (application error code: 13304)
Did you look up "shebang"? In the case of PHP, it's the character sequence
"<?" that should begin in the file; the last line of the file should be the corresponding "?>".

You don't need any web page or web server to run a PHP program, just the PHP interpreter, which should ordinarily be on your path. Write and save your php file from any text editor, including Text Wrangler. Then run it from the command line. For example, look at the following file prog.php:
Code:
<?
echo "Hello, World!\n";
echo "1+1 equals ",1+1,"\n";
?>
Then at the Terminal command line:
Code:
[~/mydir]$ php prog.php
Hello, World!
1+1 equals 2
It's standard to replace the opening shebang sequence with "<?php".

Of course, the most common use of PHP is to execute scripts within a web page. but that's not what you actually asked.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.