Join 3,564 readers in helping fund MetaFilter (Hide)


I want to start to learn PHP *TONIGHT* on a Mac! What the hell do I need and is there a good site/tutorial/book that is best suited for the job?
August 16, 2012 2:06 PM   Subscribe

I want to start to learn PHP *TONIGHT* on a Mac! What the hell do I need and is there a good site/tutorial/book that is best suited for the job?

While not a noob by any means, my only programming skills are are the intro to C++ and I don't remember a damn thing about libraries, etc.

I want to learn PHP so I can scrape things from the web with ease, but the hardest part when I have tried in the past has just been matching what is on my screen with what is in the book/tutorial.

I'm on a Mac running 10.7 (soon 10.8) and I don't have ANY software, but I know I can get it from Apple. That said, I need a mac centric tutorial. Anyone really blown away by a tutorial out there?
posted by darkgroove to Education (13 answers total) 38 users marked this as a favorite
 
You want MAMP. It's a program that, when running, runs a local Apache server with PHP / MySQL but when not running, does, um, nothing. My feeling is that it's slightly easier to get into, and slightly more like a production LAMP environment, than using the built-in webserver from Apple.

As far as tutorials and books go, I think you'd find this book to be useful.
posted by gauche at 2:15 PM on August 16, 2012 [4 favorites]


PHP.net documentation is a good way to learn. They have a tutorial linked from the front page.
posted by wongcorgi at 2:23 PM on August 16, 2012 [1 favorite]


I liked tizag tutorials when I first tried to pick up PHP.

When you start using a database to store and retrieve information, please start with PDO (baked into PHP) and parameters! Using parameters helps you completely avoid a major SQL security issue (SQL injection).

That may seem like blue-sky stuff at the moment, but you'll be using databases very quickly if you don't give up.

You will definitely want an editor that has syntax highlighting. Sublime Text will bug you occasionally and ask you to purchase it, but you can use it indefinitely without paying for it. It is very good. There are likely many other free options for Macs if you google around (or wait for more suggestions in the thread).

BTW, PHP tutorials should be OS agnostic. At most you might need OS-specific instructions for which text editor or IDE to use.
posted by jsturgill at 2:26 PM on August 16, 2012


As some one who primarily writes PHP, I haven't found a better web scraping toolset than scrapy, but it is written in Python. The good news is you already have python on your Mac. You should be able to use easy_install to install scrapy.

I would recommend Learn Python The Hard Way as a tutorial, there is a free version. There is a pretty good scrapy tutorial as well.

What makes scrapy my favorite web scraper is its framework of handling requests. You are able to queue up several requests to traverse discovered urls. All the other scraping toolkits I've used are really geared toward scraping single pages. Scrapy makes it very easy to build much more complex spiders.
posted by ambirex at 2:42 PM on August 16, 2012 [8 favorites]


Are you familiar with Terminal (or iTerm2, from MeFi's own jewzilla)? Referencing any online or offline resource for PHP tutorials, you can run your own simple scripts from the command line.

For example, from my Terminal session, I wrote* a script called test.php that had this one line:

<?php print "Hello world!\n"; ?>

Saved the file, and at the prompt I typed:

php test.php

There are other software out there that will let you edit PHP files, but if you want to start right now I believe your machine may already have the capability. At least this way, you can get your feet wet and hands dirty.

Other sites for PHP tutorials include W3Schools. I also visit the PHP.net manual for function references, whenever my memory fails me.

* FWIW, I used vim with a .vimrc file that enabled syntax highlighting and colors.
posted by CancerMan at 2:57 PM on August 16, 2012


God, I love you guys :)

I'll have to learn a bit about each and delve deeper from there. But this seems like a fantastic place to start. Thank you all so much!
posted by darkgroove at 2:58 PM on August 16, 2012


Don't do it. If you're not careful you'll wind up like me, with a full-time job writing PHP.

I am not even remotely joking about this.
posted by brennen at 3:01 PM on August 16, 2012 [6 favorites]


Actually, just to quickly follow up, I've decided to learn Python and read Learn Python the Hard Way. Having read a bit about it, it sounds like that will provide a solid foundation for me, which is ultimately what I need, along with the mention of scrapy which may make sense to me at that point.
posted by darkgroove at 3:03 PM on August 16, 2012


Get MAMP, open an editor, create index.php, place in webroot. Start programming: tutorial. stackoverflow for questions.
posted by artlung at 3:04 PM on August 16, 2012


I've heard not-so-great things about LPTHW, though if it works for you that's good =)

I would recommend Think Like a Computer Scientist if you want to learn how to program, or any of a number of tutorials if you can already program and just need to learn Python.
posted by katrielalex at 3:32 PM on August 16, 2012


I'd definitely rather use python for scraping the web:
in terminal type:

$ sudo easy_install pip
$ sudo pip install requests
$ python
>>> import requests
>>> page = requests.get("http://ask.metafilter.com/222413/I-want-to-start-to-learn-PHP-TONIGHT-on-a-Mac-What-the-hell-do-I-need-and-is-there-a-good-sitetutorialbook-that-is-best-suited-for-the-job")
>>> page.text
<>

I recommend you use python as well - since it is cleaner than php and definitely better for parsing. php might be easier when making a quick and dirty website though.
If you do go with python, also
$ sudo pip install ipython
and ipython will let you tab to autocomplete and all kinds of other things that make it better for learning and discovery
posted by uncreative at 4:56 PM on August 16, 2012 [2 favorites]


Quick plug for PHP's associative arrays (ordered maps). They can be quite powerful and not every language has that feature. Knowing that a language has powerful features is (at least for me) a motivation to dive in and explore. Also, when I program in PHP on my MBP I use Komodo Edit.
posted by forthright at 7:09 PM on August 16, 2012


It isn't PHP or Python, but The Bastards Book of Ruby is a primer on Ruby written by a reporter who mainly uses it for scraping data. The projects are all scraping-centric, and deal with things like grabbing and following links, storing stuff in a database, and all of that jazz. If you fall out of the Python camp it might be worth a shot!
posted by soma lkzx at 5:42 AM on August 17, 2012 [1 favorite]


« Older Does anyone have any experienc...   |  Will Pink Tentacle ever come b... Newer »
This thread is closed to new comments.