一、系统环境
系统环境:LNMP(可选择LAMP)
系统版本:CentOS 6.9 (Minimal)
下面用一个以最小化方式(Minimal)安装的CentOS 6.9操作系统为例,演示LNMP环境完整搭建过程,并且最后部署了一个WordPress博客,最后完成的效果如下:

二、安装Nginx
1、安装Nginx依赖函数库pcre、openssl
[root@localhost ~]# yum -y install pcre pcre-devel openssl-devel openssh

[root@localhost ~]# rpm -qa pcre pcre-devel openssl openssl-devel

2、下载安装Nginx,这里使用的是nginx-1.13.4
[root@localhost ~]# yum -y install wget

[root@localhost ~]# wget -c -P /src https://mirrors.yangxingzhen.com/nginx/nginx-1.13.4.tar.gz
[root@localhost ~]# ls /src

2、解压软件包
[root@localhost ~]# cd /src
[root@localhost src]# tar zxf nginx-1.13.4.tar.gz

3、指定编译参数(需要安装gcc编译器)
[root@localhost ~]# yum -y install gcc gcc-c++

[root@localhost ~]# useradd -s /sbin/nologin www
[root@localhost ~]# cd /src/nginx-1.13.4
[root@localhost nginx-1.13.4]# ./configure –user=www –group=www –prefix=/usr/local/nginx/ –with-http_stub_status_module –with-http_ssl_module


#结果输出0则说明命令执行成功
[root@localhost nginx-1.13.4]# echo $?

4、安装nginx
[root@localhost nginx-1.13.4]# make && make install

# 结果输出0则说明命令执行成功
[root@localhost nginx-1.13.4]# echo $?

5、测试Nginx,启动Nginx
[root@localhost nginx-1.13.4]# /usr/local/nginx/sbin/nginx -t
[root@localhost nginx-1.13.4]# /usr/local/nginx/sbin/nginx

#浏览器输入本机ip

6、域名配置
#因为要搭建一个博客服务,所以这里配置的域名为blog.admin.org,操作过程如下:
[root@localhost conf]# cd /usr/local/nginx/conf/
[root@localhost conf]# grep –vE “^$|#” nginx.conf.default > nginx.conf (过滤空行跟#开头的注释行)
[root@localhost conf]# cat nginx.conf

7、修改Nginx配置文件
编辑nginx.conf,内容如下:
[root@localhost conf]# vim nginx.conf

8、创建域名对应的站点目录及文件
[root@localhost conf]# cd ../html
[root@localhost html]# mkdir blog
[root@localhost html]# echo “This page is: blog.admin.org” > blog/index.html
[root@localhost html]# cat blog/index.html

9、重启nginx
[root@localhost html]# ../sbin/nginx -t
[root@localhost html]# ../sbin/nginx -s reload (平滑重启)

10、本机上进行测试
先修改/etc/hosts
[root@localhost html]# echo “127.0.0.1 blog.admin.org” >> /etc/hosts

再使用命令测试:
[root@localhost html]# curl blog.admin.org
[root@localhost html]# wget blog.admin.org

11、在Windows 7测试(需要添加hosts文件)
C:\Windows\System32\drivers\etc\hosts,添加116.196.117.83 blog.admin.org

三、安装MySQL
1、下载MySQL软件包
[root@localhost ~]# cd /src
[root@localhost src]# wget -c https://mirrors.yangxingzhen.com/mysql/mysql-5.6.36.tar.gz
[root@localhost src]# ls -l

2、解压软件包
[root@localhost src]# tar zxf mysql-5.6.36.tar.gz

3、预编译(MySQL-5.5版本及以上需要cmake)
[root@localhost src]# useradd -s /sbin/nologin mysql
[root@localhost src]# mkdir -p /usr/local/mysql
[root@localhost src]# chown -R mysql.mysql /usr/local/mysql
[root@localhost src]# yum -y install cmake ncurses-devel perl

[root@localhost src]# cd mysql-5.6.36
[root@localhost mysql-5.6.36]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql \
-DSYSCONFDIR=/etc \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306 \
-DWGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_BLACGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_EXDDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all \
-DWITH_BIG_DEBUG=0


4、编译及安装MySQL
[root@localhost mysql-5.6.36]# make &&make install

5、修改配置文件
编辑vim /etc/my.cnf,内容如下
[root@localhost mysql-5.6.36]# vim /etc/my.cnf
[mysqld]
datadir = /data/mysql
socket = /tmp/mysql.sock
user = mysql
log-error = /var/log/mysqld.log
character_set_server = utf8
[client]
default-character-set = utf8
[mysql]
default-character-set = utf8
6、初始化数据库
[root@localhost ~]# mkdir -p /data/mysql
[root@localhost ~]# chown -R mysql.mysql /data/mysql
[root@localhost ~]# /usr/local/mysql/scripts/mysql_install_db –user=mysql –datadir=/data/mysql –basedir=/usr/local/mysql

