一、WordPress简介
WordPress是使用PHP语言开发的博客平台,用户可以在支持PHP和MYSQL数据库的服务器上架设属于自己的网站。也可以把WordPress当作一个内容管理系统(CMS)来使用。
WordPress是一款个人博客系统,并逐步演化成一款内容管理系统软件,它是使用PHP语言和MYSQL数据库开发的,用户可以在支持 PHP 和 MYSQL数据库的服务器上使用自己的博客。
WordPress有许多第三方开发的免费模板,安装方式简单易用。不过要做一个自己的模板,则需要你有一定的专业知识。比如你至少要懂的标准通用标记语言下的一个应用HTML代码、CSS、PHP等相关知识。
WordPress官方支持中文版,同时有爱好者开发的第三方中文语言包,如wopus中文语言包。WordPress拥有成千上万个各式插件和不计其数的主题模板样式。
二、准备工作
1、服务器信息
操作系统 |
服务器IP |
CPU |
内存 |
CentOS 7.4 |
192.168.0.117 |
1C |
2G |
软件版本:
httpd:2.4.29
MYSQL:5.7.22
PHP:7.2.9
WordPress:5.2.2
2、下载软件包
# httpd软件包
https://mirrors.yangxingzhen.com/apache/httpd-2.4.29.tar.gz
# httpd依赖包
https://mirrors.yangxingzhen.com/apr/apr-1.6.3.tar.gz
https://mirrors.yangxingzhen.com/apr-util/apr-util-1.6.1.tar.gz
# MYSQL软件包
https://mirrors.yangxingzhen.com/mysql/mysql-5.7.22.tar.gz
# MYSQL依赖包
https://mirrors.yangxingzhen.com/mysql/boost_1_59_0.tar.gz
# PHP软件包
https://mirrors.yangxingzhen.com/php/php-7.2.9.tar.gz
# PHP依赖包
https://mirrors.yangxingzhen.com/libiconv/libiconv-1.15.tar.gz
# WordPress软件包
https://mirrors.yangxingzhen.com/wordpress/wordpress-5.2.2.tar.gz
注:
Apr-1.6.3.tar.gz和Apr-util-1.6.1.tar.gz是httpd-2.4以后的版本所需要的插件,必须安装
3、将防火墙与selinux关闭
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# systemctl disable firewalld
[root@localhost ~]# sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config
三、安装Apache服务
1、下载软件包和安装编译工具与插件
[root@localhost ~]# yum -y install wget gcc gcc-c++ make pcre-devel pcre perl expat-devel perl-devel libtool
[root@localhost ~]# wget -c https://mirrors.yangxingzhen.com/apache/httpd-2.4.29.tar.gz
[root@localhost ~]# wget -c https://mirrors.yangxingzhen.com/apr/apr-1.6.3.tar.gz
[root@localhost ~]# wget -c https://mirrors.yangxingzhen.com/apr-util/apr-util-1.6.1.tar.gz
#APR安装
1、解压APR软件包
[root@localhost ~]# tar zxf apr-1.6.3.tar.gz
[root@localhost ~]# cd apr-1.6.3
2、预编译
[root@localhost apr-1.6.3]# ./configure --prefix=/usr/local/apr
3、编译及安装
[root@localhost apr-1.6.3]# make && make install
# Apr-util安装
1、解压apr-util软件包
[root@localhost apr-1.6.3]# cd ..
[root@localhost ~]# tar zxf apr-util-1.6.1.tar.gz
[root@localhost ~]# cd apr-util-1.6.1
2、预编译
[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
3、编译及安装
[root@localhost apr-util-1.6.1]# make && make install
# Apache安装
1、解压httpd软件包
[root@localhost apr-util-1.6.1]# cd ..
[root@localhost ~]# tar zxf httpd-2.4.29.tar.gz
[root@localhost ~]# cd httpd-2.4.29
2、预编译
[root@localhost ~]# ./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-so --enable-rewrite --enable-cahreset-lite
3、编译及安装
[root@localhost httpd-2.4.29]# make && make install
4、将httpd服务添加到系统服务
[root@localhost httpd-2.4.29]# cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
[root@localhost httpd-2.4.29]# vi /etc/init.d/httpd
#添加以下两行(注意,"#"不能省略):
# chkconfig: - 85 21
# description: Apache is a World Wide Web Server
5、将httpd加入到SERVICE管理器
[root@localhost httpd-2.4.29]# chkconfig --add httpd
[root@localhost httpd-2.4.29]# systemctl daemon-reload
6、编辑httpd主配置文件
[root@localhost httpd-2.4.29]# vim /usr/local/apache/conf/httpd.conf
修改以下内容:
ServerName localhost:80
7、创建软连接
[root@localhost httpd-2.4.29]# ln -s /usr/local/apache/bin/* /usr/bin
# 检查语法错误
[root@localhost httpd-2.4.29]# httpd -t
或者:
[root@localhost httpd-2.4.29]# apachectl -t
8、启动httpd服务
[root@localhost httpd-2.4.29]# systemctl start httpd
9、验证
# 浏览器访问服务器IP,http://192.168.0.117
四、安装MySQL服务
# MYSQL安装
1、下载boost库(MYSQL5.7及以上需要,必须安装)
[root@localhost ~]# yum -y install wget
[root@localhost ~]# wget -c https://mirrors.yangxingzhen.com/mysql/boost_1_59_0.tar.gz
[root@localhost ~]# tar zxf boost_1_59_0.tar.gz -C /usr/local/
2、下载扩展包
[root@localhost ~]# yum -y install ncurses ncurses-devel perl perl-devel gcc gcc-c++ cmake make openssl-devel openssl
3、建立MYSQL用户
[root@localhost ~]# useradd -s /sbin/nologin mysql
4、下载MYSQL-5.7.22源码包
[root@localhost ~]# wget -c https://mirrors.yangxingzhen.com/mysql/mysql-5.7.22.tar.gz
[root@localhost ~]# tar zxf mysql-5.7.22.tar.gz
[root@localhost ~]# cd mysql-5.7.22
[root@localhost mysql-5.7.22]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql /
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock /
-DMYSQL_DATADIR=/data/mysql /
-DSYSCONFDIR=/etc /
-DEXTRA_CHARSETS=all /
-DDEFAULT_CHARSET=utf8 /
-DDEFAULT_COLLATION=utf8_general_ci /
-DWITH_MYISAM_STORAGE_ENGINE=1 /
-DWITH_INNOBASE_STORAGE_ENGINE=1 /
-DWITH_MEMORY_STORAGE_ENGINE=1 /
-DWITH_PARTITION_STORAGE_ENGINE=1 /
-DDOWNLOAD_BOOST=1 /
-DWITH_BOOST=/usr/local/boost_1_59_0 /
-DENABLED_LOCAL_INFILE=1 /
-DMYSQL_TCP_PORT=3306 /
-DWITH_READLINE=1 /
-DMYSQL_USER=mysql /
-DWITH_SSL=yes
[root@localhost mysql-5.7.22]# make && make install
5、创建MYSQL数据存储目录
[root@localhost mysql-5.7.22]# mkdir -p /data/mysql
[root@localhost mysql-5.7.22]# chown -R mysql.mysql /data/mysql
6、编辑MYSQL主配置文件
[root@localhost mysql-5.7.22]# vim /etc/my.cnf
[client]
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysql]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /data/mysql
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
server-id = 1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
7、初始化数据库(生成空密码,生成随机密码--initialize)
[root@localhost mysql-5.7.22]# cd /usr/local/mysql/bin
[root@localhost bin]# ./mysqld --initialize-insecure --user=mysql --datadir=/data/mysql --basedir=/usr/local/mysql
8、配置成系统服务
[root@localhost bin]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost bin]# chmod o+x /etc/init.d/mysqld
[root@localhost bin]# chown -R mysql.mysql /usr/local/mysql
[root@localhost bin]# service mysqld start
[root@localhost bin]# chkconfig --add mysqld
[root@localhost bin]# chkconfig mysqld on
[root@localhost bin]# ln -s /usr/local/mysql/bin/* /usr/bin
[root@localhost bin]# mysql
# 数据库安装配置成功,退出则输入"quit"
五、安装PHP运行环境
# 安装libiconv
1、下载libiconv软件包
[root@localhost ~]# wget -c https://mirrors.yangxingzhen.com/libiconv/libiconv-1.15.tar.gz
2、解压libiconv软件包
[root@localhost ~]# tar zxf libiconv-1.15.tar.gz
[root@localhost ~]# cd libiconv-1.15
3、预编译
[root@localhost libiconv-1.15]# ./configure --prefix=/usr/local/libiconv
4、编译及安装
[root@localhost libiconv-1.15]# make && make install
# 安装 PHP-7.2.9
1、安装编工具及插件(下载阿里云yum源)
[root@localhost ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
[root@localhost ~]# yum -y install gcc gcc-c++ libvpx libvpx-devel libjpeg-turbo libjpeg-turbo-devel libzip libpng libpng-devel freetype-devel libxml2 libxml2-devel gd gd-devel libxslt-devel libcurl-devel libmcrypt-devel mhash mcrypt openssl openssl-devel
2、解压PHP软件包
[root@localhost ~]# tar zxf php-7.2.9.tar.gz
[root@localhost ~]# cd php-7.2.9
3、预编译
[root@localhost php-7.2.9.]# ./configure --prefix=/usr/local/php /
--with-config-file-path=/usr/local/php/etc /
--with-apxs2=/usr/local/apache/bin/apxs /
--with-mysql=mysqlnd /
--with-mysqli=mysqlnd /
--with-pdo-mysql=mysqlnd /
--enable-opcache /
--with-iconv-dir=/usr/local/libiconv /
--with-freetype-dir /
--with-jpeg-dir /
--with-png-dir /
--with-zlib /
--with-libxml-dir /
--enable-xml /
--disable-rpath /
--enable-bcmath /
--enable-shmop /
--enable-sysvsem /
--enable-inline-optimization /
--with-curl /
--enable-mbregex /
--enable-fpm /
--enable-mbstring /
--with-mcrypt /
--with-gd /
--enable-gd-native-ttf /
--with-openssl /
--with-mhash /
--enable-pcntl /
--enable-sockets /
--with-xmlrpc /
--enable-soap /
--enable-short-tags /
--enable-static /
--with-fpm-user=apache /
--with-fpm-group=apache /
--enable-ftp /
--enable-zip /
--with-gettext
4、编译及安装
[root@localhost php-7.2.9.]# make && make install
5、配置PHP
[root@localhost php-7.2.9]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@localhost php-7.2.9]# cp php.ini-production /usr/local/php/etc/php.ini
[root@localhost php-7.2.9]# useradd -s /sbin/nologin apache
[root@localhost php-7.2.9]# sed -i 's/User daemon/User apache/' /usr/local/apache/conf/httpd.conf
[root@localhost php-7.2.9]# sed -i 's/Group daemon/Group apache/' /usr/local/apache/conf/httpd.conf
[root@localhost php-7.2.9]# sed -i '/AddType *.* .tgz/a//tAddType application/x-httpd-php .php' /usr/local/apache/conf/httpd.conf
[root@localhost php-7.2.9]# sed -i 's/index.html/index.php index.html/' /usr/local/apache/conf/httpd.conf
7、验证
# 编辑PHP测试页面
[root@localhost php-7.2.9]# cd /usr/local/apache/htdocs/
[root@localhost htdocs]# vim index.php
<?php
phpinfo();
?>
# 重启httpd服务
[root@localhost htdocs]# systemctl restart httpd
# 浏览器访问服务器:http://192.168.0.117
8、测试数据库
[root@localhost htdocs]# mysql
mysql> create database test;
mysql> grant all on test.* to test@'%' identified by '123456';
mysql> flush privileges;
[root@localhost htdocs]# vim info_mysql.php
<?php
$link=mysqli_connect('192.168.0.117','test','123456');
if($link) echo "<h1>Success!!</h1>";
else echo "Fail!!";
?>
[root@localhost htdocs]# systemctl restart httpd
浏览器访问http://192.168.0.117/info_mysql.php
至此,LAMP环境搭建完毕。
六、安装Wordpress博客
1、下载软件包
[root@localhost ~]# wget -c https://mirrors.yangxingzhen.com/wordpress/wordpress-5.2.2.tar.gz
2、解压软件包
[root@localhost ~]# tar zxf wordpress-5.2.2.tar.gz
3、拷贝WordPress文件到Apache发布目录
[root@localhost ~]# /mv wordpress/* /usr/local/apache/htdocs/
4、重启httpd服务
[root@localhost ~]# systemctl restart httpd
5、创建数据库并授权
[root@localhost ~]# mysql
mysql> create database wordpress;
mysql> grant all on wordpress.* to wordpress@'localhost' identified by '123456';
mysql> flush privileges;
6、授权发布目录权限
[root@localhost ~]# chown -R apache.apache /usr/local/apache/
7、访问WordPress博客
# 打开浏览器访问服务器IP:192.168.0.117,如下图所示
8、选择简体中文,点击继续
9、点击—>现在就开始
10、输入数据库名、用户名、密码、数据库主机,点击提交
11、点击—>现在安装
12、输入站点标题、用户名、密码、电子邮件,点击安装WordPress
13、点击登录
14、输入用户名和密码,点击登录即可
至此WordPress博客搭建完毕。