Last updated on May 5, 2021
- 前言
- 1. 安装并配置wordpress
- 2. 配置mysql和wordpress做安装wordpress前的准备
- 3. 安装完wordpress后一些通常的配置
- 4. 申请域名,并将网站从http增加为https
- 5. 在整个安装过程中遇到的问题及解决办法汇总:
- 5.1 新安装的mysql 不知道root的密码无法登录。
- 5.2 把网站从http升级为https后,虽然出现了https和锁的标志,却仍然显示Not secure并有红线
- 5.3 在安装插件过程中,一些设置并未起效,比如配置wps-hide-login插件,设置的url访问时,提示404
- 5.4 一切配置好后,比如login url被重设后,突发奇想想换个端口,导致再也登录不进admin界面
- 5.5 某种原因导致死活登录不了admin界面了
- 5.6 无法在线安装插件,提示需要什么ftp server,
- 5.7 media library 允许上传文件只有2M
- 5.8 上传多媒体文件如图片等其他文件时,显示无法拷贝到uploads之类的错误
- 5.9 最后mod_rewrite和.htaccess 是非常重要的两块内容,遇到问题可以针对性学习
- 安装脚本以便方便大家,此脚本可以完成到步骤1到步骤2.2
前言
如何建立自己的博客站点? 本文提供一种基于wordpress的解决方案,即本文内容不仅包括如何安装wordpress,而且包含在安装过程中可能遇到的问题,本文详细地介绍了这些问题并给出了解决办法,最后本文提供了一个安装脚本来帮助大家更快的安装。
1. 安装并配置wordpress
WordPress是一个基于php的知名博客站点被广泛用来建立个人博客站点。
Wordpress的正常使用需要依赖于apache,php,mysql。
1.1 下载并解压wordpress
wget https://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
1.2 安装mysql
“`sudo apt-get install mysql-server“`
1.3 安装php,并配置php和apache以及mysql集成
“`sudo apt-get install php php-mysql“`
2. 配置mysql和wordpress做安装wordpress前的准备
2.1 创建MySQL用户和数据库
mysql -uroot -p #连接上mysql 这一步可能遇到问题:不知道root密码
create database if not exists [YourDbameHere];
create user if not exists 'YourUserName'@'localhost' identified by 'YourPassword'; #创建本地用户
grant all privileges on [YourDbameHere].* to 'YourUserName'@'localhost'; flush privileges; #赋予用户对应数据库的权限。
2.2 配置wordpress文件 wp-config.php
在安装wordpress之前,需要进行一些必要的配置,以便能够顺利的完成安装。
具体过程如下:
– 进入wordpress解压后的目录,找到wp-config-sample.php 重命名为wp-config.php
– 打开wp-config.php文件,找到如下字段,并填上对应的值:
– Define('DB_NAME','database_name here')
– Define('DB_User','username_here')
– Define('DB_Password','password_here')
– DB_NAME,DB_User,DB_Password,是在步骤2.1中创建的数据库相关的属性。DB_Host一般是localhost,也可以是ip:port的形式,但是需要和数据库的相关配置保持一致
2.3 配置apache使其可以访问wp-admin/install.php 以完成安装
当执行到这一步时,启动apache,并在浏览器里输入 http://localhost:80 默认情况下会显示一个ubuntu下apache的相关界面.
执行 http://localhost/wp-admin/install.php 时并不能出现wordpress的安装界面,所以需要配置apache使其能够访问上述界面,以进入wordpress安装程序
– 简便方法1: 把wordpress的内容全部拷贝到/var/www/html 目录下,这样就能够访问http://localhost/wp-admin/install.php 了。
这种方式能够工作的原因是apache默认站点监听80端口,并且站点目录为/var/www/html
– 方法2:另外设置一个apache站点。
– 进入apache配置目录 /etc/apache2/
– 仿照 site-availables/00-default.conf
文件新建一个文件 yoursite.conf cp 00-default.conf yoursite.conf
– 编辑这个文件 更改VirtualHost参数中端口的值,比如从80端口,改为任意一个大于1024的端口即可。
– 更改文件中DocumentRoot 的值, DocumentRoot就是指你的站点文件应该放在哪里,apache 默认是/var/www/html , 这里应该与第一步中解压后的wordpress的位置相对应
– 在site-availables/yoursite.conf
中更改了端口和DocumentRoot的值,需要激活这两个值:
– 编辑 /etc/apache2.conf
文件 增加如下:
“`
<Directory ${your wordpress folder location}>
Options FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
“`
– 编辑`/etc/ports.conf` 模拟监听80端口的写法,增加一个监听的端口 `Listen ${your port here}`
– 执行完这个后,通过 http://localhost:port/wp-admin/install.php 就可以看到wordpress的安装界面了, 按照提示设定用户名,密码等操作用网站就安装完成了。
3. 安装完wordpress后一些通常的配置
- 比如安装一些必要的插件等:
- wps-hide-login
- increase-maximum-upload-file-size
- disable-xml-rpc
- redirection
- really-sample-ss
4. 申请域名,并将网站从http增加为https
-
- 购买域名并解析
-
- 获得SSL证书,可以从免费的Letsencypt获取
- 具体步骤参考:
- Add Certbot PPA
sudo apt-get update sudo apt-get install software-properties-common sudo add-apt-repository universe sudo add-apt-repository ppa:certbot/certbot sudo apt-get update
- Install Cerbt
sudo apt-get install certbot python-certbot-apache
- 获取ssl证书,配置当前apache 站点,并激活https
sudo certbot --apache
- 通过https://yoursite.com 检测是否有安全锁标志
- 安装wordpress 插件 really-simple-ssl 进行设置
5. 在整个安装过程中遇到的问题及解决办法汇总:
5.1 新安装的mysql 不知道root的密码无法登录。
- 解决办法:重置root 密码
- 方法1:
# 以安全方式启动mysql,此时登录root 无需密码 sudo mkdir /var/run/mysqld; sudo chown mysql /var/run/mysqld sudo mysqld_safe --skip-grant-tables& sudo mysql --user=root mysql ### 修改root 密码 登录mysql 后执行一下mysql语句(适用于mysql 5.7以上) update user set plugin='mysql_native_password' where user='root'; update user set authentication_string=PASSWORD('new-password') where user='root'; flush privileges; ### 重启mysql 找到mysqld_safe 起的进程,kill掉 sudo service mysql start
- 方法2:
- ubuntu下会默认有一个
debian-sys-maint
的用户,其密码定义在/etc/mysql/debian.cnf
文件中,找到该密码,以debian-sys-maint
这个用户登录 mysql -udebian-sys-maint -p password
- 登录mysql后重置root密码
use mysql; update user set plugin='mysql_native_password' where user='root'; commit; update user user set authentication_string=password('yourpassword') where user='root'; flush privileges; commit;
- 方法1:
5.2 把网站从http升级为https后,虽然出现了https和锁的标志,却仍然显示Not secure并有红线
解决办法:这是由于,通常情况下,ssl证书是根据域名申请的,而你的wordpress的站点名称还是ip:port 或者localhost:port的形式
– 需要修改站点的site url 和home url为域名的形式
– 1. 在wordpress admin控制面板修改站点site url和home url
– 2. 直接更新wp_options 标中 site_url和home_url字段
– 如果上述方法还没有解决,则可能是还引用了其他图片,css的素材,并且是通过ip:port localhost访问这些素材的。
– 新开一个浏览器窗口,打开控制台,输入https网址,可以看到具体的错误,进行针对性解决
5.3 在安装插件过程中,一些设置并未起效,比如配置wps-hide-login插件,设置的url访问时,提示404
解决办法: wordpress 的某些插件需要重写apache配置,因此apache需要安装mod_rewrite模块,
并在.htaccess 增加相关配置
– 检查是否安装mod_rewrite模块:
– sudo a2enmod rewrite #如果未安装会安装mod_rewrite,如果安装了会提示已经安装
– sudo service apache2 restart #重启apache 服务
– 配置.htaccess 文件
– 在wordpress根目录,打开.htaccess 文件,没有则新建
– 增加以下内容:
“`
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
“`
5.4 一切配置好后,比如login url被重设后,突发奇想想换个端口,导致再也登录不进admin界面
解决办法:
– 把端口先改回之前正常的端口,先登录admin,在控制面板,先修改site url和home url,并检查对应的login url有没有更新,待更新后,再去修改apche配置,更换端口
5.5 某种原因导致死活登录不了admin界面了
解决办法:
– 删除数据库相关表,执行重装wordpress 步骤
5.6 无法在线安装插件,提示需要什么ftp server,
解决办法:
– 可以单独去wordpress 官网去下载插件,然后直接把插件的解压文件拷贝到wp-content/plugins 目录下
5.7 media library 允许上传文件只有2M
解决办法:
– 安装 increase-maximum-upload-file-size 插件增加到75M
5.8 上传多媒体文件如图片等其他文件时,显示无法拷贝到uploads之类的错误
解决办法:
– 修改相关文件夹的权限,比如644,755,甚至777。注意的是权限越大,风险越高
– 修改相关文件夹的owner user 和group
5.9 最后mod_rewrite和.htaccess 是非常重要的两块内容,遇到问题可以针对性学习
安装脚本以便方便大家,此脚本可以完成到步骤1到步骤2.2
#!/bin/bash
echo -e "\033[41;37m create a folder \033[0m"
mkdir yoursite
#Step 1 Download and Extract
echo -e "\033[41;37m Downloading wordpress \033[0m"
wget https://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz -C ./yoursite >/dev/null
echo -e "\033[41;37m Success Downloading wordpress \033[0m"
#Step 2 Create the Database and a User
echo -e "\033[41;37m Install mysql-server \033[0m"
sudo apt-get install -y mysql-server
echo -e "\033[41;37m Start Mysql \033[0m"
sudo /etc/init.d/mysql start
echo ""
user="debian-sys-maint"
pw=`sudo grep "password" /etc/mysql/debian.cnf| awk -F=' ' '{print $2}' | head -n 1`
sudo mysql -u"$user" -p"$pw" -e "use mysql; update user set plugin='mysql_native_password' where user='root'; commit; update user user set authentication_string=password('yourpassword') where user='root'; flush privileges; commit;"
echo -e "\033[41;37m Create User \033[0m"
mysql -uroot -p -e "create database if not exists yourdatabase; use mysql; create user if not exists 'yourdbusername'@'localhost' identified by 'yourpassword'; grant all privileges on yourdatabase.* to 'yourdbusername'@'localhost'; flush privileges; \!echo 'the db name and user name is as bellow:'; select user from user where user='yourdbusername'; show grants for 'yourdbname'@'localhost';"
#Step 3 Set up wp-config.php
cp ./yoursite/wordpress/wp-config-sample.php ./yoursite/wordpress/wp-config.php
sed -i 's/database_name_here/yourdatabase/g' ./yoursite/wordpress/wp-config.php
sed -i 's/username_here/yourdbusername/g' ./yoursite/wordpress/wp-config.php
sed -i 's/password_here/yourpassword/g' ./yoursite/wordpress/wp-config.php
Hi
Hi
fue
[…]Here is a good Weblog You might Obtain Fascinating that we Encourage You[…]