Alternatives to php for in-line web programming?
Question: I first learned web programming with php a while back. It has some features
that I find very helpful, but the overall language is not something I enjoy,
just as a matter of personal preference. I am wondering what alternatives I
could use to provide similar functionality using a different underlying
programming language (Python? Ruby?).

What I am looking for:

  * general purpose programming capability
  * in-line server-side code embedded in HTML (i.e. I want to be able to make my documents pure HTML if desired, rather than demanding special syntax even where I don't want dynamic content)
  * access to request parameters
  * ability to send headers, set cookies, etc

Preferably:

  * does not require a separate server process
  * easy to connect with Apache

Does anyone have any suggestions?

One thing I tried to do was embedded Ruby (erb) through CGI. This looked like
a good fit on paper. Unfortunately, I was not able to get it to work, because
I was following a few different guides and the result of combining them did
not work out. At any rate, it seems this would not allow me to set arbitrary
headers (and more importantly, use sessions and cookies).

Note: I'm not looking for a full web framework at the moment. Just relatively
small amounts of dynamic content among otherwise HTML pages.

Thanks!


Answer: You've hit on the big reason why PHP is so popular - it has all of those
pieces in a server-embeddable package. There aren't really many solutions with
its ease of deployment; PHP is written specifically for what you want, which
is both its strength and weakness. It's why it's such a weak general-purpose
language, and why everyone and their dog knows it. It's everywhere, and the
barrier to entry is near zero.

PHP is a language plus templating plus a web framework all baked into one
package. To get an equivalent, you're going to need a web framework, even if
it's a small one. Something like [Sinatra](http://www.sinatrarb.com/) is a
super lightweight way to do similar in Ruby, though it requires a separate
server process.

You could look at something like Perl with cgi.pm, but it may be a step in the
wrong direction if you're wanting something cleaner than PHP.

I don't know Python packages well enough to offer suggestions there, but
Twisted makes it easy to bind a Python program to a web interface. That does
end up running in its own server process, though.

You'll need to do a little more work than your standard PHP deploy if you want
to use something besides PHP, but that's often a choice that people consider
to be a reasonable tradeoff for gains in productivity.

