<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: TAKASUGI Yuya</title>
    <description>The latest articles on Forem by TAKASUGI Yuya (@takasugi).</description>
    <link>https://forem.com/takasugi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2760813%2Fc1b0201f-ae5a-44c2-9248-b899cfab0e47.jpg</url>
      <title>Forem: TAKASUGI Yuya</title>
      <link>https://forem.com/takasugi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/takasugi"/>
    <language>en</language>
    <item>
      <title>Setting up PHP Development and Production Server Environments</title>
      <dc:creator>TAKASUGI Yuya</dc:creator>
      <pubDate>Wed, 12 Mar 2025 04:23:52 +0000</pubDate>
      <link>https://forem.com/takasugi/setting-up-php-development-and-production-server-environments-5ab1</link>
      <guid>https://forem.com/takasugi/setting-up-php-development-and-production-server-environments-5ab1</guid>
      <description>&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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 &lt;a href="https://www.servbay.com/features/web-server" rel="noopener noreferrer"&gt;web server&lt;/a&gt; you choose, the philosophy of configuring PHP remains consistent: you &lt;em&gt;must&lt;/em&gt; strictly differentiate between development and production environments.&lt;/p&gt;

&lt;p&gt;Security is the lifeline of a production environment. Now, let's go through a step-by-step configuration of these two environments.&lt;/p&gt;

&lt;h2&gt;
  
  
  Development Environment
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Windows
&lt;/h3&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;XAMPP is the most commonly used – you can download it at &lt;a href="http://www.apachefriends.org" rel="noopener noreferrer"&gt;www.apachefriends.org&lt;/a&gt; – 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 &lt;code&gt;php.ini&lt;/code&gt; to enable debugging mode. If error messages aren't displayed, you can manually navigate to &lt;code&gt;C:\xampp\php\php.ini&lt;/code&gt; and make the following changes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="py"&gt;display_errors&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;On&lt;/span&gt;
&lt;span class="py"&gt;display_startup_errors&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;On&lt;/span&gt;
&lt;span class="py"&gt;error_reporting&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;E_ALL&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once XAMPP is finished installing, it will open a dashboard that you can use to start, stop, and configure services.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0e4ap11dvmx99neli4bt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0e4ap11dvmx99neli4bt.png" alt="Image description" width="800" height="578"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After installing and running XAMPP, the webroot is located at &lt;code&gt;c:xampp/htdocs/&lt;/code&gt;. This is where you create your site/application. To view your work, just enter &lt;code&gt;localhost&lt;/code&gt; into your browser's address bar, and it will immediately launch the &lt;code&gt;index&lt;/code&gt; file in &lt;code&gt;htdocs&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mac
&lt;/h3&gt;

&lt;p&gt;Installation on a Mac is very similar to Windows. The easiest and least expensive way to set up your &lt;a href="https://www.servbay.com" rel="noopener noreferrer"&gt;development environment&lt;/a&gt; is to install a third-party application, such as ServBay or MAMP.&lt;/p&gt;

&lt;p&gt;ServBay is my personal favorite here, and you can download it at &lt;a href="http://www.servbay.com" rel="noopener noreferrer"&gt;www.servbay.com&lt;/a&gt;. 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.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6ufvv0nv3h5wc9j7be0g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6ufvv0nv3h5wc9j7be0g.png" alt="Image description" width="800" height="473"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Moreover, ServBay comes with phpMyAdmin and Adminer, saving us the trouble of configuration.&lt;/p&gt;

&lt;h3&gt;
  
  
  Linux (Debian-based)
&lt;/h3&gt;

&lt;p&gt;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:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get update
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get upgrade
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get dist-upgrade
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;After updating your system, Apache2 should already be installed on most Linux machines. However, if you're unsure, just run &lt;code&gt;sudo apt-get install apache2&lt;/code&gt; (remember, if something is already installed, running the install command will just check if there's an updated version of that software).&lt;/p&gt;

&lt;p&gt;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:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install &lt;/span&gt;mysql-server
&lt;span class="nb"&gt;sudo &lt;/span&gt;mysql_secure_installation
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Follow the prompts and enter a secure password.&lt;/p&gt;

&lt;p&gt;Once you're sure you have Apache2 and MySQL installed, you can install PHP by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install &lt;/span&gt;php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will install PHP with its default settings, so you'll need to locate the &lt;code&gt;php.ini&lt;/code&gt; file, which can be found in &lt;code&gt;/etc/php/7.0/apache2&lt;/code&gt; and &lt;code&gt;/etc/php/7.0/cli&lt;/code&gt;.  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 &lt;em&gt;on&lt;/em&gt;, and for production, turn everything &lt;em&gt;off&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;You'll also want to install phpMyAdmin, which will make setting up and altering your database much easier.&lt;/p&gt;

&lt;p&gt;Doing so is rather simple, just open your terminal and type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install &lt;/span&gt;phpmyadmin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you've done that, you need to configure the Apache configuration file to include phpMyAdmin.  This can be done by executing the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo echo&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;Include /etc/phpmyadmin/apache.conf"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; /etc/apache2/apache2.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now all you need to do is start Apache and MySQL, and everything will be working. Use the following command to do so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;service apache2 start &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; service mysql start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And there we go, all set up on your Linux machine.&lt;/p&gt;

&lt;h2&gt;
  
  
  Production Environment
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;However, whether you're running a Windows server or a Linux server, the principles for adjusting &lt;code&gt;php.ini&lt;/code&gt; are the same:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Turn off all error display: &lt;code&gt;display_errors = Off&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; Enable error logging: &lt;code&gt;log_errors = On&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; Specify the log path: &lt;code&gt;error_log = /var/log/php_errors.log&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;On Linux, it's recommended to use a log rotation tool to prevent log files from growing too large:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;logrotate &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For Windows servers, it's recommended to regularly use the Event Viewer to check system logs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Important Note:&lt;/strong&gt; 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.&lt;/p&gt;

&lt;p&gt;Thank you for reading my tutorial, and I hope it helps you set up your system for the exact purpose you need.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>php</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
