1核2G1M带宽阿里云服务器上搭建WordPress个人博客网站-全流程
搭建博客网站的方法不止一种,根据个人需要进行选择;
操作环境阿里云ECS服务器、centos7、SecureCRT\Xshell,MySQL5.7
wordpress
;
做下面一些列操作前的要求:对Linux一些命令有所了解,会些简单的数据库操作命令即可
我的博客网站建成得益于 B站UP主 '‘晓哥爱折腾’'的视频,如需通过视频了解可去B站观看,非常详细
1、异常情况
No package 'oniguruma' found
1、安装:oniguruma:
2、cd oniguruma-6.9.4/
3、./configure --prefix=/usr --libdir=/lib64
failed to open error_log (/usr/local/php/var/log/php...em (30)
打开 /usr/lib/systemd/system/php-fpm.service
其中:ProtectSystem=true
改成:ProtectSystem=false- Navicat远程连接不上阿里云服务器上的MySQL
1、在服务器安全组中手动添加 3306端口
2、创建一个数据库,并给予对外访问的权限 - nginx.conf文件出现“Swap file “.nginx.conf.swp” already exists!”
ls -a 找到.swap文件删除即可
2、Nginx
通过yum安装完后 ,有关Nginx的操作 在/etc/nginx/
下进行
nginx.conf
中所有内容如下 可全部拷贝使用
每修改完nginx的配置 执行一次nginx -s reload
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
include conf.d/phpMyAdmin.conf;
server {
listen 80;
server_name localhost;
root /www/wordpress;
location / {
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi.conf;
}
}
}
3、php环境搭建(完整过程)
- 安装cmake
yum install epel-release -y
yum install cmake3 -y
cp /usr/bin/cmake3 /usr/bin/cmake
执行命令cmake -version
查看是否安装成功:
#输出
cmake version 3.16.1
CMake suite maintained and supported by Kitware (kitware.com/cmake).
- 安装libzip1.5.2
#安装bzip2-devel依赖包
yum install bzip2 bzip2-devel -y
#安装libzip,下面每一行为一步操作
wget https://libzip.org/download/libzip-1.5.2.tar.gz
tar xf libzip-1.5.2.tar.gz
cd libzip-1.5.2
mkdir build
#在build进行操作
cd build
cmake ..
make && make install
- 安装php依赖
yum install gcc \
gcc-c++ \
libxml2 \
libxml2-devel \
openssl \
openssl-devel \
libcurl \
libcurl-devel \
freetype \
freetype-devel \
libjpeg \
libjpeg-devel \
libpng \
libpng-devel \
libxslt \
libxslt-devel \
systemd-devel \
libicu-devel \
libedit-devel
- 创建www用户
useradd -M -s /sbin/nologin www
修改库加载路径
vim /etc/ld.so.conf
#添加如下几行
/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64
ldconfig -v
最终,再次进行预配置
- 下载php源码并预配置
#安装wget工具
yum install wget -y
#下载php源码、如果压缩包已下,跳过这步
wget https://www.php.net/distributions/php-7.4.10.tar.gz
#解压php tar包
tar xf php-7.4.10.tar.gz
#进入php解压后的目录
cd php-7.4.10
#预配置
./configure --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-config-file-scan-dir=/usr/local/php/etc/conf.d \
--disable-cgi \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-ftp \
--with-curl \
--with-gd \
--with-gettext \
--with-iconv-dir \
--with-kerberos \
--with-libedit \
--with-openssl \
--with-pcre-regex \
--with-pdo-mysql \
--with-xsl \
--with-zlib \
--with-mhash \
--with-mysqli \
--with-png-dir=/usr/lib \
--with-jpeg-dir=/usr/lib\
--with-freetype-dir=/usr/lib \
--enable-mysqlnd \
--enable-bcmath \
--enable-libxml \
--enable-inline-optimization \
--enable-gd-jis-conv \
--enable-mbregex \
--enable-mbstring \
--enable-opcache \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvsem \
--enable-xml \
--enable-zip \
--enable-calendar \
--enable-intl \
--enable-exif
出现下面情况
Thank you for using PHP
- 进行编译安装
make && make install
- 创建启动脚本
路径为: /root/php-7.4.10/sapi/fpm
下php-fpm.service
#复制一份配置文件
cp php-fpm.conf.default php-fpm.conf
#拷贝启动脚本到指定目录
cp /root/php-7.4.10/sapi/fpm/php-fpm.service /usr/lib/systemd/system/
#依次进行操作
systemctl daemon-reload
systemctl start php-fpm
#查看php状态
systemctl status php-fpm
cd /usr/local/php/etc/php-fpm.d/
cp www.conf www.conf.default
#重新启动
systemctl start php-fpm
#active running 则启动成功
systemctl status php-fpm
查看进程是否存在
ps -ef|grep php-fpm
查看端口是否启动:
ss -lntup|grep 9000
4、安装Mysql
- 安装操作
#通过连接进行下载
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
#安装
yum install mysql80-community-release-el7-3.noarch.rpm
#安装utils工具
yum install yum-utils -y
#关闭MySQL8服务
yum-config-manager --disable mysql80-community
#安装MySQL5.7
yum-config-manager --enable mysql57-community
#:若启动时出现该异常 Unit not found.
yum install -y mysql-community-server
#启动MySQL
systemctl start mysqld
#登陆
mysql -uroot -p
- 查看给定的登陆密码
cat /var/log/mysqld.log
- 登陆进去创建一个数据库后修改密码
alter user 'root'@'localhost' identified by 'specialW7.';
- 数据库被远程连接前的一些操作
create user 'specialwu'@'%' identified by 'specialW7.';
create database firstmysql;
grant all privileges on firstmysql.* to 'specialwu'@'%';
- MySQL改密码时要求包含数字、字母大小写、特殊符号
5、安装phpMyAdmin
安装在/www/
下
通过该查看该文档也可完成配置,
phpMyAdmin官方文档
在 /etc/nginx/conf.d/phpMyAdmin.conf
进行如下配置,
目的是通过880端口访问下面这个页面
server {
listen 880;
server_name localhost;
root /www/phpMyAdmin;
location / {
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi.conf;
}
}
ESC :wq
经过如下配置即可进入该页面
[root@specialwu ~]# cd /www
[root@specialwu www]# ll
total 8
drwxr-xr-x 13 www www 4096 Sep 13 01:15 phpMyAdmin
drwxr-xr-x 5 www www 4096 Sep 13 02:15 wordpress
[root@specialwu www]# cd phpMyAdmin
[root@specialwu phpMyAdmin]# cp libraries/config.default.php config.inc.php
[root@specialwu phpMyAdmin]# vim config.inc.php
#137行处做如下改动
$cfg['Servers'][$i]['host'] = '127.0.0.1';
#265行附近,做如下改动
$cfg['Servers'][$i]['user'] = 'root';
/**
* MySQL password (only needed with 'config' auth_type)
*
* @global string $cfg['Servers'][$i]['password']
*/
$cfg['Servers'][$i]['password'] = 'specialW7.';
#341行处做如下变动
$cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
ESC :wq
在上面配置完成后在 MySQL中创建phpmyadmin数据库
6、部署WordPress
安装在/www/
下
www 文件给予www权限,在php部分已说明
chown -R www.www /www
通过服务器的IP地址访问如下页面则整个搭建过程完成
WordPress安装位置
[root@specialwu ~]# cd /www
[root@specialwu www]# ll
total 8
drwxr-xr-x 13 www www 4096 Sep 13 17:39 phpMyAdmin
drwxr-xr-x 5 www www 4096 Sep 13 02:15 wordpress
[root@specialwu www]#
搭建成功
若无法跳转到WordPress页面,则看以下介绍
- 原因分析
1.1wordpress页面跳转路径:index.php–>wp-admin—>.php
1.2没能跳转可能是index.php出现问题,或者是跳转问题
1.3我的index.php
内容如下,查看自己这部分是否变动
1.4如未变动则检查nginx.conf
配置文件中是否配置
<?php
/**
* Front to the WordPress application. This file doesn't do anything, but loads
* wp-blog-header.php which does and tells WordPress to load the theme.
*
* @package WordPress
*/
/**
* Tells WordPress to load the WordPress theme and output it.
*
* @var bool
*/
define( 'WP_USE_THEMES', true );
/** Loads the WordPress Environment and Template */
require __DIR__ . '/wp-blog-header.php';
- 文件结构展示
[root@specialwu ~]# cd /www
[root@specialwu www]# cd wordpress/
[root@specialwu wordpress]# ll
total 212
-rw-r--r-- 1 root root 406 Sep 13 02:07 index.php
drwxr-xr-x 9 www www 4096 Sep 2 02:54 wp-admin
[root@specialwu wordpress]# cd wp-admin/
[root@specialwu wp-admin]# ll
total 1020
#所有WordPress页面则存储在如下位置
-rw-r--r-- 1 www www 15796 Sep 2 01:44 about.php
-rw-r--r-- 1 www www 4690 May 21 02:49 admin-ajax.php
-rw-r--r-- 1 www www 2832 Jan 29 2020 admin-footer.php
-rw-r--r-- 1 www www 406 Feb 6 2020 admin-functions.php
-rw-r--r-- 1 www www 8547 Aug 24 18:50 admin-header.php
-rw-r--r-- 1 www www 12133 Jul 22 20:56 admin.php
-rw-r--r-- 1 www www 1671 Feb 6 2020 admin-post.php
-rw-r--r-- 1 www www 3834 Jun 23 07:53 async-upload.php
-rw-r--r-- 1 www www 11288 Jul 24 08:21 comment.php
-rw-r--r-- 1 www www 3861 Aug 5 01:44 credits.php
drwxr-xr-x 3 www www 4096 Sep 2 02:54 css
-rw-r--r-- 1 www www 416 Feb 6 2020 custom-background.php
-rw-r--r-- 1 www www 426 Feb 6 2020 custom-header.php
-rw-r--r-- 1 www www 10316 Jul 10 19:36 customize.php
-rw-r--r-- 1 www www 13744 Jul 7 05:52 edit-comments.php
-rw-r--r-- 1 www www 28902 Jun 28 07:02 edit-form-advanced.php
-rw-r--r-- 1 www www 14823 Jul 21 23:38 edit-form-blocks.php
-rw-r--r-- 1 www www 8104 Jul 24 08:21 edit-form-comment.php
-rw-r--r-- 1 www www 6233 Jul 4 17:33 edit-link-form.php
-rw-r--r-- 1 www www 18505 Jul 7 05:52 edit.php
-rw-r--r-- 1 www www 10107 May 13 02:32 edit-tag-form.php
-rw-r--r-- 1 www www 21910 Apr 5 11:02 edit-tags.php
-rw-r--r-- 1 www www 3231 Jul 14 19:17 erase-personal-data.php
-rw-r--r-- 1 www www 3206 Jul 14 19:17 export-personal-data.php
-rw-r--r-- 1 www www 10972 May 13 02:32 export.php
-rw-r--r-- 1 www www 4567 Jul 29 01:46 freedoms.php
drwxr-xr-x 2 www www 4096 Sep 2 02:54 images
-rw-r--r-- 1 www www 7530 Jul 21 07:14 import.php
drwxr-xr-x 2 www www 4096 Sep 2 02:54 includes
-rw-r--r-- 1 www www 6913 Jul 21 20:37 index.php
-rw-r--r-- 1 www www 6031 May 13 02:40 install-helper.php
-rw-r--r-- 1 www www 16902 Jun 26 08:27 install.php
drwxr-xr-x 3 www www 4096 Sep 2 02:54 js
-rw-r--r-- 1 www www 711 Feb 6 2020 link-add.php
-rw-r--r-- 1 www www 4189 May 13 02:32 link-manager.php
-rw-r--r-- 1 www www 2654 Jul 5 23:22 link-parse-opml.php
-rw-r--r-- 1 www www 2732 May 13 02:32 link.php
-rw-r--r-- 1 www www 1693 May 26 17:37 load-scripts.php
-rw-r--r-- 1 www www 2302 May 26 17:37 load-styles.php
drwxr-xr-x 2 www www 4096 Sep 2 02:54 maint
-rw-r--r-- 1 www www 3179 Feb 6 2020 media-new.php
-rw-r--r-- 1 www www 5598 May 26 17:37 media.php
-rw-r--r-- 1 www www 3489 May 13 02:32 media-upload.php
-rw-r--r-- 1 www www 9834 May 13 02:32 menu-header.php
-rw-r--r-- 1 www www 14526 Apr 20 16:39 menu.php
-rw-r--r-- 1 www www 307 Feb 6 2020 moderation.php
-rw-r--r-- 1 www www 196 Feb 6 2020 ms-admin.php
-rw-r--r-- 1 www www 4277 Jun 28 22:12 ms-delete-site.php
-rw-r--r-- 1 www www 216 Feb 6 2020 ms-edit.php
-rw-r--r-- 1 www www 223 Feb 6 2020 ms-options.php
-rw-r--r-- 1 www www 215 Feb 6 2020 ms-sites.php
-rw-r--r-- 1 www www 217 Feb 6 2020 ms-themes.php
-rw-r--r-- 1 www www 219 Feb 6 2020 ms-upgrade-network.php
-rw-r--r-- 1 www www 215 Feb 6 2020 ms-users.php
-rw-r--r-- 1 www www 4646 May 13 02:32 my-sites.php
-rw-r--r-- 1 www www 44766 Jun 17 02:38 nav-menus.php
drwxr-xr-x 2 www www 4096 Sep 2 02:54 network
-rw-r--r-- 1 www www 5380 May 23 19:38 network.php
-rw-r--r-- 1 www www 15444 Jul 23 11:14 options-discussion.php
-rw-r--r-- 1 www www 14957 Apr 5 11:02 options-general.php
-rw-r--r-- 1 www www 492 Aug 16 2019 options-head.php
-rw-r--r-- 1 www www 6299 Jun 1 19:22 options-media.php
-rw-r--r-- 1 www www 19212 Jun 3 18:38 options-permalink.php
-rw-r--r-- 1 www www 12779 Jul 23 11:14 options.php
-rw-r--r-- 1 www www 8072 Feb 10 2020 options-privacy.php
-rw-r--r-- 1 www www 9706 May 27 22:33 options-reading.php
-rw-r--r-- 1 www www 8624 Jun 27 03:38 options-writing.php
-rw-r--r-- 1 www www 13327 Jun 20 21:18 plugin-editor.php
-rw-r--r-- 1 www www 6357 Jul 3 16:51 plugin-install.php
-rw-r--r-- 1 www www 29110 Jul 29 00:32 plugins.php
-rw-r--r-- 1 www www 2703 May 17 02:42 post-new.php
-rw-r--r-- 1 www www 9997 Jul 5 18:41 post.php
-rw-r--r-- 1 www www 2386 Feb 6 2020 press-this.php
-rw-r--r-- 1 www www 2309 Jul 29 01:46 privacy.php
-rw-r--r-- 1 www www 833 Feb 6 2020 privacy-policy-guide.php
-rw-r--r-- 1 www www 283 Feb 6 2020 profile.php
-rw-r--r-- 1 www www 5537 Jul 27 05:25 revision.php
-rw-r--r-- 1 www www 15808 Jun 23 05:26 setup-config.php
-rw-r--r-- 1 www www 5783 Jun 30 21:26 site-health-info.php
-rw-r--r-- 1 www www 5339 Mar 30 09:25 site-health.php
-rw-r--r-- 1 www www 2253 Apr 5 11:02 term.php
-rw-r--r-- 1 www www 15034 Jun 20 21:18 theme-editor.php
-rw-r--r-- 1 www www 21993 Jul 27 23:04 theme-install.php
-rw-r--r-- 1 www www 44832 Jul 31 06:04 themes.php
-rw-r--r-- 1 www www 3452 Mar 3 2020 tools.php
-rw-r--r-- 1 www www 38291 Jul 28 09:02 update-core.php
-rw-r--r-- 1 www www 12522 Jul 10 14:08 update.php
-rw-r--r-- 1 www www 341 Feb 6 2020 upgrade-functions.php
-rw-r--r-- 1 www www 5599 Jun 26 08:27 upgrade.php
-rw-r--r-- 1 www www 13965 Jul 5 18:41 upload.php
drwxr-xr-x 2 www www 4096 Sep 2 02:54 user
-rw-r--r-- 1 www www 29205 May 17 02:42 user-edit.php
-rw-r--r-- 1 www www 23181 Jun 15 01:03 user-new.php
-rw-r--r-- 1 www www 19892 Jul 23 08:52 users.php
-rw-r--r-- 1 www www 19741 Feb 6 2020 widgets.php