Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Pascal Landau:
Setting up PhpStorm with Xdebug for local development on Docker
Aug 08, 2018 @ 17:44:30

Following up from his previous post about setting up Docker running PHP-FPM and Nginx on Windows 10, Pascal Landau has published the second part of the series taking things a step further and introducing (and integrating) PhpStorm and Xdebug for local development debugging.

In the second part of this tutorial series on developing PHP on Docker we're taking a good hard look at PhpStorm, Xdebug and how to run and debug scripts from within PhpStorm on Docker.

[...] The setup that I am going to use is for demonstration purposes only! I do not recommend that you use it "as is" as your development setup. [...] There will be a another part of this series that will deal with all of those (and some more common) problems and aims at providing a consistent development environment for all developers in a team (regardless of the OS they are using).

He then walks through the process from setup through actual script debugging:

  • setting up the Docker containers/configuration
  • allowing the PHP container to connect over port 2375
  • running a PHP script on this container
  • building a "workspace" container for Xdebug

For each step he provides the configuration changes needed, commands and screenshots of the settings panels to ensure its easy to follow along.

tagged: docker phpfpm nginx debugging phpstorm xdebug tutorial series part2

Link: https://www.pascallandau.com/blog/setup-phpstorm-with-xdebug-on-docker/

Websec.io:
Securing Credentials for PHP with Docker
Jul 24, 2018 @ 16:31:59

On the Websec.io site a new tutorial has been posted (a sort of continuation from this previous article) showing how to keep secrets safe in a PHP and Docker environment without too much overhead.

In a previous post I covered one method you can use to secure the credentials in your PHP application. In that article I provided an example specific to the use of Apache and its envvars handling to read in values and pass them along to the waiting PHP process as $_ENV variables. This in combination with the psecio/secure_dotenv library allowed you to pass along an encryption key that could be used to decrypt values from the application's .env file.

While this works for a flat Apache and PHP environment, the world has moved beyond that basic setup and has moved to using another popular environment building tool: Docker. [...] So, if we move forward with current technology, we need a way to secure our credentials in a Docker-based environment that makes use of PHP-FPM and Nginx. Fortunately there's a relatively simple way to handle this with just a few configuration changes.

The tutorial starts with an overview of what technologies are involved in the environment (Docker, PHP-FPM, Nginx and Vault) and some of the options for storing secrets with Docker. It then gets into the configuration files needed to create the environment: a Docker Composer configuration, the Nginx server definition, the PHP-FPM settings and the .env file that contains the secrets. Using these pieces and some special configuration directives, the secrets are injected into Docker when the containers are built and storing them in-memory rather that on disk.

tagged: tutorial docker secure credentials environment variable nginx phpfpm

Link: https://websec.io/2018/07/22/Docker-Secure-Credentials.html

Pascal Landau:
Setting up PHP, PHP-FPM and NGINX for local development on Docker (for Windows 10)
Jul 09, 2018 @ 18:19:11

On his site Pascal Landau has posted a complete guide to setting up a Docker-based PHP environment on Windows 10 using Nginx and PHP-FPM.

You probably heard from the new kid around the block called "Docker"? You are a PHP developer and would like to get into that, but you didn't have the time to look into it, yet? Then this tutorial is for you!

[...] This is the first part of a (probably) multi-part series on Docker. The next part will explain how to set up PHP in Docker containers in order to work nicely with PHPStorm when using XDebug.

He starts with a brief overview of why he chose to use Docker and the transition from Vagrant. He then breaks up the tutorial into several different sections, one for each area of the environment:

  • setting up Docker
  • creating the PHP CLI container
  • building the web container (PHP-FPM and Nginx)

He "brings it all together", sharing a docker-compose configuration file that sets up all of the services and configurations in one shot. The tutorial comes complete with screenshots and all command line calls to get your environment up and running quickly.

tagged: nginx docker phpfpm windows10 tutorial setup configure

Link: https://www.pascallandau.com/blog/php-php-fpm-and-nginx-on-docker-in-windows-10/

SitePoint PHP Blog:
Apache vs Nginx Performance: Optimization Techniques
Jun 15, 2018 @ 17:22:11

On the SitePoint PHP blog they've posted a tutorial from author Tonino Jankov sharing some techniques you can use to increase the performance of Apache and Nginx when serving up your web applications.

The article starts with some of the basics, introducing both the software and some of the concepts around their use and evaluation:

  • an introduction to Apache and Nginx
  • hardware considerations
  • monitoring
  • testing the systems (benchmarking)

