How to run php on Nginx server?

How to run php on Nginx server?

February 6, 2019
3 min read
959 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

Trading platforms compared: which one fits your style

Trading platforms compared: which one fits your style

That's the usual shape of the mistake. People compare platforms by feature count, the way you'd compare phones in a shop, when the useful question is narrower. What do you actually do in a normal week, and which software makes that loop faster and less error prone?

3 views
Read More
Read full article: Trading platforms compared: which one fits your style
Growing Your Business Through Better SEO

Growing Your Business Through Better SEO

SEO requires regular monitoring because search results are constantly changing. Competitors publish new content, websites are updated, search behavior changes, and search engines continue to improve how they evaluate pages.

2 views
Read More
Read full article: Growing Your Business Through Better SEO
DomDetailer: A Practical Guide to Domain Research, Backlink Metrics, and Bulk Analysis

DomDetailer: A Practical Guide to Domain Research, Backlink Metrics, and Bulk Analysis

Discover how DomDetailer simplifies domain research by bringing Moz, Majestic, and backlink data together in one place. Learn how to evaluate expired and auction domains using authority metrics, referring domains, Trust Flow, Citation Flow, topical signals, and a simple one-credit-per-domain pricing model.

4 views
Read More
Read full article: DomDetailer: A Practical Guide to Domain Research, Backlink Metrics, and Bulk Analysis