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

The Steps Behind Pricing a Kelvin Grove Home for Sale

The Steps Behind Pricing a Kelvin Grove Home for Sale

. Before selling in Kelvin Grove, look at what buyers have paid for comparable homes and what a range of sale prices would mean for your finances. A sound pricing plan accounts for both without assuming the market will cover every cost.

4 views
Read More
Read full article: The Steps Behind Pricing a Kelvin Grove Home for Sale
Why Do Modern Smartphones Have So Many Cameras?

Why Do Modern Smartphones Have So Many Cameras?

Ever wondered why your phone has 2, 3, or even 4 cameras? It's not marketing — it's physics. Here's the real story behind periscope zoom, bokeh, and how NASA's space telescope tech ended up in your pocket.

12 views
Read More
Read full article: Why Do Modern Smartphones Have So Many Cameras?