It then starts on the tuning tips, one section for each of the web servers. For Apache it covers changes for the mpm modules, disabling htaccess and browser cache control with mod_expires. On the Nginx side, they mention changing the number of workers created, tuning the keepalive timout and setting up server-side caching.

tagged: apache nginx performance optimize tip tutorial configuration

Link: https://www.sitepoint.com/apache-vs-nginx-performance-optimization-techniques/

Delicious Brains Blog:
Microcaching WordPress in Nginx to Improve Server Requests by 2,400%
Apr 26, 2017 @ 15:18:40

The Delicious Brains has a new tutorial posted sharing a method you can use to setup microcaching in Nginx for your WordPress installation and improve the performance of server requests by a large margin.

We’ve talked a lot about WordPress performance and hosting WordPress here at Delicious Brains. A common theme amongst those articles is the importance of page caching and how it’s arguably the best way to improve the performance of your WordPress site. [...] However, we’ve also alluded to the fact that page caching is difficult to implement on highly dynamic sites.

[...] In these circumstances page caching still has its place but the duration of the cache has to be significantly reduced. This is known as microcaching. Microcaching is a technique where content is cached for a very short period of time, usually in the range of 1-10 seconds. In this article, I’m going to demonstrate how to configure WordPress and bbPress with Nginx FastCGI caching.

They start off with some initial benchmarks performed using the Blitz.io service against a clean WordPress install on a Digital Ocean droplet. The first results are of a test with 100 concurrent users over 60 seconds (with not so great results). Then, using this method in the Nginx configuration, the site is retested resulting in much better performance but with one downfall - the pages are cached and no longer dynamic.

To resolve this they move to the "microcaching" solution, adding the caching to parts of the application that aren't the forum using the "X-Accel-Expires" header sent from WordPress. The post ends with a bit more tweaking to the configuration and some caveats to its use.

tagged: wordpress caching microcaching nginx tutorial dyanmic benchmark

Link: https://deliciousbrains.com/microcaching-wordpress-nginx-improve-server-requests-2400/

Loïc Faugeron:
Super Speed Symfony - nginx
Apr 20, 2016 @ 15:48:49

Loïc Faugeron has continued his series about speeding up Symfony applications and getting the best overall performance you can. In this new post he gets into more detail about tuning a Nginx web server (with PHP-FPM) and the web server's own caching features.

HTTP frameworks, such as Symfony, allow us to build applications that have the potential to achieve Super Speed.

We've already seen a first way to do so (by turning it into a HTTP server), another way would be to put a reverse proxy in front of it. In this article we'll take a Symfony application and demonstrate how to do so using nginx.

He starts by helping you get Nginx and PHP-FPM all set up and running on a Unix-based system (installed via apt-get). He provides a simple configuration including the user to run as and a virtual host for the application. There's a few command line checks to ensure it's working correctly and a bit of benchmarking as a baseline for the performance testing later. He then gets to the caching functionality and gives some of the basics on how it works inside of Nginx itself. He includes a basic caching configuration (caching to files) and adding this to the already created virtual host. Finally he includes sample Symfony code to send the "Cache-Control" header with every request and runs the benchmarks again (resulting in about 140x faster than without the cache).

tagged: tutorial nginx performance symfony speed phpfpm setup configuration cache cachecontrol

Link: https://gnugat.github.io/2016/04/20/super-speed-sf-nginx.html

Jeff Geerling:
Streaming PHP - disabling output buffering in PHP, Apache, Nginx, and Varnish
Apr 06, 2016 @ 18:45:27

In a recent post to his site Jeff Geerling shows you how to disable the output buffering that PHP includes and create "streaming PHP" code similar to Drupal's recently introduced BigPipe handling.

For the past few days, I've been diving deep into testing Drupal 8's experimental new BigPipe feature, which allows Drupal page requests for authenticated users to be streamed and loaded in stages—cached elements (usually the majority of a page) are loaded almost immediately, meaning the end user can interact with the main elements on the page very quickly, then other uncacheable elements are loaded in as Drupal is able to render them.

[...] BigPipe takes advantage of streaming PHP responses (using flush() to flush the output buffer at various times during a page load), but to ensure the stream is delivered all the way from PHP through to the client, you need to make sure your entire webserver and proxying stack streams the request directly, with no buffering.

He decided to try out different configurations to see if he could reproduce the same thing outside of Drupal and - good news, everyone - he found a reliable way. He starts with a basic procedural script that emulates BigPipe and calls a flush inside a loop to push the latest output to the waiting client. While this cooperates on the command line the browser doesn't cooperate the same way. A small tweak helps it work, so he shows how to reproduce this reliably across the full stack - Nginx, Apache and Varnish.

