How to run php on Nginx server?

How to run php on Nginx server?

February 6, 2019
3 min read
961 views
0

php on Nginx server

PHP is an open source server scripting language used for creating dynamic, powerful web applications and websites. PHP is a widely-used, free, and efficient alternative to competitors such as Microsoft’s ASP.

NGINX is open source software for web serving, reverse proxying, caching, load balancing, media streaming, and more. It started out as a web server designed for maximum performance and stability. In addition to its HTTP server capabilities, NGINX can also function as a proxy server for email (IMAP, POP3, and SMTP) and a reverse proxy and load balancer for HTTP, TCP, and UDP servers.

Here, we show how to setup Nginx web server environment with PHP support.

Let see how -

Install Nginx Web Server

  • Commands: sudo apt install nginx

  • After installing Nginx, the commands below can be used to stop, start and enable Nginx service to always startup when the server boots up.

  • Commands:

sudo systemctl stop nginx.service

sudo systemctl start nginx.service

sudo systemctl enable nginx.service

Install PHP-FPM  and Related Modules

  • After installing Nginx above, run the commands below to install PHP-FPM and related PHP modules. PHP-FPM is a version for Nginx web server while PHP is Apache2. There are many PHP modules that perform different functions... however, there are some important ones that are always needed when developing PHP based websites. The line will allow PHP to function with many popular PHP based websites and applications.

  • Commands:

sudo apt-get install php-fpm php-mcrypt php-cli php-mysql php-gd php-imagick php-recode php-tidy php-xmlrpc

Configure Nginx PHP Settings

  • Now that Nginx and PHP are installed, you may want to configure Nginx to use PHP properly. The default Nginx PHP configuration file is located at /etc/php/7.x/fpm/php.ini

  • The X in the location will be 0 or 1 depending on the php version installed. Open PHP Nginx configuration file by running the commands.

  • Commands:

sudo nano /etc/php/7.1/fpm/php.ini

  • Then edit the file to suit your environments.

  • Next, open the Nginx site configuration file… by default it’s stored at /etc/nginx/sites-available/default

  • If you have a custom file, then edit it to enable Nginx PHP support. Run the commands below to open Nginx default site configuration file.

  • Commands:

sudo nano /etc/nginx/sites-available/default

  • Then make uncomment the highlighted lines to enable Nginx PHP support.

Test PHP-FPM Setup

  • At this point, Nginx and PHP-FPM should be installed and ready.. to test your Nginx PHP settings, create a blank file.

  • Then add the line in the file and save.

  • Save the file and open your browser and browse to the server name or IP address followed by phpinfo.php

  • Now, you’ve successfully installed and configured.

Was this article helpful?Vote to let the author know
0
Share this article

Loading comments...

Related Articles

Why Proactive Technology Management Matters for Growing Businesses

Why Proactive Technology Management Matters for Growing Businesses

Proactive technology management helps businesses prepare for these demands rather than simply responding when something goes wrong. By regularly reviewing systems, identifying risks and planning improvements, growing companies can build a stronger technology foundation for the future.

5 views
Read More
Read full article: Why Proactive Technology Management Matters for Growing Businesses
Free AI Tools Every Developer Should Try in 2026

Free AI Tools Every Developer Should Try in 2026

The good news is that developers are better served by genuinely free options than almost any other audience. This article covers the categories where free tools are actually usable, and what to watch out for.

7 views
Read More
Read full article: Free AI Tools Every Developer Should Try in 2026
The Weld Decides The Rating

The Weld Decides The Rating

The component rating covers the component. What determines how much the installed anchor can actually take is the weld holding it there and the structure underneath it, and neither of those came from the manufacturer

64 views
Read More
Read full article: The Weld Decides The Rating