Nginx Php Fpm 7.2 Laravel


Nginx Php Fpm 7.2 Laravel

Introduction to Nginx

Nginx (pronounced “engine-x”) is a free, open-source web server software. It’s quickly becoming one of the most popular web servers, used by many of the world’s biggest websites such as Facebook, Twitter, WordPress, and more.

Nginx is known for its high performance, stability, rich feature set, simple configuration, and low resource consumption. It is the chosen web server for many of the biggest websites in the world due to its super-fast speed and efficient design. It’s also perfect for server load balancing and reverse proxy configurations.

PHP 7.2 and Laravel

PHP 7.2 is the latest stable version of the PHP programming language. It was released in late 2017 and brings many improvements over the previous 7.1 version. It introduces new features, bug fixes, and performance improvements, making it the perfect choice for modern web applications.

Laravel is a powerful open-source and free PHP framework designed for web applications. It’s easy to use and comes with an endless array of powerful features. It’s one of the most popular frameworks for creating websites and web applications, with many prominent websites and web applications utilizing it.

Combining PHP 7.2 with the Laravel framework is the perfect setup for any modern web application. It provides an up-to-date stack with all of the most powerful features and bug fixes.

Installing Nginx and PHP 7.2

Before we can install Nginx and PHP 7.2, we first need to install the necessary packages. Open a terminal or SSH connection and run the following command:

sudo apt-get update

This command will update the package lists from the various sources defined in the configuration file.

Next, we need to install Nginx and PHP 7.2. We can do this with a single command:

sudo apt-get install nginx php7.2

This command will install Nginx and PHP 7.2, as well as any necessary dependencies. Once the installation is complete, we can start Nginx with the following command:

sudo systemctl start nginx

Nginx is now running and ready to serve our web pages.

Configuring PHP-FPM 7.2

PHP-FPM 7.2 is the process manager for PHP 7.2, and it’s what we’ll be using to serve our PHP requests. We need to configure PHP-FPM to listen on a socket instead of a network port, since it provides the most efficient way to serve PHP requests from Nginx.

First, we need to open the PHP-FPM configuration file and modify it. We can do this with a text editor, such as nano, vim, or emacs. The configuration file is located at /etc/php/7.2/fpm/pool.d/www.conf.

We need to find the [www] section and modify it. We need to change the listen line from 127.0.0.1:9000 to /run/php-fpm7.2.sort.

This tells PHP-FPM to listen on a UNIX socket, instead of a network port. We also need to add the following lines to the [www] section:

  • user = www-data
  • group = www-data
  • listen.mode = 0660

These three lines will configure the user and group that PHP-FPM will run as, as well as the permissions of the socket. Once that’s done, we need to save and close the configuration file.

Next, we need to restart PHP-FPM so that the changes take effect. We can do this with the following command:

sudo systemctl restart php7.2-fpm

PHP-FPM is now configured and ready to serve PHP requests from Nginx.

Configuring Nginx

Once we have Nginx and PHP-FPM installed and configured, we can now configure Nginx to serve our web pages. Nginx requires us to create a “server block” for each website or application we want to serve.

We can create a server block with a text editor such as nano, vim, or emacs. The configuration file is located at /etc/nginx/sites-enabled/default.

We need to modify the configuration file to reflect our application’s settings. Here’s an example of a server block for a Laravel application:

  • server {
  • listen 80;
  • listen [::]:80;
  • root /var/www/example.com/public;
  • index index.php index.html index.htm;
  • server_name example.com www.example.com;
  • location / {
  • try_files $uri $uri/ /index.php?$query_string;

}

# pass the PHP scripts to FastCGI server listening on the Unix socket

  • location ~ .php$ {
  • fastcgi_pass unix:/run/php/php-fpm7.2.sock;
  • fastcgi_index index.php;
  • include fastcgi_params;
  • fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

}

}

Once we’ve configured our server block, we can save and close the file. We then need to restart Nginx for the changes to take effect. We can do this with the following command:

sudo systemctl restart nginx

Nginx is now ready to serve our web page.

Conclusion

In this article we’ve looked at how to install and configure Nginx, PHP 7.2, and Laravel. We’ve seen how to install all of the necessary packages, how to configure PHP-FPM to listen on a Unix socket, and how to create a server block for our website or application.

With the right configuration, Nginx, PHP 7.2, and Laravel can provide a powerful, modern, and efficient web stack for your applications.

FAQs

Q: What is Nginx?

A: Nginx is a free, open-source web server software. It’s quickly becoming one of the most popular web servers, used by many of the world’s biggest websites such as Facebook, Twitter, WordPress, and more.

Q: What is PHP 7.2?

A: PHP 7.2 is the latest stable version of the PHP programming language. It was released in late 2017 and brings many improvements over the previous 7.1 version. It introduces new features, bug fixes, and performance improvements, making it the perfect choice for modern web applications.

Q: What is Laravel?

A: Laravel is a powerful open-source and free PHP framework designed for web applications. It’s easy to use and comes with an endless array of powerful features. It’s one of the most popular frameworks for creating websites and web applications, with many prominent websites and web applications utilizing it.

Q: How do I install Nginx?

A

Leave a Reply

Your email address will not be published. Required fields are marked *