3分钟快速搭建wordpress博客

准备工作:

[root@iZm5eh8g1nh0vcbupue6dnZ blog]# cat /etc/os-release 
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

1.安装Nginx并启动

[root@iZm5eh8g1nh0vcbupue6dnZ ]# yum install -y nginx
[root@iZm5eh8g1nh0vcbupue6dnZ ]# nginx

2.安装mysq并启动

yum -y install mariadb-server mariadb mariadb-devel
systemctl start mariadb.service

3.安装PHP

3.1 检查安装PHP所需的lib库

需安装这些lib库不是运行php程序时会出现问题:
[root@web02 extra]# yum install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel -y
[root@web02 extra]# yum install freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libxslt-devel -y
说明:libiconv-devel这个包没有安装,因为默认的yum源没有此包
安装libmcrypt库
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum -y install libmcrypt-devel mhash mcrypt
rpm -qa libmcrypt-devel mhash mcrypt

3.2安装yum无法安装的libiconv库

mkdir -p /home/chengzi/tools
cd /home/chengzi/tools
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar zxf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv

make之后出现如错误

In file included from progname.c:26:0:
 ./stdio.h:1010:1: error: ‘gets’ undeclared here (not in a function)
 _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
 ^
 make[2]: *** [progname.o] Error 1
 make[2]: Leaving directory `/usr/local/src/zabbix-2.4.7/libiconv-1.14/srclib'
 make[1]: *** [all] Error 2
 make[1]: Leaving directory `/usr/local/src/zabbix-2.4.7/libiconv-1.14/srclib'
 make: *** [all] Error 2
解决办法
vi libiconv-1.14/srclib/stdio.in.h

将698行的代码:_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");替换为:

#if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16)
 _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
#endif
make
make install

3.3开始安装PHP(FastCGI 方式)服务

3.3.1获取PHP软件包

mkdir -p /home/chengzi/tools
cd /home/chengzi/tools
https://pan.baidu.com/s/1b4BxAu  #<==php下载链接
tar xf php-5.5.32.tar.gz
cd php-5.5.32
编译PHP: ./configure  --prefix=/application/php-5.5.32  --with-mysql=mysqlnd  --with-pdo-mysql=mysqlnd  --with-iconv-dir=/usr/local/libiconv  --with-freetype-dir  --with-jpeg-dir  --with-png-dir  --with-zlib  --with-libxml-dir=/usr  --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-xsl  --with-fpm-user=www  --with-fpm-group=www  --enable-ftp  --enable-opcache=no

3.4编译PHP

在编译PHP的过程中防止编译错误,需要提前执行如下命令:

[root@web02 php-5.5.32]# ln -s /application/mysql/lib/libmysqlclient.so.18 /usr/lib64/
[root@web02 php-5.5.32]# touch ext/phar/phar.phar
命令说明:让php能找到指定的库,能访问ext/phar/phar.phar这个文件或目录
[root@web02 php-5.5.32]# make
[root@web02 php-5.5.32]# make install #<-安装PHP生成文件到系统

3.5配置PHP引擎配置文件php.ini

1) 设置软链接以方便访问,命令如下:

[root@web02 php-5.5.32]# ln -s /application/php-5.5.32 /application/php
[root@web02 php-5.5.32]# ls php.ini*
php.ini-development php.ini-production

2) 拷贝PHP配置文件到PHP默认目录,并改文件名称为php.ini,命令如下:

[root@web02 php-5.5.32]# \cp php.ini-production /application/php/lib/php.ini

3.6配置PHP服务(FastCGI方式)的配置文件php-fpm.conf

[root@web02 php]# pwd
/application/php
[root@web02 php]# ll etc/php-fpm.conf
-rw-r--r-- 1 root root 22609 May 24 21:41 etc/php-fpm.conf
[root@web02 php]# cd etc/
[root@web02 etc]# cp php-fpm.conf.default php-fpm.conf

3.7启动PHP

[root@web02 ~]# useradd -s /sbin/nologin -M www
[root@web02 ~]# /application/php/sbin/php-fpm
[root@web02 ~]# ps -ef |grep php-fpm
[root@web02 ~]# lsof -i:9000

4. 配置Nginx支持PHP程序请求访问

[root@iZm5eh8g1nh0vcbupue6dnZ blog]# cat /etc/nginx/nginx.conf
worker_processes 1;
events {
 worker_connections 1024;
}
http {
 client_max_body_size 20m;
 include mime.types;
 default_type application/octet-stream;
 sendfile on;
 keepalive_timeout 65;
 
 include /etc/nginx/conf.d/*.conf; 
 }
[root@iZm5eh8g1nh0vcbupue6dnZ blog]# cat /etc/nginx/conf.d/blog.conf 
 server {
 listen 80;
 server_name xionghaier.centoscn.cn;
 location / {
 root html/blog;
 index index.php index.html index.htm;
 }
 location ~* .*\.(php|php5)?$ {
 root html/blog;
 fastcgi_pass 127.0.0.1:9000;
 fastcgi_index index.php;
 include fastcgi.conf;
 }
 }

5. WordPress博客程序的搭建准备

mysql> create database wordpress;
mysql> show databases like 'wordpress'; #<-查看

3) 创建一个专用的WordPress blog管理用户,命令如下:
mysql> grant all on wordpress.* to 'wordpress'@'localhost' identified by '123456';
#说明:当数据库和PHP服务不在一台机器上,可以执行如下命令授权:
mysql> grant all on wordpress.* to 'wordpress'@'172.16.1.0/255.255.255.0' identified by '123456';
mysql> flush privileges; #<-刷新权限,使得创建用户生效
mysql>show grants for 'wordpress'@'localhost'; #<-查看用户对应的权限
mysql> select user,host from mysql.user; #<-查看数据库里创建的wordpress用户
mysql> quit

6. 获取WordPress博客程序,并放置到blog域名对应虚拟主机的站点目录下

[root@web02 blog]# cd /home/chengzi/tools/
[root@web02 tools]# ls -sh wordpress-4.7.3-zh_CN.tar.gz 
8.1M wordpress-4.7.3-zh_CN.tar.gz
[root@web02 tools]# tar xf wordpress-4.7.3-zh_CN.tar.gz
[root@web02 tools]# mv wordpress/* /usr/share/nginx/html/blog/
[root@web02 blog]# chown -R www.www /usr/share/nginx/html/blog/

 

5
如无特殊说明,文章均为本站原创,转载请注明出处

该文章由 发布

这货来去如风,什么鬼都没留下!!!
发表我的评论

Hi,请填写昵称和邮箱!

取消评论
代码 贴图 加粗 链接 删除线 签到