Setting up PHP Development & Production Server Environments

As most developers know, for a server to run reliably, you need a complete software ecosystem. Fundamental components like Apache, PHP, and MySQL are like the server's "organs" – they're all essential and must work together harmoniously. We'll assume you already understand the basic principles of how servers operate, so let's focus on the specific configuration strategies.
Among the many server architectures, the LAMP stack (Linux, Apache, MySQL, PHP) is a classic configuration. It's not only easy to install, but also boasts strong community support, and can handle everything from personal blogs to medium-sized e-commerce platforms.
Of course, technology choices are always diverse. Nginx, as a rising star, performs exceptionally well in high-concurrency scenarios due to its event-driven architecture. You can run comparative tests to choose the solution that best suits your needs. However, regardless of which web server you choose, the philosophy of configuring PHP remains consistent: you must strictly differentiate between development and production environments.
Security is the lifeline of a production environment. Now, let's go through a step-by-step configuration of these two environments.
Development Environment
Windows
Setting up a development environment on Windows doesn't require purchasing an expensive server edition of the OS; third-party integrated packages make everything easy. Some of these applications are XAMPP and WAMP. All of these third-party applications do the same thing – install Apache, MySQL, and PHP within the program.
XAMPP is the most commonly used – you can download it at www.apachefriends.org – because it's cross-platform. XAMPP stands for cross-platform, Apache, MariaDB, PHP, Perl. Installing XAMPP is very straightforward. After double-clicking the installer, just keep the default settings. However, be sure to check the "Developer Tools" option. This crucial step will automatically configure php.ini
to enable debugging mode. If error messages aren't displayed, you can manually navigate to C:\xampp\php\php.ini
and make the following changes:
display_errors = On
display_startup_errors = On
error_reporting = E_ALL
Once XAMPP is finished installing, it will open a dashboard that you can use to start, stop, and configure services.
After installing and running XAMPP, the webroot is located at c:xampp/htdocs/
. This is where you create your site/application. To view your work, just enter localhost
into your browser's address bar, and it will immediately launch the index
file in htdocs
.
Mac
Installation on a Mac is very similar to Windows. The easiest and least expensive way to set up your development environment is to install a third-party application, such as ServBay or MAMP.
ServBay is my personal favorite here, and you can download it at www.servbay.com. With ServBay, you don't need to do anything else. Just click on the PHP version you want, go grab a coffee, and when you come back, PHP will be installed. You don't even need to open the terminal. The whole process takes less than 3 minutes, which is why I recommend it. The built-in ServBay Dashboard displays key information in real-time, such as service status, port usage, and log streams.
Moreover, ServBay comes with phpMyAdmin and Adminer, saving us the trouble of configuration.
Linux (Debian-based)
In the Linux world, I advocate for native installations to achieve optimal performance. First, update the software repositories to ensure component compatibility. You can do this by running the following commands in the terminal:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
These commands simply ensure that your system is up to date with the latest versions of the software. This also helps ensure you don't have any dependency issues.
After updating your system, Apache2 should already be installed on most Linux machines. However, if you're unsure, just run sudo apt-get install apache2
(remember, if something is already installed, running the install command will just check if there's an updated version of that software).
Now you'll also need to install a database. You can use any database you like, but I use MySQL. To install MySQL, run the following in your terminal:
sudo apt-get install mysql-server
sudo mysql_secure_installation
Follow the prompts and enter a secure password.
Once you're sure you have Apache2 and MySQL installed, you can install PHP by running:
sudo apt-get install php
This will install PHP with its default settings, so you'll need to locate the php.ini
file, which can be found in /etc/php/7.0/apache2
and /etc/php/7.0/cli
. You'll need to update the "Error handling and logging" section (around line 392) to display all errors. There are comments that will help you make the correct changes. However, a simple rule is: for development, turn everything on, and for production, turn everything off.
You'll also want to install phpMyAdmin, which will make setting up and altering your database much easier.
Doing so is rather simple, just open your terminal and type:
sudo apt-get install phpmyadmin
Once you've done that, you need to configure the Apache configuration file to include phpMyAdmin. This can be done by executing the following:
sudo echo -e "\nInclude /etc/phpmyadmin/apache.conf" >> /etc/apache2/apache2.conf
Now all you need to do is start Apache and MySQL, and everything will be working. Use the following command to do so:
sudo service apache2 start && service mysql start
And there we go, all set up on your Linux machine.
Production Environment
When your code is facing real users, secure configuration is your digital armor. On a Mac, this is a breeze. With ServBay, you can turn off various parameters with a single click, and then you can immediately start coding with your preferred IDE.
However, whether you're running a Windows server or a Linux server, the principles for adjusting php.ini
are the same:
Turn off all error display:
display_errors = Off
Enable error logging:
log_errors = On
Specify the log path:
error_log = /var/log/php_errors.log
On Linux, it's recommended to use a log rotation tool to prevent log files from growing too large:
sudo apt install logrotate -y
For Windows servers, it's recommended to regularly use the Event Viewer to check system logs.
Important Note: Differences in configuration between development and production environments should be managed through a version control system, such as using Git branches to differentiate environment configuration files.
Thank you for reading my tutorial, and I hope it helps you set up your system for the exact purpose you need.
Subscribe to my newsletter
Read articles from Fireworkkk directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Fireworkkk
Fireworkkk
I am a PHP developer.