Skip to main content

安装 wordpress

安装 apache

sudo apt-get install apache2 sudo apt-get install apache2-utils(可选)

启动

sudo systemctl enable apache2 sudo systemctl start apache2

安装 mariadb

sudo apt-get install mariadb-server sudo apt-get install mariadb-client(可选)

sudo systemctl start mariadb.service sudo systemctl enable mariadb.service

配置 mariadb

sudo mysql_secure_installation

连接 mariadb

sudo mariadb

创建 mariadb 新用户

GRANT ALL ON . TO 'admin'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;

刷新权限

FLUSH PRIVILEGES;

退出

exit

测试新用户

mariadb -u admin -p

安装 php

添加仓库(可选)

sudo apt-get install software-properties-common sudo add-apt-repository ppa:ondrej/php

sudo apt install php libapache2-mod-php php-mysql sudo apt install php-curl php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip sudo apt install php7.2 libapache2-mod-php7.2 php7.2-common php7.2-mysql php7.2-gmp php7.2-curl php7.2-intl php7.2-mbstring # 处理语言编码问题 php7.2-xmlrpc # 支持 xmlrpc 客户端发布协议 php7.2-gd # 用来剪切图片

php7.2-xml php7.2-cli php7.2-zip php7.2-cgi

修改 apache 配置,查找 index.php

sudo vi /etc/apache2/mods-enabled/dir.conf

<IfModule mod_dir.c>
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>

重启 apache

sudo systemctl restart apache2

查看 apache 状态

sudo systemctl status apache2

查看可选的 php 插件

apt search php- | less

查看 php 插件详细信息

apt show package_name

安装 php 插件

sudo apt install php-cli

测试 php

sudo vi /var/www/html/info.php

<?php
phpinfo();
?>

删除测试文件

sudo rm /var/www/html/info.php

设置 apache 允许 htaccess 重写

sudo vi /etc/apache2/sites-available/wordpress.conf

<Directory /var/www/wordpress/>
AllowOverride All
</Directory>

开启 apache 重写功能

sudo a2enmod rewrite

插件 apache 配置

sudo apache2ctl configtest

重启 apache

sudo systemctl restart apache2

下载 wordpress

curl -O https://wordpress.org/latest.tar.gz

解压

tar xzvf latest.tar.gz

新建重写配置

touch /tmp/wordpress/.htaccess

新建配置

cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php

创建文件夹,防止升级时候报错

mkdir /tmp/wordpress/wp-content/upgrade

sudo cp -a /tmp/wordpress/. /var/www/wordpress

配置 wordpress 文件夹

sudo chown -R www-data:www-data /var/www/wordpress

sudo find /var/www/wordpress/ -type d -exec chmod 750 {} ; sudo find /var/www/wordpress/ -type f -exec chmod 640 {} ;

获取配置

curl -s https://api.wordpress.org/secret-key/1.1/salt/

sudo vi /var/www/wordpress/wp-config.php

修改数据库配置

增加文件直接可写配置

define('FS_METHOD', 'direct');

访问网址完成安装

安装 wp 命令

cd /tmp

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

chmod +x /tmp/wp-cli.phar

sudo mv /tmp/wp-cli.phar /usr/local/bin/wp

wp --info