lnmp+wordpress搭建

准备环境:nginx,alisql,php安装包
/data/server服务安装位置
/usr/local/src安装包位置
将nginx,alisql,php安装包上传到centos放到/usr/local/src位置

安装nginx

1、解压tar -zxvf nginx-1.16.0.tar.gz
2、下载依赖包yum install openssl openssl-devel zlib zlib-devel pcre pcre-devel gcc gcc-c++ -y
3、进到目录下./configure --prefix=/data/server/nginx
4、编译安装Make && make install
5、进到配置文件目录下cd /data/server/nginx/conf
6、进到sbin下运行cd /data/server/nginx/sbin
7、运行nginx./nginx
8、检测./nginx -t
9、查看进程ps aux | grep nginx
10、关闭SElinuxsetenforce 0
11、打开浏览器输入 192.168.124.58

二、安装Mysql

1…安装依赖包yum -y install cmake bison git ncurses-devel gcc gcc-c++
2.添加用户groupadd mysqluseradd -g mysql mysql
3.解压unzip AliSQL-AliSQL-5.6.32-9.zip
4.创建MySQL/datamkdir -p /data/server/mysql/data
5.安装perlWget http://repo.openfusion.net/centos7-x86_64//perl-Data-Dumper-2.154-1.of.el7.x86_64.rpm
6.解压perlrpm -ivh http://repo.openfusion.net/centos7-x86_64//perl-Data-Dumper-2.154-1.of.el7.x86_64.rpm
7.进到该目录下cd AliSQL-AliSQL-5.6.32-9/
8.编译安装 cmake -DCMAKE_INSTALL_PREFIX=/data/server/mysql -DMYSQL_UNIX_ADDR=/data/server/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/data/server/mysql/data -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql -DENABLE_DOWNLOADS=1 make make install
9.修改目录属主权限chown -R mysql:mysql /data/server/mysql
10.复制文件 给权限cd /data/server/mysql cp support-files/my-default.cnf ./my.cnf chown -R mysql:mysql my.cnf
11.配置文件vim my.cnf 添加以下代码basedir = /data/server/mysql
datadir = /data/server/mysql/
datasocket = /data/server/mysql/mysql.
socklog-error= /data/server/mysql/data/error.
logpid-file = /data/server/mysql/data/mysql.
piduser = mysqltmpdir = /tmp
12.数据库初始化scripts/mysql_install_db --defaults-file=./my.cnf --user=mysql
13.启动数据库 support-files/mysql.server start 这里会出现以下报错Starting MySQL. ERROR! The server quit without updating PID file (/usr/local/mysql/data/mysql.pid). # rm -rf /etc/my.cnf# rm -rf my.conf# cd data# rm -rf # cd …# scripts/mysql_install_db --defaults-file=./my.cnf --user=mysql # cd support-files/# ./mysql.server start# cd …/bin
14.进入mysql交互环境./mysql -u root -p
15.创建数据库>create database wordpress;>grant all on wordpress.
to [email protected]‘localhost’ identified by’123456’;>flush privileges;>exit

三、安装PHP

1.添加用户groupadd wwwuseradd -g www -s /sbin/nologin -M www
2.安装依赖的程序包yum install zlib libxml libjpeg freetype libpng gd curl libiconv zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel openssl openssl-devel libxslt-devel -y
3.安装 libiconvwget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz
4.解压 libiconv包tar -zxf libiconv-1.15.tar.gz
5.进入到libiconf文件下cd libiconv-1.15
6.编译libiconv./configure --prefix=/data/server/libiconv Make && make install
7.解压tar xzvf php-5.6.30.tar.gz
8.进到php-5.6.30文件下cd /data/server/php-5.6.30
9.编译./configure
–prefix=/data/server/php
–enable-fpm
–with-mysql=mysqlnd
–with-pdo-mysql=mysqlnd
–with-mysqli=mysqlnd
–with-openssl
–with-zlib
–with-gd
–with-jpeg-dir
–with-png-dir
–with-iconv=/data/server/libiconv
–enable-short-tags
–enable-sockets
–enable-zend-multibyte
–enable-soap
–enable-mbstring
–enable-static
–with-curl
–enable-ftp
–with-libxml-dir Make && make install
10. php.ini配置cp php.ini-development /data/server/php/lib/php.ini
11. php-fpm配置cp -R ./sapi/fpm/php-fpm.conf /data/server/php/etc/php-fpm.conf
12. 将php给我们准备好的init.d.php-fpm备份cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
13. 将php-fpm服务添加到chkconfig列表chkconfig --add php-fpm
14. 设置开机自启动chkconfig php-fpm on
15. 启动服务service php-fpm start 在这里会报错:Permission Denied # 配置环境变量vim /etc/profile在最末尾添加PATH=PATH:PATH:HOME/bin:/data/server/php56/bin
#使环境生效
source /etc/profile

