0178.html 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <!DOCTYPE html>
  2. <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title>Install and Configure nginx with PHP on Linux</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <meta charset="UTF-8">
  7. <meta name="keywords" content="Browser Based,Home Lab,Home Lab Ideas,Install Guide,Self-Hosted,Web Based,Web Based Tools,Debian,Developer,Development,Free Software,Homelab,Linux,Nginx,PHP,PHP Developer,PHP Development,PHP Nginx Install Guide,PHP Nginx Installation Guide,Web Server,Web Server Administration,How To,Tutorial,i12bretro">
  8. <meta name="author" content="i12bretro">
  9. <meta name="description" content="Install and Configure nginx with PHP on Linux">
  10. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  11. <meta name="revised" content="08/08/2022 05:05:56 AM" />
  12. <link rel="icon" type="image/x-icon" href="includes/favicon.ico">
  13. <script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
  14. <script type="text/javascript" src="includes/js/steps.js"></script>
  15. <link href="css/steps.css" rel="stylesheet" type="text/css" />
  16. </head>
  17. <body>
  18. <div id="gridContainer">
  19. <div class="topMargin"></div>
  20. <div id="listName" class="topMargin">
  21. <h1>Install and Configure nginx with PHP on Linux</h1>
  22. </div>
  23. <div></div>
  24. <div id="content">
  25. <ol>
  26. <li>Log into the Linux device</li>
  27. <li>Run the following commands in a terminal window
  28. <div class="codeBlock"># update software repositories<br />
  29. sudo apt update<br />
  30. # install available software updates<br />
  31. sudo apt upgrade -y<br />
  32. # install nginx and php<br />
  33. sudo apt install nginx php7.3-fpm php7.3-common php7.3-mysql php7.3-gmp php7.3-curl php7.3-intl php7.3-mbstring php7.3-xmlrpc php7.3-gd php7.3-xml php7.3-cli php7.3-zip php7.3-soap php7.3-imap<br />
  34. # set the owner of the web root<br />
  35. sudo chown -R www-data /usr/share/nginx/html<br />
  36. # edit the nginx config to add PHP support<br />
  37. sudo nano /etc/nginx/conf.d/default.conf</div>
  38. </li>
  39. <li>Paste the following configuration into default.conf
  40. <p>server {<br />
  41. &nbsp; &nbsp; listen 80;<br />
  42. &nbsp; &nbsp; listen [::]:80;</p>
  43. <p>&nbsp; &nbsp; root /usr/share/nginx/html;<br />
  44. &nbsp; &nbsp; index index.php index.html index.htm;</p>
  45. <p>&nbsp; &nbsp; server_name localhost;</p>
  46. <p>&nbsp; &nbsp; location / {<br />
  47. &nbsp; &nbsp; &nbsp; &nbsp; try_files $uri $uri/ =404;<br />
  48. &nbsp; &nbsp; }</p>
  49. <p>&nbsp; &nbsp; location ~ \.php$ {<br />
  50. &nbsp; &nbsp; &nbsp; &nbsp; include snippets/fastcgi-php.conf;<br />
  51. &nbsp; &nbsp; &nbsp; &nbsp; fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;<br />
  52. &nbsp; &nbsp; }<br />
  53. }</p>
  54. </li>
  55. <li>Press CTRL+O, Enter, CTRL+X to write the changes to default.conf</li>
  56. <li>Continue with the following commands
  57. <div class="codeBlock"># restart nginx service<br />
  58. sudo systemctl restart nginx<br />
  59. # create a test phpinfo file<br />
  60. sudo nano /usr/share/nginx/html/phpinfo.php</div>
  61. </li>
  62. <li>Paste the following into the .php page
  63. <p>&lt;?php<br />
  64. &nbsp; &nbsp; phpinfo();<br />
  65. ?&gt;</p>
  66. </li>
  67. <li>Press CTRL+O, Enter, CTRL+X to write the changes to phpinfo.php</li>
  68. <li>Open a web browser and navigate to http://DNSorIP/phpinfo.php</li>
  69. </ol> </div>
  70. </div>
  71. </body>
  72. </html>