He ends with a quick warning for those using VMWare/VirtualBox about some oddness he experienced in buffering the responses and includes a way to test if it's your script or the VM causing the trouble.

tagged: stream output disable buffering apache nginx varnish tutorial

Link: http://www.jeffgeerling.com/blog/2016/streaming-php-disabling-output-buffering-php-apache-nginx-and-varnish

Geeky Platypus Blog:
Dockerise your PHP application with Nginx and PHP7-FPM
Apr 06, 2016 @ 16:57:58

The Geeky Platypus Blog has a new post showing you exactly how to Dockerise your PHP application with a PHP7-FPM and Nginx setup.

The goal that we will try to achieve is to run a simple PHP application using the official Docker repositories for both PHP and Nginx. There are several docker repositories combining PHP-FPM with Nginx, but depending on the official repositories gives you several benefits, like using a service which is configured by its maintainers and you can always choose between the latest and greatest or different versions of both services, instead of relying on someone else’s choices.

The tutorial assumes you already have both Docker and Docker Compose installed, so do that first if you don't. Then you can follow along with the rest of the steps:

  • Setting up Nginx
  • Adding PHP-FPM
  • Setting up a mount point (in the filesystem) to your code

If all goes well you should have a complete setup of PHP 7 and Nginx running your application. If you'd like to see the complete project for reference, you can find it over on GitHub.

tagged: docker nginx php7fpm tutorial setup configure

Link: http://geekyplatypus.com/dockerise-your-php-application-with-nginx-and-php7-fpm/

Nginx.com:
Maximizing PHP 7 Performance with NGINX, Part I: Web Serving and Caching
Feb 29, 2016 @ 19:55:10

On the Nginx.com site they've posted the first part of a series showing you how to maximize your performance with PHP 7 and this already speedy web server.

PHP is the most popular way to create a server-side Web application, with roughly 80% market share. (ASP.net is a distant second, and Java an even more distant third.) [...] Now the PHP team is releasing a new version, PHP 7 – more than a decade after the introduction of PHP 5. During this time, usage of the web and the demands on websites have both increased exponentially.

[...] This blog post is the first in a two-part series about maximizing the performance of your websites that use PHP 7. Here we focus on upgrading to PHP 7, implementing open source NGINX or NGINX Plus as your web server software, rewriting URLs (necessary for requests to be handled properly), caching static files, and caching dynamic files (also called application caching or microcaching).

They start by looking at why "PHP hits a wall" in its execution in high load situations, stepping through the process it follows to handle each request. They also share some of the common ways PHP developers have combatted these issues including more hardware, better server software and multi-server setups. They then get into the actual tips themselves:

  • Tip 1. Upgrade to PHP 7
  • Tip 2. Choose Open Source NGINX or NGINX Plus
  • Tip 3. Convert Apache Configuration to NGINX Syntax
  • Tip 4. Implement Static File Caching
  • Tip 5. Implement Microcaching

For each tip there's a summary with more information on why they make the suggestion and, for some, how to make the transition happen. In the next part of the series they'll get into reverse proxy servers and a multi-server Nginx implementation to boost performance even more.

tagged: performance php7 nginx series part1 maximize tutorial static cache apache conversion

Link: https://www.nginx.com/blog/maximizing-php-7-performance-with-nginx-part-i-web-serving-and-caching/

Laravel News:
How To: Optimizing SSL on Laravel Forge
Jan 14, 2016 @ 15:27:59

On the Laravel News site there's a post showing you how to optimize your SSL support on Forge, the Laravel-related tool that makes creating and configuring servers simpler. The post focuses on a recently added feature to Forge, support for Let's Encrypt certificates, and other SSL optimizations.

Laravel Forge was recently to allow one-click installations of Let’s Encrypt certificates. It is now easier than ever to have your own SSL!

Let’s take a few extra minutes to optimize your server and help it perform faster and be more secure. In this tutorial we will look at using SSL session caching, HTTP Strict Transport Security (HSTS), and Hypertext Transfer Protocol 2 (HTTP/2).

The example they give are more Force-centric but the SSL changes and optimizations themselves could be used on any server running Nginx. They talk about:

  • the SSL Log-Jam Fix
  • SSL Optimizations (optimized cypher suite, OCSP stapling)
  • HTTP Strict Transport Security (HSTS)
  • HTTP/2

The post ends with a screenshot of how to test the new configuration and how to restart the web service to put it all into effect. There's also a link to an SSL checker that can help you verify things are set up correctly.

tagged: ssl forge laravel tutorial session cache hsts http2 nginx configuration

Link: https://laravel-news.com/2016/01/optimizing-ssl-laravel-forge/


Trending Topics: