User Tools

Site Tools


nginx_php

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
nginx_php [2022/11/07 18:18] – [Details] adminnginx_php [2023/01/28 21:10] (current) – [Finish] admin
Line 2: Line 2:
 ===== Credits ===== ===== Credits =====
 The original article was published at [[https://raspberry-hosting.com/en/faq/how-install-nginx-php-fpm-raspberry-pi|Raspberry Hosting]]. It was written for an earlier Raspberry Pi OS.  I've since installed nginx and php on the latest OS, Bullseye.  The kernel was last compiled on October 26, 2022. The original article was published at [[https://raspberry-hosting.com/en/faq/how-install-nginx-php-fpm-raspberry-pi|Raspberry Hosting]]. It was written for an earlier Raspberry Pi OS.  I've since installed nginx and php on the latest OS, Bullseye.  The kernel was last compiled on October 26, 2022.
-===== Details =====+===== Package Installation =====
 Please refer to the original article for the discussion.  I'd repost it but I suspect I'd get in trouble for copyright violations.   Please refer to the original article for the discussion.  I'd repost it but I suspect I'd get in trouble for copyright violations.  
  
Line 47: Line 47:
 The backslash at the end of the adduser is a continuation character.  The adduser command ends with the "user001" This wiki doesn't wrap, so without the backslash you wouldn't see the entire command without scrolling. The backslash at the end of the adduser is a continuation character.  The adduser command ends with the "user001" This wiki doesn't wrap, so without the backslash you wouldn't see the entire command without scrolling.
  
 +===== Configuration Files =====
 Here's where we start to use the DOMAIN and PHP_VER variables we set earlier.   Here's where we start to use the DOMAIN and PHP_VER variables we set earlier.  
 <code> <code>
-cp /etc/php/${PHP_VER}/fpm/pool.d/www.conf /etc/php/${PHP_VER}/fpm/pool.d/${MYDOMAIN}.conf+cp /etc/php/${PHP_VER}/fpm/pool.d/www.conf /etc/php/${PHP_VER}/fpm/pool.d/${DOMAIN}.conf
 </code> </code>
-So you could edit that file and make some changes, or you could use this one. WARNING if you are tempted  to simply copy/paste the configuration data don't unless your understand here documents and escaping special characters.  If you don't/can't write to the pool.d file, change the file name to something else like /tmp/sample and let the cat command write the file.  To do that change the first line of this script to  cat >/tmp/sample.conf <<EOF+So you could edit the ${DOMAIN}.conf file and make some changes, or you could use this script to generate it 
 + 
 +WARNING if you are tempted  to simply copy/paste the configuration data rather than copy the entire code block, don't unless you understand here documents and escaping special characters.  
  
 Otherwise you'll have problems you don't want to have to fix.  Same goes for the nginx config file. Otherwise you'll have problems you don't want to have to fix.  Same goes for the nginx config file.
 +
 +If you don't/can't write to the pool.d file, change the file name to something else like /tmp/sample and let the cat command write the file.  To do that change the first line of this script to  'cat >/tmp/sample.conf <<EOF' then figure out how to get that data into the /etc/php/${PHP_VER}/fpm/pool.d/${DOMAIN}.conf file.  This is the way you would do it if you are attempting to run these instructions as a normal user.
 +
 +Highlight and copy this block and paste it directly into your shell.
 <code> <code>
-cat >/etc/php/${PHP_VER}/fpm/pool.d/${MYDOMAIN}.conf <<EOF+cat >/etc/php/${PHP_VER}/fpm/pool.d/${DOMAIN}.conf <<EOF
 ; pool name ('www' here) ; pool name ('www' here)
 [${DOMAIN}] [${DOMAIN}]
Line 91: Line 98:
  
 Here's my nginx config.  Adjust as you need: Here's my nginx config.  Adjust as you need:
 +Highlight and copy this block and paste it directly into your shell.
 <code> <code>
 cat >/etc/nginx/sites-available/${DOMAIN}.conf  <<EOF cat >/etc/nginx/sites-available/${DOMAIN}.conf  <<EOF
Line 146: Line 154:
 Now create the subdirectories. Now create the subdirectories.
 <code> <code>
 +mkdir /home/${DOMAIN}
 cd /home/${DOMAIN} cd /home/${DOMAIN}
 mkdir logs sessions tmp www mkdir logs sessions tmp www
 chown -R user001.group001 * chown -R user001.group001 *
 +chown user001.group001 /home/${DOMAIN}
 </code> </code>
  
-To make this a bit more generic, you could define the php version (export PHP_VER=${PHP_VER}) and then change all the versions to use the variable, PHP_VER as we did with the domain.+===== Finish ===== 
 +<code> 
 +service nginx restart && service php${PHP_VER}-fpm restart 
 +</code> 
 + 
 +Test with these commands: 
 +<code> 
 +cd /home/${DOMAIN}/www 
 +cat >phpinfo.php <<EOF 
 +<?php 
 +phpinfo( )
 +?> 
 +EOF 
 +</code> 
 +Now bring up a browser and go to http://YOUR_DOMAIN/phpinfo.php. 
 + 
 +Where YOUR_DOMAIN is the value you set into ${DOMAIN} earlier. 
 + 
 +This is somewhat tested
  
-This is untested +This was used to install nginx/php on a 32 bit Bullseye Pi4 on 28 January 2023, when I found a couple of bugs and fixed them
  
  
nginx_php.1667841505.txt.gz · Last modified: 2022/11/07 18:18 by admin