I have written this article specially for businesses who want to start a Web Application project and they are trying to select either PHP or Python for its back-end (server-side) programming language.

I have worked in the application development industry for 30 years and I come across clients who would ask me to build them a simple web application using Python because they were told that Python is a newer and much better programming language.

There have been a few cases when clients came to me asking me to rebuild their back-end web application from PHP to Python because they have heard that PHP is dead and they should rebuild their web application's back-end in Python.

What I have noticed and learned from the web application development industry is that a lot of people in the industry would give you their biased opinion based on what suits them. For example, one person went to a Python Development Company asking them to make some updates to their PHP code, but because the Python development company was mostly specialized in Python development, the sales rep told him that PHP is dead and they should rebuild their back-end application from PHP to Python.

In my opinion, every programming language has its strength and its use.

Python is a general purpose programming language meaning that you can use Python to build any system application such as desktop applications, business applications, web applications, APIs, data analysis applications, machine learning, etc..
So you can use Python to build web applications, but it is mostly efficient if you use a Python framework built for Web Applications such as Django, CubicWeb, Web2py, Pyramid, CherryPy, Flask, etc..

PHP is not a general purpose programming language but it was specifically developed for web development / web application development, you can easily embed your PHP code in HTML for server-side scripting. That is why so many web applications are built using PHP. WordPress which is the most popular CMS application is written in PHP, so is Drupal and Joomla. There are many full featured open source ecommerce applications which are written in PHP such as Magento, Opencart, WooCommerce, OsCommerce, Prestashop, Zencart, X-Cart, Bagisto. And there are many many PHP Programming Frameworks such as Laravel, CodeIgniter, Symfony, FuelPHP, Slim, Phalcon, Yii Framework, Zend Framework, CakePHP. So PHP is not dead and in my opinion, it is going to be around for a long time.

There are also rummer that PHP applications tend to be written in substandard coding practices, but Python applications are more structured and less spaghetti. This rummer can be true because some new coders quickly learn PHP and start writing PHP code for clients without learning how to write structured, maintainable code and without following the best practices in writing code. But this does not mean that PHP was the main reason that we have substandard coders, there are coders that also do not follow best practices in writing Python code, so if there are substandard, poor quality code out there, the blame should go to the coder who did not follow best coding practices and did not put extra time in writing structured, better maintainable code.

So if you are a business owner or an inventor and want to build a custom web application for your business, which back-end (server-side) programming language you should choose?

In my opinion, it depends on the application scope. If the application is a simple application, mostly web database type application, then PHP should be the better option. However, I'm not stating that PHP is not a good choice for complex applications; there are many complex web applications that are written in PHP, but what I'm saying is that it is no brainer to use PHP on a simple database type web application. But, you need to make sure that the PHP coder that you hire has experience in building structured based applications so you won't be spending a lot of money and time building a web application that is not maintainable, scalable and possibly have application security flaws.

That is the reason that there are many open source PHP frameworks out there. Using a PHP framework creates a development framework that is more structured and more secure. At the same time, if the web application that you are building is simple in nature, sometimes it is less costly and less time consuming to just build the web application using a simple structured based coding practices. This requires the coder to have knowledge and experience in application security and structured way of coding.

So to answer your question of which programming language you should use to build your web application; in my opinion you should be focusing on hiring a coder that has the knowledge and experience in building secure and structured applications and then consult with experienced consultants and then choose a programming language and the framework that is best suited for your project. Sometimes when you find a very qualify coder with knowledge and experience and you feel comfortable about hiring him/her, and you have done your due diligence to get secondary unbiased opinion, then you may want to choose the programming language and framework that your experienced coder has recommended to you to choose for your application.

PHP and Python are both powerful and capable programming languages for building most web applications, it is usually the scope of the project and who you find as a coder who has the knowledge and experience of building web application that is important for building a secure and maintainable web application.

Some very large applications use different programming languages based on what is suited for them for example:

  • Google uses: JavaScript, TypeScript, C, C++, Java, Go, Python, and Node
  • Facebook uses: JavaScript, Hack, PHP, Python, C++, Java, and others
  • Yahoo uses JavaScript and PHP for the most part
  • Etsy use JavaScript and PHP for the most part
  • Wikipedia uses JavaScript and PHP

Below are pros and cons of PHP over Python and vice versa

PHP Pros over Python

  • PHP, especially, the latest PHP 8.1 is much faster than Python
  • Since PHP is specialized in server-side scripting for web development / web application development, it usually takes less development time to build a web application project using PHP.
  • Since Python is a general purpose application and it's being used in many system software / application development besides web, there are more demands for Python developers than PHP developers so since there is a shortage of Python developers, the rate and cost of hiring Python developers tend to be higher.
  • PHP has a more straight-forward and easier interfacing tools with database servers such as MySQL or MariaDB.

PHP Cons over Python

  • Unfortunately it is not difficult build a PHP application that is not secure and not maintainable and there are new coders that quickly learn PHP and code web applications in such a way that is not secure and not maintainable.

Python Pros over PHP

  • Python is a very powerful programming language and it is ideal for building part of the very large application, especially in the areas / sections where Python has more strength.
  • Python makes it harder for the programmers to build a spaghetti code; however, I have seen Python code and I wondered what was the programmer thinking using such a convoluted logic.
    So, although it is harder for a coder to build a spaghetti code in Python, he/she could use convoluted logic or code practices that are not friendly for future developers.

Python Cons over PHP

  • Python tend to be slower performing than PHP, especially, the latest PHP 8.1 is much faster than Python.
  • Python's interfacing with different database servers are not as straight-forward.
  • It may be harder to find Python developers; therefore, the rate and cost of hiring a Python developer is higher.
  • It may take additional development time to develop a web application using Python than PHP so the development cost of building a Python application maybe higher.

Below are very top level comparison of Python vs PHP

  Python PHP
Type / Use General Purpose - for Building any System Application Specialized in Server-side Web Application Development
Performance Python tend to be slower than latest PHP Latest PHP is much faster than Python
Security Security of the application usually relies on the code security experience of the coder rather than the programming language Security of the application usually relies on the code security experience of the coder rather than the programming language
Code Maintainability Python promotes more of code maintainability If the PHP developer is not experienced in building a maintainable code, he/she can build a spaghetti, hard to maintain code using PHP
Development Time to Build It can take more time to build a web application using Python than PHP PHP's time to build and deploy tend to be quicker
Cost The cost to build a Python web application tend to be higher The cost to build a PHP web application tend to be lower
Popular Web Application Framework Django, CubicWeb, Web2py, Pyramid, CherryPy, Flask, etc.. Laravel, CodeIgniter, Symfony, FuelPHP, Slim, Phalcon, Yii Framework, Zend Framework, CakePHP, etc..