先贴两个官方源
debian9 官方源
deb http://deb.debian.org/debian/ stretch main
deb-src http://deb.debian.org/debian/ stretch main
deb http://security.debian.org/ stretch/updates main
deb-src http://security.debian.org/ stretch/updates main
deb http://deb.debian.org/debian/ stretch-updates main
deb-src http://deb.debian.org/debian/ stretch-updates main
debian10 官方源
deb http://deb.debian.org/debian/ buster main
deb-src http://deb.debian.org/debian/ buster main
deb http://security.debian.org/debian-security buster/updates main contrib
deb-src http://security.debian.org/debian-security buster/updates main contrib
deb http://deb.debian.org/debian/ buster-updates main contrib
deb-src http://deb.debian.org/debian/ buster-updates main contrib
Debian9 以上默认内核应该都是 4.9 以上了,所以可以在开始之前先开一波 BBR,优化下网络:
echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf
sysctl -p
1.一些报错先提前解决
先更新软件源,更新软件
apt update
apt upgrade
报错 1
gnupg, gnupg2 and gnupg1 do not seem to be installed, but one of them is required for this operation
安装
apt-get install -y gnupg2
报错 2
apt-get update
E: 无法找到获取软件包的渠道 /usr/lib/apt/methods/https 所需的驱动程序。
N: 请检查是否安装了 apt-transport-https 软件包
E: 无法下载 https://mariadb.mirror.serveriai.lt/repo/10.5/debian/dists/stretch/InRelease
E: 部分索引文件下载失败。如果忽略它们,那将转而使用旧的索引文件。
安装
apt-get install apt-transport-https
2.安装 Mriadb
查看 APT 存储库 mariadb 版本
apt show mariadb-server
MariaDB 10.1
是默认 Debian 9 stretch
存储库上的当前可用版本。
MariaDB 10.3
是默认 Debian 10 Buster
存储库上的当前可用版本。
安装自带的版本直接
apt update
apt-get install mariadb-server
安装最新 10.5 版本
Mariadb 官网选择对应版本根据提示安装
链接
MariaDB - Setting up MariaDB Repositories - MariaDB
进入后选择对应版本后如下
执行过程过出现上面那些报错已经先解决了
我选择的是 debian9 安装 10.5 版本
以下是要运行以将 MariaDB 添加到系统的命令:
sudo apt-get install software-properties-common dirmngr
sudo apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'
sudo add-apt-repository 'deb [arch=amd64,arm64,i386,ppc64el] https://mariadb.mirror.serveriai.lt/repo/10.5/debian stretch main'
导入密钥并添加存储库后,可以使用以下功能安装 MariaDB:
sudo apt-get update
sudo apt-get install mariadb-server
您还可以创建自定义 MariaDB 源.list 文件。为此,请将以下内容复制并粘贴到*/etc/apt/sources.d*/(我们建议命名文件 MariaDB.list 或类似内容)下的文件中,或将其添加到您的 /etc/apt/sources.list 文件的底部。
# MariaDB 10.5 repository list - created 2020-12-19 02:11 UTC
# http://downloads.mariadb.org/mariadb/repositories/
deb [arch=amd64,arm64,i386,ppc64el] https://mariadb.mirror.serveriai.lt/repo/10.5/debian stretch main
deb-src https://mariadb.mirror.serveriai.lt/repo/10.5/debian stretch main
3.安装 Nginx
Debian9 的源默认只能安装到 1.10 版本
Debian10 的源默认只能安装到 1.14 版本
我们要安装新一点的版本
vi /etc/apt/sources.list
Debian9 写入
deb http://nginx.org/packages/debian/ stretch nginx
deb-src http://nginx.org/packages/debian/ stretch nginx
Debian10 写入
deb http://nginx.org/packages/debian/ buster nginx
deb-src http://nginx.org/packages/debian/ buster nginx
添加 key 不然安装的时候出现 GPG 签名报错:
wget http://nginx.org/keys/nginx_signing.key
apt-key add nginx_signing.key
更新软件并源查看版本
apt update
apt show nginx
Package: nginx
Version: 1.18.0-2~stretch
安装
apt install nginx
4.安装 PHP
Debian 9 自带 PHP7.0
apt-get install php7.0 php7.0-cli php7.0-common php7.0-curl php7.0-fpm php7.0-gd php7.0-mysql php7.0-opcache php7.0-xml php7.0-xmlrpc php7.0-sqlite3 php7.0-mbstring
Debian 10 自带 PHP7.3
apt-get install php7.3 php7.3-cli php7.3-common php7.3-curl php7.3-fpm php7.3-gd php7.3-mysql php7.3-opcache php7.3-xml php7.3-xmlrpc php7.3-sqlite3 php7.3-mbstring
安装完成之后记得启动一下 FPM
systemctl start php7.0-fpm
systemctl start php7.3-fpm
安装最新版 PHP7.4
依次输入
apt -y install lsb-release apt-transport-https ca-certificates
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php.list
apt update
apt-get install php7.4 php7.4-cli php7.4-common php7.4-curl php7.4-fpm php7.4-gd php7.4-mysql php7.4-opcache php7.4-xml php7.4-xmlrpc php7.4-sqlite3 php7.4-mbstring
启动
systemctl start php7.4-fpm
php -v
查看版本
PHP 7.4.13 (cli) (built: Nov 30 2020 20:40:50) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.13, Copyright (c), by Zend Technologies
安装 php7.4 必要的扩展
apt install php7.4-dev #phpize需要
apt install php-pear #pecl需要
apt install php7.4-fpm php7.4-mysql php7.4-curl php7.4-json php7.4-mbstring php7.4-xml php7.4-intl
安装可选扩展
apt install php7.4-gd
apt install php7.4-soap
apt install php7.4-gmp
apt install php7.4-odbc
apt install php7.4-pspell
apt install php7.4-bcmath
apt install php7.4-enchant
apt install php7.4-ldap
apt install php7.4-opcache
apt install php7.4-readline
apt install php7.4-sqlite3
apt install php7.4-xmlrpc
apt install php7.4-bz2
apt install php7.4-interbase
apt install php7.4-pgsql
apt install php7.4-recode
apt install php7.4-sybase
apt install php7.4-xsl
apt install php7.4-cgi
apt install php7.4-dba
apt install php7.4-phpdbg
apt install php7.4-snmp
apt install php7.4-tidy
apt install php7.4-zip*
注:这个 7.0.30 的 FPM 监听方式已经从之前的 127.0.0.1:9000
改为了 /run/php/php7.0-fpm.sock
所以接下来我们在编辑 Nginx 配置文件的时候需要注意一下。
5.搭建环境测试
先来安装一个 phpMyAdmin
apt-get install unzip
cd /usr/share/nginx/
wget https://files.phpmyadmin.net/phpMyAdmin/4.8.2/phpMyAdmin-4.8.2-all-languages.zip
unzip phpMyAdmin-4.8.2-all-languages.zip
rm -rf phpMyAdmin-4.8.2-all-languages.zip
mv phpMyAdmin-4.8.2-all-languages phpmyadmin
新建一个 Nginx 配置文件:
vi /etc/nginx/conf.d/phpmyadmin.conf
server {
listen 2333;
server_name 192.168.31.22;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/phpmyadmin;
index index.html index.htm index.php;
}
location ~ \.php$ {
root /usr/share/nginx/phpmyadmin;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/phpmyadmin$fastcgi_script_name;
include fastcgi_params;
}
}
systemctl restart nginx
访问 http://IP:2333
再来安装一个 WordPress:
cd /usr/share/nginx/
wget https://cn.wordpress.org/wordpress-4.9.4-zh_CN.zip
unzip wordpress-4.9.4-zh_CN.zip
rm -rf wordpress-4.9.4-zh_CN.zip
新建一个 Nginx 配置文件:
nano /etc/nginx/conf.d/wordpress.conf
server {
listen 81;
server_name 172.104.111.195;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/wordpress;
index index.html index.htm index.php;
include /etc/nginx/conf.d/rewrite/wordpress.conf;
}
location ~ \.php$ {
root /usr/share/nginx/wordpress;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/wordpress$fastcgi_script_name;
include fastcgi_params;
}
}
再新建一个 WordPress 的伪静态配置文件:
mkdir -p /etc/nginx/conf.d/rewrite/
vi /etc/nginx/conf.d/rewrite/wordpress.conf
写入伪静态规则:
location / {
try_files $uri $uri/ /index.php?$args;
}
重要!最后把 wordpress 的目录所有者改为 www-data(在 Debian9 中,PHP 默认以 www-data 用户运行)
chown -R www-data:www-data wordpress
520 错误网关
出现此错误是由于权限不足
vim /etc/nginx/nginx.conf
将运行用户改为 root
user root;
你可能会用到的配置文件
Nginx 错误日志:/var/log/nginx/error.log
Nginx 主配置文件:/etc/nginx/nginx.conf
Nginx 站点配置文件:/etc/nginx/conf.d/
Nginx 站点目录:/usr/share/nginx/
PHP-FPM 配置文件:/etc/php/7.0/fpm/pool.d/www.conf
PHP.INI 配置文件:/etc/php/7.0/fpm/php.ini
MySQL 主配置文件:/etc/mysql/my.cnf
如果不想用这个环境了,想删除环境:
apt-get autoremove --purge nginx
apt-get autoremove --purge mysql-server
参考:https://lala.im/3894.html
https://www.sooele.com/4156.html
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于