nginx_php
                Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| nginx_php [2022/11/07 12:56] – [Details] admin | nginx_php [2023/01/28 21:10] (current) – [Finish] admin | ||
|---|---|---|---|
| Line 2: | Line 2: | ||
| ===== Credits ===== | ===== Credits ===== | ||
| The original article was published at [[https:// | The original article was published at [[https:// | ||
| - | ===== Details | + | ===== Package Installation | 
| Please refer to the original article for the discussion. | Please refer to the original article for the discussion. | ||
| Line 18: | Line 18: | ||
| apt-get install nginx php-fpm php-apcu | apt-get install nginx php-fpm php-apcu | ||
| </ | </ | ||
| - | The repo doesn' | + | The repo doesn' | 
| < | < | ||
| apt-get install mariadb-client mariadb-server php-mysql phpmyadmin | apt-get install mariadb-client mariadb-server php-mysql phpmyadmin | ||
| Line 25: | Line 25: | ||
| < | < | ||
| export DOMAIN=mydomain.com | export DOMAIN=mydomain.com | ||
| + | export PHP_VER=7.4 | ||
| </ | </ | ||
| - | That way you can copy and paste the commands without substituting your domain name.  Just remember to change that export | + | That way you can copy and paste the commands without substituting your domain name and php version.  Just remember to set the variables to match your system values. | 
| + | < | ||
| + | dpkg -l | grep fpm | ||
| + | </ | ||
| + | It will return something like: | ||
| + | < | ||
| + | ii  php-fpm | ||
| + | ii  php7.3-fpm | ||
| + | </ | ||
| + | So in this instance, set PHP_VER to 7.3. | ||
| This section is identical to the original | This section is identical to the original | ||
| Line 37: | Line 47: | ||
| The backslash at the end of the adduser is a continuation character. | The backslash at the end of the adduser is a continuation character. | ||
| - | Here's where we start to use the DOMAIN | + | ===== Configuration Files ===== | 
| + | Here's where we start to use the DOMAIN | ||
| < | < | ||
| - | The following NEW packages will be installed: | + | cp /etc/php/ | 
| - |  | + | |
| - | php7.3-readline | + | |
| </ | </ | ||
| + | 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 | ||
| + | |||
| + | Otherwise you'll have problems you don't want to have to fix. Same goes for the nginx config file. | ||
| + | |||
| + | If you don' | ||
| + | |||
| + | Highlight and copy this block and paste it directly into your shell. | ||
| < | < | ||
| - | cp /etc/php/ | + | cat >/etc/php/${PHP_VER}/ | 
| - | </ | + | |
| - | So you could edit that file and make some changes, or you could use this one: | + | |
| - | < | + | |
| - | cat >/ | + | |
| ; pool name (' | ; pool name (' | ||
| [${DOMAIN}] | [${DOMAIN}] | ||
| Line 56: | Line 69: | ||
| group = group001 | group = group001 | ||
| ; The address on which to accept FastCGI requests. | ; The address on which to accept FastCGI requests. | ||
| - | ;listen = /var/run/php7.4-fpm-${DOMAIN}.sock | + | ;listen = /var/run/php${PHP_VER}-fpm-${DOMAIN}.sock | 
| - | listen = / | + | listen = / | 
| ; Set permissions for unix socket, if one is used. In Linux, read/write | ; Set permissions for unix socket, if one is used. In Linux, read/write | ||
| listen.owner = user001 | listen.owner = user001 | ||
| Line 85: | Line 98: | ||
| Here's my nginx config. | Here's my nginx config. | ||
| + | Highlight and copy this block and paste it directly into your shell. | ||
| < | < | ||
| cat >/ | cat >/ | ||
| Line 91: | Line 105: | ||
| listen 80; | listen 80; | ||
| server_name www.${DOMAIN}; | server_name www.${DOMAIN}; | ||
| - | return 301 $scheme:// | + | return 301 \$scheme:// | 
| } | } | ||
| server { | server { | ||
| Line 104: | Line 118: | ||
| location / { | location / { | ||
| - | try_files $uri $uri/ / | + | try_files | 
| } | } | ||
| # pass the PHP scripts to FastCGI | # pass the PHP scripts to FastCGI | ||
| location ~ \.php$ { | location ~ \.php$ { | ||
| - | try_files $uri = 404; | + | try_files | 
| fastcgi_split_path_info ^(.+\.php)(/ | fastcgi_split_path_info ^(.+\.php)(/ | ||
| - | # php7.4-fpm : | + | # php${PHP_VER}-fpm : | 
| - | fastcgi_pass unix:/ | + | fastcgi_pass unix:/ | 
| fastcgi_index index.php; | fastcgi_index index.php; | ||
| #                include fastcgi_params; | #                include fastcgi_params; | ||
| Line 140: | Line 154: | ||
| Now create the subdirectories. | Now create the subdirectories. | ||
| < | < | ||
| - | cd ${DOMAIN} | + | mkdir / | 
| + | cd /home/${DOMAIN} | ||
| mkdir logs sessions tmp www | mkdir logs sessions tmp www | ||
| chown -R user001.group001 * | chown -R user001.group001 * | ||
| + | chown user001.group001 / | ||
| </ | </ | ||
| - | To make this a bit more generic, you could define the php version (export | + | ===== Finish ===== | 
| + | < | ||
| + | service nginx restart && service | ||
| + | </ | ||
| + | |||
| + | Test with these commands: | ||
| + | < | ||
| + | cd / | ||
| + | cat >phpinfo.php << | ||
| + | <?php | ||
| + | phpinfo( | ||
| + | ?> | ||
| + | EOF | ||
| + | </ | ||
| + | Now bring up a browser | ||
| + | |||
| + | Where YOUR_DOMAIN is the value you set into ${DOMAIN} earlier. | ||
| + | |||
| + | This is somewhat tested. | ||
| + | |||
| + | 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. | ||
| - | This is untested. | ||
nginx_php.1667822185.txt.gz · Last modified: 2022/11/07 12:56 by admin
                
                