php-fpm 服务

cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpmoverwrite ? [y/n]
y

php-fpm 服务

加权限chmod +x /etc/init.d/php-fpm
16.这时再启动php-fpm
service php-fpm start
17.更改配置文件
vim /data/server/nginx/conf/nginx.conf
将user 前面注释去掉
并将nobady改成www www
lnmp+wordpress搭建
在server/location模块下的index栏下 加一个 index.php
lnmp+wordpress搭建
将location ~ .php$ 模块注释去掉

lnmp+wordpress搭建
将/scripts改成$document_root
lnmp+wordpress搭建
18.去到html目录下cd /data/server/nginx/html
19.添加test.php文件
vim test.php
在其中添加

<?php phpinfo() ; ?>

20.进到nginx运行
目录cd /data/server/nginx/sbin
21.重读nginx
./nginx -s reload
22.在浏览器里输入
域名/test.php192.168.124.58/test.php
23.至此,LNMP环境已经搭建成功

四、搭建 wordpress

1.下载wordpresswget https://cn.wordpress.org/wordpress-4.9.4-zh_CN.tar.gz
2.解压tar xf wordpress-4.9.4-zh_CN.tar.gz -C /usr/local/src
3.进到/usr/local/src目录下cd /usr/local/src
4.列出wordpress详细信息ll -d wordpress*
lnmp+wordpress搭建
5.将wordpress文件复制到网页目录下cp -r wordpress /data/server/nginx/html
6.修改Wordpress配置文件
#进到wordpress目录下
cd /data/server/nginx/html/wordpress
#拷贝配置文件
cp -r wp-config-sample.php wp-config.php
#修改wp-config.php
vim wp-config.php
在其中修改数据库名字、账号、密码(这里修改的是mysql中创建的数据库名字、用户、密码)
再将主机改成127.0.0.1(设置自己可以访问)
lnmp+wordpress搭建
7.访问网页
在网址栏输入192.168.124.58/wordpress/
lnmp+wordpress搭建
8.成功
lnmp+wordpress搭建
9.登录

10.再次访问时 能访问到自己的博客输入
192.168.124.58/wordpress
或者
www.nautilus.org/wordpresss

解决报错:
1.访问时显示无法访问网页

解决办法:将nginx,mysql,php全都重新启动
cd /data/server/nginx/sbin
./nginx -s reload
cd /data/server/mysql/support_files
./mysql.server stop
./mysql.server start
cd /data/server/php/bin
service php_fpm start

2.访问网页时404报错
解决办法:vim /data/server/nginx/conf/nginx.con
f将loaction模块下的root栏 改成 html(也就是将html/www后面的www删掉)

3.建立数据库连接时出错
解决方法:
第一种:vim /data/server/nginx/html/wordpress/wp-config.php
将主机下面改成 127.0.0.1
再重启mysql
cd /data/server/mysql/support-files
./mysql.server stop
./mysql.server start
第二种:进到/data/server/mysql/bin
去进到mysql交互环境
cd /data/server/mysql/bin
./mysql -u root -p
重新在wordpress数据库中创建用户及密码

grant all on wordpress.* to [email protected]‘localhost’ identified by’123456’;
flush privileges;
exit
再重启mysql
cd /data/server/mysql/support-files
./mysql.server stop
./mysql.server start