PHP famously claims to be the backend programming language for just under 80% of the Internet. However, if you look at the popularity rankings of programming languages, Python is consistently far ahead of PHP. How can that be? Both languages can be used for backend web development, and PHP was even specifically made for web development.
So which one is better, Python or PHP? If I were starting fresh, I’d probably learn Python, and here’s why.
🔗 Python versus PHP: Groundwork
Python is a high-level interpreted programming language that makes use of garbage collection and is dynamically typed. Designed by Guido van Rossum in 1991, Python is intended to be readable and is more concise than other popular languages like Java, C, C++, etc. It has aspects of object-oriented programming as well as functional programming, and it’s intended to be versatile.
In case you were curious (I was) Python’s name comes from Monty Python’s Flying Circus, a BBC comedy special, not just the snake.
PHP was created in 1994 by Rasmus Lerdorf. His first use for it was tracking who viewed his resume online, which also explains the origins of the original name, Personal Home Page tools, though now PHP stands for PHP: Hypertext Preprocessor making it a funny recursive name.
PHP has also been deemed a general-purpose scripting language. It was one of the first few server-side languages which developers could embed into HTML, which makes it easier to produce jazzy and interactive websites.
🔗 Python versus PHP: Easiest to Learn
Python was created with the intent to be incredibly easy to understand. Most people who are not familiar with programming can fairly easily read through a Python script and get the gist of it, as long as whoever wrote it was good at naming variables!
Students often start their learning journeys with Python. Since it’s more concise than most other programming languages, there’s less syntax to memorize, the code looks cleaner, and there’s less visual noise. All of these aspects make Python a great introduction to programming. I’ve personally found it to be the fastest programming language for beginners to learn.
PHP, though it claims to be a general-purpose scripting language, was designed specifically to be used with web applications. Web apps are typically complex things that take quite a bit of overhead to stand up. So if you’re just trying to get a simple little PHP script to run, you’ll find it to be much more challenging than doing the same using Python.
If it’s any indication, there are lots of people on the Internet that passionately despise PHP, whereas the same cannot be said for Python. One developer, Eevee, went so far as to compile a laundry list of reasons why PHP is a poor choice as a programming language, particularly when you’re just starting out to learn. Their main points claim that PHP is “full of surprises, inconsistent, flaky, and opaque.”
Take a look for yourself, but these claims are valid. I’ve heard plenty of developers complain again and again about the frustrating task of building and maintaining a website developed with PHP due to its inconsistencies and confusing behavior. For beginners, always choose Python versus PHP. Here are some amazing projects to get you started in Python!
🔗 Python versus PHP: Ease of Installation
PHP is pretty great when it comes to getting it installed. It runs without issues on Windows, macOS, as well as Linux, and usually comes pre-installed on most web servers.
Python, on the other hand, can require a bit more work. It comes pre-installed on Mac and Linux, but if that version is outdated, but you’ll often need to install newer versions of Python, and maintaining multiple versions on one device can be tricky. Luckily, there’s a cool tool called pyenv that was made just for managing multiple Python versions.
If you’re interested in getting a Python environment set up on your machine, check out our development environment setup project.
🔗 Python versus PHP: Popularity
When it comes to popularity amongst developers, Python leads by a wide margin. No matter which ranking list you look at, whether it’s for general use or specifically for web development, Python is more popular than PHP. Not only that, but Python’s ratings are five times higher than PHPs. If you look away from developer ratings to actual usage on the web though, PHP is used by ~78% of websites.
The primary reason PHP is so widely used comes down to CMS products like WordPress. WordPress is an open-source no-code tool for managing websites, and since it’s written in PHP and is so popular, PHP gets a crazy usage bump. WordPress also used to be even more loved than it is today, so legacy websites very often use PHP.
🔗 Python versus PHP: Libraries
Python has over 137,000 libraries. Python libraries are incredibly powerful and active chunks of code that can make your life as a developer significantly easier. Whether you’re talking about machine learning, network programming, or web development, there are myriad libraries to help you implement powerful tools.
There are a good number of useful PHP libraries as well. According to CloudWays, “PHP requires coding from scratch for every single function. This becomes a bit of a hassle for the developers and is a time-consuming process.” PHP made the move to make more libraries built-in to make getting your PHP program off the ground easier. That being said, CloudAway’s list of top PHP libraries includes some that make me question what PHP can do on its own, like the Symfony Finder Component, which is intended to make locating files and folders in your project easier.
🔗 Python versus PHP: Frameworks
According to the CodeInstitute, a framework is a platform that “provides a foundation for developing software applications.” It’s a sort of template for a program, like React. You can run a single command in the command line and a working program will be created. It’s just a boilerplate, but it’s an easy place to start and provides you with the backbone of a working program. You can then edit it to your needs and customize it as you wish.
Laravel, a back-end framework for PHP helped to revive it as a language that was waning in popularity. It helped to bring PHP into the limelight again and made it a viable option for modern web development.
PHP’s Laravel ranks as the #8 most popular framework on GitHub, and Symfony and CodeIgniter come in at #13 and #14 respectively. Python’s Django, however, beats out Laravel at #7 and Flask is #12.
🔗 Python versus PHP: Maintainability
Python has undergone two major version changes since its inception, and though you’ll have to put in some serious work to convert a Python 2 program to a Python 3 program, the changes aren’t too drastic. The latest major version came out in 2008, meaning that it has had plenty of time to mature. There are 13 years worth of relevant and helpful Python tutorials out there. Even if you find older Stack Overflow posts, only a few mainstream functions have changed from Python 2 to 3. If you’re learning for the first time, just learn Python 3! No need to muck around with old technology.
PHP on the other hand is already on its 8th major version, which was only released in 2020. This update is a major one. If you check out the examples posted in their documentation of changes from PHP 7 to PH 8, there are syntax changes scattered throughout, even just the tags for an HTTP request method in a controller.
This new version makes PHP more readable and concise, but it’s still a lot less pretty to look at than Python. It can cause major security issues if you do not use the most up-to-date version of PHP, which means you must stick with the newest version. One unfortunate side effect of big language changes is that it cuts down on the amount of available learning material you can use, making it harder to get all of your questions answered.
🔗 Python versus PHP: Security
Security issues like SQL injection and cross-site scripting (XSS) are major concerns. Web security is extremely important. In terms of security, Python is certainly the recommended option over PHP. The Django framework, for example, comes with built-in protections against most XSS, cross-site forgery, SQL injections, and clickjacking attacks.
Many organizations that handle sensitive data or have security concerns opt for Python over PHP. All of the kinds of attacks that Django helps protect you against are valid concerns when using raw PHP. You have to be extremely careful to watch out for these holes in your implementation. These security issues are avoidable, but you will have to be on high alert to catch every security bug you introduce when using PHP.
Let’s be honest, every developer makes mistakes. Now and then, these mistakes even get through code reviews and make it into production. That’s why it’s important to take security seriously and do everything you can to make keeping your web application secure easy. If you’re looking at Python versus PHP for backend security, while you can write secure code in PHP, it can be easier to write secure code in Python.
🔗 Python versus PHP: Employability
Picking which programming language to learn depends on your interests and current skill set. If you know 100% that WordPress or Laravel development is your life’s passion and there’s nothing you would rather do, you should certainly learn PHP. It’s still used all over the place in web development, and it will be worth it to learn. However, if you’re more interested in Django, Flask, data science, or other kinds of programming, I think Python is the more pragmatic choice.
When it comes to money, Python wins again. The average base salary of PHP developers in the US is $92K, whereas the average base pay of a Python developer in the US is $108,000. If you happen to live in (or want to move to) New York, NY, your base pay could look more like $134,000.
Spotify, Instacart, and Pinterest use Python as their backend web development language, but Facebook, Wikipedia, Slack, and WordPress all use PHP. You’ll find the use of both Python and PHP scattered across the software development industry. That said, the trend is definitely in Python’s favor, as even Facebook has been migrating away from PHP.
🔗 What should I learn?
Python is one of the world’s most popular programming languages, and it seems to gain more popularity every year. It’s an incredibly versatile language, and the tech fields that are currently gaining the most popularity, like machine learning and data science, rely heavily on Python. If you have to pick one, I’d pick Python, and you can even easily learn it using our Python course for beginners. It will serve you well in the long run.