温馨提示×

如何在Debian LAMP上部署WordPress

小樊
79
2025-04-01 23:32:06
栏目: 智能运维

在Debian LAMP上部署WordPress的步骤如下:

1. 安装LAMP环境

  • 安装Apache

    sudo apt update
    sudo apt install apache2
    

    安装完成后,Apache服务默认自动运行。

  • 安装MariaDB/MySQL

    sudo apt install mariadb-server
    

    安装完成后,MariaDB服务将会自动启动。运行mysql_secure_installation命令进行安全配置。

  • 安装PHP

    sudo apt install php libapache2-mod-php php-mysql php-fpm
    

    编辑并查看PHP测试页/var/www/html/phpinfo.php

2. 配置域名和HTTPS

  • 修改/etc/apache2/sites-available/000-default.conf,添加以下内容:
    ServerName yourdomain.com
    Redirect permanent / https://yourdomain.com/
    
  • 修改/etc/apache2/sites-available/default-ssl.conf,添加以下内容:
    SSLCertificateFile /etc/apache2/sites-available/yourdomain.com.crt
    SSLCertificateKeyFile /etc/apache2/sites-available/yourdomain.com.key
    SSLCertificateChainFile /etc/apache2/sites-available/root_bundle.crt
    
  • 运行以下命令启用SSL:
    sudo a2ensite default-ssl
    sudo systemctl reload apache2
    

3. 安装WordPress

  • 从WordPress官网下载最新的WordPress程序:
    cd /tmp
    wget https://wordpress.org/latest.tar.gz
    
  • 解压软件包:
    sudo tar xzvf latest.tar.gz
    
  • 进入解压后的目录并重命名wp-config-sample.phpwp-config.php
    cd /tmp/wordpress
    sudo mv wp-config-sample.php wp-config.php
    
  • 将WordPress文件拷贝到Apache的默认文档根目录/var/www/html
    sudo cp -a /tmp/wordpress/. /var/www/html/wordpress
    
  • 更改文档根目录的所有权为Apache用户(www-data):
    sudo chown -R www-data: /var/www/html/wordpress
    

4. 配置WordPress

  • 打开浏览器,访问http://yourdomain.com/wordpress,按照提示完成WordPress的安装过程。

5. (可选)配置Nginx

如果你希望使用Nginx作为Web服务器,可以参考以下步骤:

  • 安装Nginx:
    sudo apt install nginx
    
  • 配置Nginx以支持WordPress: 编辑/etc/nginx/sites-available/default文件,添加以下内容:
    server {
        listen 80;
        server_name yourdomain.com;
        root /var/www/html/wordpress;
        index index.php index.html index.htm;
    
        location / {
            try_files $uri $uri/ /wordpress/index.php?$args;
        }
    
        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        }
    }
    
  • 重启Nginx:
    sudo systemctl restart nginx
    

完成以上步骤后,你的WordPress网站应该已经在Debian LAMP环境中成功部署。

0