7、配置并启动MySQL数据库
[root@localhost ~]# ln -s /usr/local/mysql/bin/* /usr/bin
[root@localhost ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]# chmod o+x /etc/init.d/mysqld
[root@localhost ~]# /etc/init.d/mysqld start

#检查端口、进程
[root@localhost ~]# netstat -lntup | grep mysqld
[root@localhost ~]# ps -ef | grep mysqld

8、设置MySQL开机启动
[root@localhost ~]# chkconfig –add mysqld
[root@localhost ~]# chkconfig mysqld on
[root@localhost ~]# chkconfig –list mysqld

9、登录MySQL测试
[root@localhost ~]# mysql
mysql> show databases;

四、安装PHP
# 安装Libiconv
1、安装PHP依赖函数库
[root@localhost ~]# yum install -y zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel

2、安装libmcrypt库、mhash加密扩展库、mcrypt加密扩展库
[root@localhost ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
[root@localhost ~]# yum -y install libmcrypt-devel mhash mcrypt

3、源码安装libiconv
[root@localhost ~]# wget -c https://mirrors.yangxingzhen.com/libiconv/libiconv-1.14.tar.gz
[root@localhost ~]# tar zxf libiconv-1.14.tar.gz
[root@localhost ~]# cd libiconv-1.14
[root@localhost libiconv-1.14]# ./configure –prefix=/usr/local/libiconv
[root@localhost libiconv-1.14]# make &&make install
# 安装PHP
1、下载php源码包,这里采用的是php-5.6.29
[root@localhost libiconv-1.14]# cd /src
[root@localhost src]# wget -c http://mirrors.sohu.com/php/php-5.6.29.tar.gz

2、解压软件包
[root@localhost src]# tar zxf php-5.6.29.tar.gz
[root@localhost src]# ls -l

3、配置PHP的安装参数
[root@localhost src]# cd /src/php-5.6.29
[root@localhost php-5.6.29]# ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64
[root@localhost php-5.6.29]# ./configure –prefix=/usr/local/php \
–with-config-file-path=/usr/local/php/etc \
–with-mysql=/usr/local/mysql \
–with-mysqli=/usr/local/mysql/bin/mysql_config \
–with-pdo-mysql=/usr/local/mysql \
–enable-opcache \
–with-gettext \
–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=www \
–with-fpm-group=www \
–enable-ftp \
–enable-zip


4、编译及安装PHP
[root@localhost php-5.6.29]# make &&make install

5、配置与启动PHP
[root@localhost php-5.6.29]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@localhost php-5.6.29]# /usr/local/php/sbin/php-fpm
#LNMP环境测试
1、修改nginx.conf配置文件

2、配置域名站点目录
[root@localhost php-5.6.29]# cd /usr/local/nginx/html/blog/
[root@localhost blog]# echo “<? phpinfo(); ?>” > test.php
[root@localhost blog]# /usr/local/nginx/sbin/nginx -t
[root@localhost blog]# /usr/local/nginx/sbin/nginx -s reload

3、Windows7主机上在浏览器中输入地址http://blog.admin.org/test.php进行访问

五、安装WordPress
1、MYSQL数据库准备
#进入mysql终端命令行
[root@localhost blog]# mysql

#创建数据库wordpress、创建wordpress用户并授权
mysql> create database wordpress;
mysql> grant all on wordpress.* to wordpress@”localhost” identified by ‘123456’;
mysql> flush privileges;

2、下载wordpress安装包
[root@localhost blog]# cd /src
[root@localhost src]# wget -c https://mirrors.yangxingzhen.com/wordpress/wordpress-4.9.1-zh_CN.tar.gz
3、解压软件包
[root@localhost src]# tar zxf wordpress-4.9.1-zh_CN.tar.gz

4、拷贝WordPress程序到blog目录下,对blog下所有文件授予www用户和组的权限
[root@localhost src]# cd wordpress
[root@localhost wordpress]# cp -a * /usr/local/nginx/html/blog
[root@localhost wordpress]# chown -R www.www /usr/local/nginx/html/blog
5、访问安装WordPress
#在windows7主机浏览器输入http://blog.admin.org

接下来的安装都是非常人性化的,点击”现在就开始”,出现下面的页面:

填好信息后,点击”提交”,如下:

点击”进行安装”,接下来就会让我们填写一些信息,如下:

点击”安装WordPress”,之后就会显示如下页面:

输入账号和密码,会显示如下页面:

显示上面的页面,就说明我们的WordPress安装成功了!接下来就可以好好管理自己的个人WordPress博客站点了!
原创文章,作者:admin,如若转载,请注明出处:https://hostingchat.cn/625.html