PHP Local Development vs Production Website
Where should you code your PHP project? Should you add your code on a Production Website or should you develop your PHP project locally?
First some Terminology:
- Production Website – a live website that anyone can visit by typing in the url or doing a google search for.
- Web Server – is software used on a computer to run websites. Apache is the most widely used web server. NGINX is another option used.
- Database – is what’s used to store data for a website. Your code is typically separate from the database itself. MySQL is the most widely used database management system used. MariaDB is another database used by many.
- Local Web Server/Development – this is when you have software on your local computer that simulates a live server environment. This enables you to code locally, safely in an environment that can only be viewed by you. You will have a web server, a database and support for the server side language you’re working with.
- Text Editor/IDE – these are what’s used to create your code. Every Operating System has a basic text editor installed but it’s best to go with either Atom, VSCode or a Premium IDE aka Integrated Development Environment like PHPStorm
Out of convenience, some think it’s ok to add new code to an existing Production website without first debugging their code locally. This is called Cowboy Coding and most developers have done it, me included.
Yes, there are times you might have to change some code that’s already live on your production website. So you SSH into your web server, cd – change directory into the appropriate folder and use the nano text editor to add or change some code.
That maybe, might be ok in an emergency but normally it’s best to code locally, test locally and once all bugs are cleared up, then deploy your new code to your production website.
Local Development with PHP
So how do you setup a local development environment that’s similar to your production environment? Good question. There are a few things you want to keep in mind.
- Local PHP version should match your production website. This is important because you want to make sure your code will work the same in both environments. Each new version of PHP adds new functionality and deprecates older code, which you need to watch out for.
- Your Database version should be the same on both. And the type of database should be the same for both your local and production environment.
- Your web server used should also be the same. There are differences between the way Apache and NGINX operate.
One thing you might have noticed is I didn’t mention the Operating System used locally.
Linux vs Windows vs MacOS
When it comes to production websites, Linux reigns supreme! The overwhelmingly, vast majority of websites are on computers powered by Linux. Often using either CentOS or Ubuntu Server.
So does that mean you need to be running Linux in your local development environment? The answer is not necessarily.
You can code on either a Windows 10 Computer, MacOS laptop/desktop or of course a Linux powered Computer. It doesn’t matter (much).
Of course there are differences between each OS, but you can use software that makes coding with PHP, pretty much seamless on either platform.
Local Web Development Software Options
- MAMP – is used on either Windows or MacOS but not Linux.
- WAMP – is used only on Windows Computers
- XAMPP – can be used on either Windows, MacOS and Linux
- Local by Flywheel – Can be used on Windows, MacOS and Linux. Used for WordPress Development
- Varying Vagrant Vagrants – can be used on all three OS’s but is considered a more advanced option.
There are others, but the one’s mentioned above are what you will typically come across. Here are a few videos on some of them to help get you started.
In the video above, I show you how to setup MAMP for use with WordPress, but it can also be used for non WordPress Based Projects.
In the video above, I show you how to use VVV aka Varying Vagrant Vagrants which is a more advanced option.
In the video above, I demonstrate how to use Local by Flywheel for WordPress Development.
Adding PHP to a Production Web Server/Website
So once you test out your code locally and are sure that it’s secure, efficient and accomplishes what you want, you will then add it to your production web server/website.
The process can be as easy as logging into your web server control panel and pasting the code in the proper file. This is not what I recommend doing.
The preferred process is using an SFTP program like FileZilla or SCP aka Secure Copy. In another tutorial I will go over in more detail how to use FileZilla. And in another tutorial series on Linux, I’ll demonstrate SCP.
You should code locally in a safe environment where you can test your code thoroughly and then once you’re confident that your code is ready for Prime Time, then deploy to your Production Website.
Hopefully you found this article helpful. Thanks for reading and checkout some other articles here on PixemWeb.