溫馨提示×

如何在Debian LAMP上部署WordPress

小樊
69
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
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女