How to set the document root for a PHP application in Nginx?

To set the document root for a PHP application in Nginx, follow these steps:

  1. Open the Nginx configuration file for your application, usually located at /etc/nginx/sites-available/[your-site].
  2. Inside the server block, locate the root directive. This specifies the location of the root directory for the website.
  3. Update the root directive with the path to your PHP application's directory. For example, if your PHP application is located in /var/www/html/myapp, you would set the root directive as follows: root /var/www/html/myapp;
  4. Save the configuration file and exit.
  5. Restart Nginx to apply the changes: sudo systemctl restart nginx

After these steps, Nginx will use the specified document root directory for your PHP application.