现在Debian 12已发布,代号bookworm,中文名字为书虫。

之前写了一个在debian 11上搭建web服务器:https://kzpu.com/archives/4579.html,在Debian 12上搭建方法类似,小幅更新一下。

  • debian 12 bookworm
  • nginx
  • php 8.2
  • mariaDB

一,准备工作

1,确保是用root用户登录来安装。修改root用户登录的方法,修改之后,reboot重启一下系统,后面就用root用户操作所有命令。

su -
nano /etc/ssh/sshd_config

#PermitRootLogin prohibit-password

改为

PermitRootLogin yes

2,视情况修改源。

如果国内的话,修改为国内的源比较快,方法如下。修改为ustc的源,这个在国内是比较快的。

sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list

修改源后,更新一下

apt-get update && apt-get upgrade

3,安装所需要的软件

apt-get install -y wget libcurl4-openssl-dev libevent-dev ca-certificates libssl-dev pkg-config build-essential intltool git autoconf automake libtool autopoint libxml2-dev zip unzip net-tools screen curl lsb-release gnupg2

二,安装php8.2,debian 12软件库里,默认是php8.2,直接安装

apt-get install -y php8.2 php8.2-common php8.2-cli php8.2-fpm php8.2-mysql php8.2-zip php8.2-gd  php8.2-mbstring php8.2-curl php8.2-xml php8.2-bcmath

三,安装nginx

apt-get update
apt-get install -y nginx-full

四,配置php.ini和nginx.conf

sed -i 's/^;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/' /etc/php/8.2/fpm/php.ini

sed -i 's/# server_names_hash_bucket_size/server_names_hash_bucket_size/' /etc/nginx/nginx.conf

五,网站模板配置

cat > /etc/nginx/sites-enabled/default << "EOF"
# Default server
server {
        listen 80 default_server;
        listen [::]:80 default_server;
      
        server_name _;
        root /var/www/default;
        index index.php index.html index.htm default.html;

        location / {
                try_files $uri $uri/ =404;
        }

        # pass the PHP scripts to FastCGI server
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php8.2-fpm.sock;
        }
        # optimize static file serving
        location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
                access_log off;
                log_not_found off;
                expires 30d;
        }

        # deny access to .htaccess files, should an Apache document root conflict with nginx
        location ~ /\.ht {
                deny all;
        }
}
EOF

六,对网站目录进行设置

rm -rf /var/www/html
chown www-data:www-data -R /var/www
chmod g+s -R /var/www/.

mkdir -p /var/www/default

wget -P /var/www/default https://gitee.com/nbweb/dnmp_d/raw/master/p.php

检查一下nginx配置是否正确:

root@debian:~# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

配置正确

重启php和nginx

systemctl restart php8.2-fpm
systemctl restart nginx

七,安装MariaDB-server和MariaDB-client

apt-get install -y mariadb-server mariadb-client

设置mariadb的密码

mysqladmin -u root password "123456"

其中的“123456”换成你自己的密码。

重启mariaDB

systemctl restart mariadb

八,安装phpmyadmin

wget -P /var/www/default https://files.phpmyadmin.net/phpMyAdmin/5.2.1/phpMyAdmin-5.2.1-all-languages.zip
cd /var/www/default
unzip -p phpMyAdmin-*-all-languages.zip
mv phpMyAdmin-*-all-languages phpmyadmin

九,安装完成

打开:ip/p.php,看看php的探针是否能打开

重启应用如下:

重启nginx:systemctl restart nginx

重启php:systemctl restart php8.2-fpm

重启mariadb:systemctl restart mariadb

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注