Debian做网站服务器用途非常广泛,有很多机房的服务器都是Linux系统,所以web服务器无处不在。今天就试试在Debian系统上在线安装web服务器。

环境如下:

  • Debain buster 10.3
  • ngixn
  • PHP7.3
  • MariaDB

一,准备工作

  1. 修改用root用户登录,修改/etc/ssh/sshd_config文件,把#PermitRootLogin prohibit-password改为PermitRootLogin yes
  2. 用ip address查看ip地址
  3. 修改源,用自己认为比较快的源地址,输入下面几行,然后更新一下源,命令:

    apt-get update && apt-get upgrade

cat > /etc/apt/sources.list << "EOF"

deb https://mirrors.ustc.edu.cn/debian/ buster main contrib non-free
deb-src https://mirrors.ustc.edu.cn/debian/ buster main contrib non-free

deb https://mirrors.ustc.edu.cn/debian/ buster-updates main contrib non-free
deb-src https://mirrors.ustc.edu.cn/debian/ buster-updates main contrib non-free

deb https://mirrors.ustc.edu.cn/debian-security/ buster/updates main contrib non-free
deb-src https://mirrors.ustc.edu.cn/debian-security/ buster/updates main contrib non-free

EOF

         4.安装需要的软件:

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

二,安装php7.3

apt-get install -y php7.3 php7.3-common php7.3-cli php7.3-fpm php7.3-json php7.3-mysql php7.3-zip php7.3-gd  php7.3-mbstring php7.3-curl php7.3-xml php7.3-bcmath

三,安装nginx

先添加nginx官方的源,这样可以安装最新版

echo "deb http://nginx.org/packages/mainline/debian `lsb_release -cs` nginx" | tee /etc/apt/sources.list.d/nginx.list

下载安装nginx的key

curl -fsSL https://nginx.org/keys/nginx_signing.key | apt-key add -
apt-key fingerprint ABF5BD827BD9BF62

安装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/7.3/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/php7.3-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配置是否正确:

nginx -t

重启php和nginx

systemctl restart php7.3-fpm
systemctl restart nginx

七,安装MariaDB-server和MariaDB-client

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

设置mariadb的密码

mysqladmin -u root password "123456"

mysqladmin -u root password "123456"

重启

systemctl restart mysql

八,安装phpmyadmin

wget -P /var/www/default https://files.phpmyadmin.net/phpMyAdmin/5.0.2/phpMyAdmin-5.0.2-all-languages.tar.gz
cd /var/www/default
tar zxf phpMyAdmin-5.0.2-all-languages.tar.gz
mv phpMyAdmin-5.0.2-all-languages phpmyadmin

九,安装完成

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

发表回复

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