奋斗
努力

京东云服务器如何安装WordPress?

云计算

在京东云服务器上安装WordPress需要完成以下步骤,分为环境准备、WordPress安装及配置三个阶段:


一、环境准备

1. 购买并登录京东云服务器

  • 在京东云官网购买云服务器(推荐至少2核4G配置,操作系统选择 CentOS 7/8 或 Ubuntu 20.04 LTS)。
  • 通过SSH登录服务器:
     ssh root@你的服务器IP

2. 安装LAMP/LNMP环境

  • 选项1:LAMP(Apache + MySQL + PHP)

     # CentOS
     yum install httpd mariadb-server mariadb php php-mysql php-gd php-mbstring -y
     system start httpd mariadb
     system enable httpd mariadb
    
     # Ubuntu
     apt install apache2 mysql-server php libapache2-mod-php php-mysql -y
     systemctl start apache2 mysql
     systemctl enable apache2 mysql
  • 选项2:LNMP(Nginx + MySQL + PHP)

     # CentOS
     yum install nginx mariadb-server mariadb php-fpm php-mysql -y
     system start nginx mariadb php-fpm
     system enable nginx mariadb php-fpm
    
     # Ubuntu
     apt install nginx mysql-server php-fpm php-mysql -y
     systemctl start nginx mysql php7.4-fpm
     systemctl enable nginx mysql php7.4-fpm

3. 配置数据库

  • 登录MySQL并创建WordPress数据库:
     mysql -u root -p
     # 执行以下SQL命令
     CREATE DATABASE wordpress;
     CREATE USER 'wpuser'@'localhost' IDENTIFIED BY '你的密码';
     GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
     FLUSH PRIVILEGES;
     EXIT;

二、安装WordPress

1. 下载并解压WordPress

   cd /var/www/html
   wget https://wordpress.org/latest.tar.gz
   tar -xzvf latest.tar.gz
   mv wordpress/* .
   chown -R www-data:www-data /var/www/html  # Ubuntu
   chown -R apache:apache /var/www/html      # CentOS

2. 配置Web服务器

  • Apache用户:无需额外配置,直接访问服务器IP。
  • Nginx用户:编辑配置文件:

     nano /etc/nginx/sites-available/wordpress

    添加以下内容(替换server_name为你的域名或IP):

     server {
         listen 80;
         root /var/www/html;
         index index.php index.html;
         server_name 你的域名或IP;
    
         location / {
             try_files $uri $uri/ /index.php?$args;
         }
    
         location ~ .php$ {
             include snippets/fastcgi-php.conf;
             fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
         }
     }

    启用配置并重启Nginx:

     ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
     nginx -t
     systemctl restart nginx

三、完成WordPress安装

  1. 访问安装页面
    浏览器输入 http://你的服务器IP,按提示选择语言,进入安装界面。

  2. 填写数据库信息

    • 数据库名:wordpress
    • 用户名:wpuser
    • 密码:之前设置的MySQL密码
    • 主机:localhost
    • 表前缀:默认wp_(可修改)
  3. 完成安装
    设置站点标题、管理员账号密码,登录WordPress后台(http://你的IP/wp-admin)。


四、可选优化

  1. 配置HTTPS
    使用京东云SSL证书或Let’s Encrypt免费证书:

    apt install certbot python3-certbot-nginx -y  # Ubuntu
    certbot --nginx -d 你的域名
  2. 性能优化

    • 安装缓存插件(如WP Super Cache)。
    • 启用OPcache(编辑php.ini):
      zend_extension=opcache.so
      opcache.enable=1

常见问题

  • 403错误:检查文件权限(chmod -R 755 /var/www/html)。
  • PHP报错:确保已安装所需扩展(如php-curlphp-xml)。
  • 数据库连接失败:确认MySQL用户权限和密码正确。

通过以上步骤,WordPress即可在京东云服务器上正常运行。如需更详细指导,可参考WordPress官方文档。

未经允许不得转载:云服务器 » 京东云服务器如何安装WordPress?