Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternatives to php for in-line web programming?

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!

like image 900
Ming Avatar asked Nov 08 '11 03:11

Ming


People also ask

What is alternative of PHP for Web development?

One of the best PHP alternatives is Python. It is a versatile language that is often used in scientific computing and data analysis. It's considered an easy-to-learn language and also supports multiple programming paradigms. This makes Python a good choice for beginners that are just starting out with coding.

What is a modern replacement for PHP?

Python is an extremely advanced server-side programming language, used for web design and development. This powerful dynamic language is massively used for server-side development. Its popularity is growing constantly to soon overpass PHP. Python suits a variety of web projects, from simple to complex.

Is Python a good alternative to PHP?

Python is better than PHP in long term project. PHP has low learning curve, it is easy to get started with PHP. Compare to PHP Python has lower number of Frameworks. Popular ones are DJango, Flask.


3 Answers

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 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.

like image 143
Chris Heald Avatar answered Oct 19 '22 09:10

Chris Heald


Python Flask is a good web framework: it fits your requirements, easy to learn, and scales gracefully. Go through the tutorial to see!

like image 30
shimofuri Avatar answered Oct 19 '22 09:10

shimofuri


I have three suggestions.

The first is Ruby on Rails - It's pretty fun once you get into it.. I would recommend going through Rails for Zombies to get a general idea of whether you like it or not.

http://railsforzombies.org/

It's really easy to get something up and running on Heroku for free, so you don't have to spend any money to get something up on the web..

My second suggestion is one I'm just trying out called Node.js. I'd recommend watching this video to get an idea of what it's about:

http://www.youtube.com/watch?v=jo_B4LTHi3I

If you're into Javascript, I think you'll get it right away. You can also build an open source Node.js project on www.cloud9ide.com which is pretty nifty too.

A third one, if you're into learning Java, is "Play". A cool video on this is:

http://vimeo.com/7087610

I haven't used this much, but it's on my "to do" list of things to check out. Overall, I suggest just dipping your toes in the water for a bunch of different frameworks and get an idea of how they work and then you'll naturally pursue whatever makes the most sense to you. Good luck!

like image 34
Mike Christensen Avatar answered Oct 19 '22 11:10

Mike Christensen