1. 更新系统
sudo apt update
sudo apt upgrade
2. 安装 Nginx
sudo apt install nginx
3. 安装 MariaDB (作为 MySQL 的替代)
sudo apt install mariadb-server mariadb-client
初始化 MariaDB 数据库(可选)
sudo mysql_secure_installation
4. 安装 PHP 和必要的扩展
# 查询php支持的扩展
apt search php apt search php7
# 首先,安装 PHP 和常用的扩展:
sudo apt install php7.4 php7.4-fpm php7.4-mysql php7.4-xml php7.4-mbstring php7.4-redis php7.4-cli php7.4-common
5. 安装 Redis 扩展
sudo apt install php-redis
php -m | grep redis
6. 安装 Yaf 扩展
# 安装 PECL 和 PHP 开发包
sudo apt install php-pear php-dev
# 使用 PECL 安装 Yaf 扩展
sudo pecl install yaf
# 添加 Yaf 扩展到 PHP 配置文件
echo "extension=yaf.so" | sudo tee -a /etc/php/7.4/fpm/php.ini
echo "extension=yaf.so" | sudo tee -a /etc/php/7.4/cli/php.ini
# 重启 PHP-FPM 服务
sudo systemctl restart php7.4-fpm
# 验证 Yaf 扩展是否成功安装
php -m | grep yaf
7. 配置 Nginx
server {
listen 80;
server_name your_domain_or_IP;
root /var/www/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
8. 启动 Nginx 并使其开机自启
sudo systemctl restart nginx
sudo systemctl enable nginx