nginx_php
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
nginx_php [2022/11/07 11:40] – created 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:// | ||
+ | ===== Package Installation ===== | ||
+ | Please refer to the original article for the discussion. | ||
+ | |||
+ | It should be obvious but you need to be root to run these commands. | ||
+ | < | ||
+ | sudo -i | ||
+ | </ | ||
+ | |||
+ | Pretty much every time you are about to install from the repo, you need to do this: | ||
+ | < | ||
+ | apt-get update && apt-get -y upgrade | ||
+ | </ | ||
+ | The name of the package has changed from php-apc to php-apcu so: | ||
+ | < | ||
+ | apt-get install nginx php-fpm php-apcu | ||
+ | </ | ||
+ | The repo doesn' | ||
+ | < | ||
+ | apt-get install mariadb-client mariadb-server php-mysql phpmyadmin | ||
+ | </ | ||
+ | Before we go any farther, let me add something: | ||
+ | < | ||
+ | export DOMAIN=mydomain.com | ||
+ | export PHP_VER=7.4 | ||
+ | </ | ||
+ | That way you can copy and paste the commands without substituting your domain name and php version. | ||
+ | < | ||
+ | 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 | ||
+ | < | ||
+ | addgroup --gid 10000 group001 | ||
+ | adduser --home / | ||
+ | | ||
+ | </ | ||
+ | |||
+ | The backslash at the end of the adduser is a continuation character. | ||
+ | |||
+ | ===== Configuration Files ===== | ||
+ | Here's where we start to use the DOMAIN and PHP_VER variables we set earlier. | ||
+ | < | ||
+ | cp / | ||
+ | </ | ||
+ | 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. | ||
+ | < | ||
+ | cat >/ | ||
+ | ; pool name (' | ||
+ | [${DOMAIN}] | ||
+ | ; Unix user/group of processes | ||
+ | user = user001 | ||
+ | group = group001 | ||
+ | ; The address on which to accept FastCGI requests. | ||
+ | ;listen = / | ||
+ | listen = / | ||
+ | ; Set permissions for unix socket, if one is used. In Linux, read/write | ||
+ | listen.owner = user001 | ||
+ | listen.group = group001 | ||
+ | listen.mode = 0666 | ||
+ | ; Default Value: nothing is defined by default except the values in php.ini ... | ||
+ | ; add php.ini admin values | ||
+ | php_admin_value[sendmail_path] = / | ||
+ | php_flag[display_errors] = off | ||
+ | php_admin_value[error_log] = / | ||
+ | php_admin_flag[log_errors] = on | ||
+ | php_admin_value[upload_tmp_dir] = / | ||
+ | php_admin_value[session.save_path] = / | ||
+ | php_admin_value[open_basedir] = / | ||
+ | php_admin_value[mail.log] = / | ||
+ | php_admin_value[memory_limit] = 64M | ||
+ | php_admin_value[post_max_size] = 18M | ||
+ | php_admin_value[max_execution_time] = 60 | ||
+ | php_admin_value[allow_url_fopen] = Off | ||
+ | php_admin_value[upload_max_filesize] = 18M | ||
+ | php_admin_value[date.timezone] = America/ | ||
+ | pm = ondemand | ||
+ | pm.max_children = 4 | ||
+ | EOF | ||
+ | </ | ||
+ | You may want to change a few of those settings. | ||
+ | |||
+ | Here's my nginx config. | ||
+ | Highlight and copy this block and paste it directly into your shell. | ||
+ | < | ||
+ | cat >/ | ||
+ | # redirect www | ||
+ | server { | ||
+ | listen 80; | ||
+ | server_name www.${DOMAIN}; | ||
+ | return 301 \$scheme:// | ||
+ | } | ||
+ | server { | ||
+ | listen | ||
+ | |||
+ | # root dir of your pages | ||
+ | root / | ||
+ | |||
+ | index index.php index.html index.htm; | ||
+ | |||
+ | server_name ${DOMAIN}; | ||
+ | |||
+ | location / { | ||
+ | try_files \$uri \$uri/ / | ||
+ | } | ||
+ | |||
+ | # pass the PHP scripts to FastCGI | ||
+ | location ~ \.php$ { | ||
+ | try_files \$uri = 404; | ||
+ | fastcgi_split_path_info ^(.+\.php)(/ | ||
+ | # php${PHP_VER}-fpm : | ||
+ | fastcgi_pass unix:/ | ||
+ | fastcgi_index index.php; | ||
+ | # include fastcgi_params; | ||
+ | include fastcgi.conf; | ||
+ | } | ||
+ | |||
+ | # deny access to .htaccess files, if Apache' | ||
+ | location ~ /\.ht { | ||
+ | deny all; | ||
+ | } | ||
+ | |||
+ | # error and access logs | ||
+ | error_log / | ||
+ | access_log / | ||
+ | |||
+ | # other converting rewrite rules search on: | ||
+ | # http:// | ||
+ | # | ||
+ | |||
+ | } | ||
+ | EOF | ||
+ | ln -s / | ||
+ | rm -f / | ||
+ | </ | ||
+ | Note: I had to replace the " | ||
+ | |||
+ | Now create the subdirectories. | ||
+ | < | ||
+ | mkdir / | ||
+ | cd / | ||
+ | mkdir logs sessions tmp www | ||
+ | chown -R user001.group001 * | ||
+ | chown user001.group001 / | ||
+ | </ | ||
+ | |||
+ | ===== Finish ===== | ||
+ | < | ||
+ | service nginx restart && service php${PHP_VER}-fpm restart | ||
+ | </ | ||
+ | |||
+ | Test with these commands: | ||
+ | < | ||
+ | cd / | ||
+ | cat > | ||
+ | <?php | ||
+ | phpinfo( ); | ||
+ | ?> | ||
+ | EOF | ||
+ | </ | ||
+ | Now bring up a browser and go to http:// | ||
+ | |||
+ | 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. | ||
+ | |||
+ |
nginx_php.1667817630.txt.gz · Last modified: 2022/11/07 11:40 by admin