No products in the cart.
Community driven content discussing all aspects of software development from DevOps to design patterns.
Nginx is the DevOps community’s most beloved http web server. And developers love the PHP programming language because it enables them to quickly build and deploy interactive websites.
As such, it’s no wonder that so many sys admins need to configure Nginx, PHP and PHP-FPM on both Linux and Windows servers.
This quick tutorial shows you how to setup PHP and Nginx on Ubuntu Linux with the fastCGI process manager (PHP-FPM) configured as Nginx’s PHP engine.
To setup and configure fastCGI (FPM), PHP, and Nginx on Ubuntu Linux, follow these steps:
Every software install in Ubuntu should start with a quick
apt-get updateand possibly an
To install PHP on Nginx, you must first install Nginx, which you can achieve through a simple
To verify the successful installation and configuration of Nginx on Ubuntu, query the HTTP server’s status:
You can visually verify the Nginx landing page displays on http://localhost:80 of a web browser.
To install PHP for Nginx, use the PHP-FPM library. You can install PHP-FPM support with another
In this instance, we have installed version 8.1 of the PHP and PHP-FPM packages.
A common mistake is to install the PHP, not PHP-FPM package. The problem with this approach is that unlike PHP-FPM, the PHP package installs the Apache HTTP server and its httpd process, which conflicts with Nginx.
PHP requires one of three dependencies to exist on a machine:
A simple PHP install uses the libapache2-mod-php module by default, which requires installation of the full Apache HTTP server software suite. To avoid this, install either the php-cgi or the php-fpm module for Nginx.
After the PHP-FPM setup is complete, check to see if it is running:
With Nginx and PHP-FPM installed, you must edit the default Nginx config file. This allow the PHP FastCGI Process Manager to handle requests that have a .php extension.
The default Nginx file can be opened with any text editor. This command will open it with Nano:
Make the following changes to the Nginx config to support PHP and PHP-FPM on the server:
To configure PHP, Nginx and FTP (fastCGI), you must update the Nginx config file.
The server section of the Nginx, PHP and PHP-FPM config file will look like this when completed. Changes are highlighted in bold:
The following command validates the updated Nginx config file to ensure the edits do not create any syntax errors:
To enable the Nginx PHP fastCGI setup, restart the server:
After the restart, PHP is fully enabled on Nginx. To prove this, create a PHP file in Nginx’s /var/www/html folder and test to ensure the page renders properly on the server.
You may have to change permissions to the folder with a
CHMODcommand in order to create a file in it:
Then add a new PHP file to Nginx’s web hosting directory. The easiest way to do so is with a quick
This creates the most basic PHP file outside of a “Hello World” example you could create. If you dislike the
echocommand, use an editor to create a file named info.php in the /var/www/html folder with the following content:
With the configuration of Nginx, PHP and the PHP-FPM module complete, and a new file named info.php added to the web server, simply open a browser to http://localhost/info.php to test the setup. The PHP info page, attesting to the fact that the install on Nginx of PHP 8.1, will appear.
When PHP, FPM and Nginx are fully configured, the server will be able to render PHP pages.
Let’s quickly review this PHP and Nginx tutorial. These are all of the commands that we used to enable the fastCGI process manager for PHP in Nginx:
And that’s how easy it is to setup and configure fastCGI (FTP), Nginx and PHP support on your web server.
Choosing a programming language is often dictated by the problem the programmer wants to solve and the compute goal that a ...
As general-purpose programming languages, both Scala and Kotlin have a lot to offer. But that doesn't mean their uses cases are ...
A recent architectural change tied to Amazon's Prime Video service could help enterprise application teams understand their own ...
Is a continuous planning strategy right for your organization's DevOps efforts? Know the practical benefits and challenges, as ...
This year's DORA DevOps report echoes the experiences of one organization that has applied them in practice: DORA metrics can be ...
Docker jumps aboard the generative AI bandwagon with a pre-built set of tools to jump-start app development using LLMs and a ...
Amazon CloudWatch and AWS CloudTrail help cloud administrators view configuration history and set up predictive monitoring alerts...
Amazon SageMaker Canvas is a useful machine learning tool for both technical and nontechnical professionals. This tutorial shows ...
AI and ML tools support several use cases in cloud operations, such as security, fault correlation and latency. These best ...
With DAS, privilege access management, AI and other features, SailPoint moves Atlas from an identity governance platform to an ...
Exploitation against CVE-2023-4966 is ongoing, and Mandiant CTO Charles Carmakal warned patching alone is insufficient against ...
One layer of security that all networks and applications need is authentication. Read up on six authentication types, from 2FA to...
Many organizations struggle to manage their vast collection of AWS accounts, but Control Tower can help. The service automates ...
There are several important variables within the Amazon EKS pricing model. Dig into the numbers to ensure you deploy the service ...
AWS users face a choice when deploying Kubernetes: run it themselves on EC2 or let Amazon do the heavy lifting with EKS. See ...
All Rights Reserved, Copyright 2000 - 2023, TechTarget
Do Not Sell or Share My Personal Information