@yangwenbo
2021-07-09T15:25:09.000000Z
字数 26487
阅读 442
LNMP
LAMP(即Linux,Apache,MySQL,PHP)
- 性能卓越,服务稳定,很少出现异常宕机。
- 开放源代码且无版权制约,自主性强,使用成本低。
- 历史悠久,社区及用户非常活跃,遇到问题,可以很快获取到帮助。
- 软件体积小,安装使用简单,并且易于维护,安装及维护成本低。
- 支持多种操作系统,提供多种API接口,支持多种开发语言,特别是对流行的PHP语言无缝支持。
- 品牌口碑效应,使得企业无需考虑就直接用之。
序号 | MySQL安装方式 | 特点说明 |
---|---|---|
1 | yum/rpm包安装 | 特点是简单、速度快,但是没法定制安装,入门新手常用这种方式 |
2 | 二进制安装 | 解压软件,简单配置后就可以使用,不用安装,速度较快,专业DBA喜欢这种方式。软件名如:mysql-5.5.32-linux2.6-x86_ 64.tar.gz |
3 | 源码编译安装 | 特点是可以定制安装9,但是安装时间长,例如:字符集安装路径,等等。软件名如: mysql-5.5.32.tar.gz |
4 | 源码软件结合yum/rpm | 把源码软件制作成符合要求的rpm,放到yum仓库里,然后通过yum来安装。结合了上面1和3的优点,即安装快速,可任意定制参数,但是安装者也需要具备更深能力 |
- 备注:安装MySQL的注意事项如下:
- 建议和之前介绍的Nginx服务安装在同一台机器上。
- 重视操作过程的报错输出,有错误要解决掉再继续,不能忽略编译中的错误。
[root@yangwenbo ~]# groupadd mysql
[root@yangwenbo ~]# useradd -s /sbin/nologin -g mysql -M mysql
[root@yangwenbo ~]# tail -1 /etc/passwd
mysql:x:500:500::/home/mysql:/sbin/nologin
[root@yangwenbo ~]# id mysql
uid=500(mysql) gid=500(mysql) groups=500(mysql)
[root@yangwenbo yuanmabao]# pwd
/root/yuanmabao
[root@yangwenbo yuanmabao]# ls
libiconv-1.14.tar.gz
nginx-1.10.2.tar.gz
wordpress-4.7.4-zh_CN.tar.gz
mysql-5.5.32-linux2.6-x86_64.tar.gz #mysql二进制源码
php-5.3.28.tar.gz
[root@yangwenbo yuanmabao]# tar xf mysql-5.5.32-linux2.6-x86_64.tar.gz -C /usr/local/
[root@yangwenbo yuanmabao]# cd /usr/local/
[root@yangwenbo local]# mv mysql-5.5.32-linux2.6-x86_64 mysql-5.5.32
[root@yangwenbo local]# ln -s mysql-5.5.32 mysql
[root@yangwenbo local]# ls
bin etc games include lib lib64 libexec mysql mysql-5.5.32 sbin share src
[root@yangwenbo local]# cd /usr/local/mysql
[root@yangwenbo mysql]# ls
bin data include lib mysql-test scripts sql-bench
COPYING docs INSTALL-BINARY man README share support-files
#提示:二进制安装包,仅需要解压就可以了,不需要执行cmake/configure,make,make install等过程
- 提示:
- 当安装LNMP一体化环境时,MySQL数据库要装在Nginx所在的机器上。如果MySQL和Nginx不在一台机器上,那么,Nginx服务器上的MySQL数据库软件包只要解压移动到/usr/local/目录,改名为mysql就可以了,不需要进行后面的初始化配置。
- 在非一体的LNMP环境(Nginx和MySQL不在一台机器上),编译PHP环境时,也是需要MySQL数据库环境的,但是高版本的PHP,例如5.3版本以上,内置了PHP需要的MySQL程序,因此,对于此类版本就不需要在Nginx服务器上安装MySQL软件了,只需要在编译PHP时指定相关参数即可。这个PHP的编译参数为--with-mysql=mysqld,表示PHP程序在编译时会调用内置的MySQL的库。
[root@yangwenbo mysql]# pwd
/usr/local/mysql
[root@yangwenbo mysql]# ls -l support-files/*.cnf
-rw-r--r--. 1 7161 wheel 4691 Jun 19 2013 support-files/my-huge.cnf
-rw-r--r--. 1 7161 wheel 19759 Jun 19 2013 support-files/my-innodb-heavy-4G.cnf
-rw-r--r--. 1 7161 wheel 4665 Jun 19 2013 support-files/my-large.cnf
-rw-r--r--. 1 7161 wheel 4676 Jun 19 2013 support-files/my-medium.cnf
-rw-r--r--. 1 7161 wheel 2840 Jun 19 2013 support-files/my-small.cnf
[root@yangwenbo mysql]# /bin/cp support-files/my-small.cnf /etc/my.cnf
#使用cp全路径/bin/cp,可实现拷贝而不出现替换提示,即如果有重名文件会直接覆盖
/bin/cp support-files/my-small.cnf /etc/my.cnf
my-medium.cnf (最低)
my-small.cnf
my-large.cnf
my-huge.cnf
my-innodb-heavy-4G.cnf(最高)
[root@yangwenbo ~]# mkdir -p /usr/local/mysql/data #建立MySQL数据文件目录
[root@yangwenbo ~]# chown -R mysql.mysql /usr/local/mysql #授权mysql用户管理MySQL的安装目录
[root@yangwenbo ~]# yum -y install libaio #光盘源安装依赖包,否则下一步的编译会报错
[root@yangwenbo ~]# rpm -q libaio
libaio-0.3.107-10.el6.x86_64
[root@yangwenbo ~]# /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql #数据初始化
#以上省略。。。
Installing MySQL system tables...
OK #初始化MySQL数据库文件,会有很多信息提示,如果没有ERROR级别的错误,会有两个OK的字样,表示初始化成功,否则就要解决初始化的问题
Filling help tables...
OK
#以下省略。。。
usr/local/mysql/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared ob
#错误原因是没有libaio函数库的支持。需要yum -y install libaio
WARNING:The host'mysql'could not be looked up with resolveip
#需要修改主机名解析,使其和uname -n一样,修改后的结果如下:
[root@yangwenbo ~]# grep `uname -n` /etc/hosts
ERROR:1004Can't create file '/tmp/#sql300e_1_o.frm'(errno:13)
#原因是/tmp目录的权限有问题。
解决办法为处理/tmp目录,如下:
[root@yangwenbo ~]# ls -ld /tmp
drwxrwxrwt. 3 root root 4096 Jul 14 07:56 /tmp
[root@yangwenbo ~]# chmod -R 1777 /tmp/
[root@yangwenbo mysql]# pwd
/usr/local/mysql
[root@yangwenbo mysql]# ls
bin data include lib mysql-test scripts sql-bench
COPYING docs INSTALL-BINARY man README share support-files
[root@yangwenbo mysql]# cp support-files/mysql.server /etc/init.d/mysqld #拷贝MySQL启动脚本到MySQL的命令路径
[root@yangwenbo mysql]# chmod +x /etc/init.d/mysqld #使脚本可执行
[root@yangwenbo mysql]# /etc/init.d/mysqld start
Starting MySQL... SUCCESS!
/usr/local/mysql/bin/mysqld_safe --user=mysql &
[root@yangwenbo mysql]# netstat -antup | grep mysql
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 1664/mysqld
[root@yangwenbo mysql]# tail -10 /usr/local/mysql/data/yangwenbo.err
InnoDB: Creating foreign key constraint system tables
InnoDB: Foreign key constraint system tables created
180824 23:21:45 InnoDB: Waiting for the background threads to start
180824 23:21:46 InnoDB: 5.5.32 started; log sequence number 0
180824 23:21:46 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
180824 23:21:46 [Note] - '0.0.0.0' resolves to '0.0.0.0';
180824 23:21:46 [Note] Server socket created on IP: '0.0.0.0'.
180824 23:21:46 [Note] Event Scheduler: Loaded 0 events
180824 23:21:46 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
Version: '5.5.32' socket: '/tmp/mysql.sock' port: 3306 MySQL Community Server (GPL)
[root@yangwenbo mysql]# chkconfig --add mysqld
[root@yangwenbo mysql]# chkconfig mysqld on
[root@yangwenbo mysql]# chkconfig --list mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
/etc/init.d/mysqld start
放到/etc/rc.local
里面
[root@yangwenbo mysql]# ln -s /usr/local/mysql/bin/* /usr/local/bin/
[root@yangwenbo mysql]# which mysqladmin
/usr/local/bin/mysqladmin
[root@yangwenbo mysql]# mysql #第一次测试,之间登录即可
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.32 MySQL Community Server (GPL)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases; #查看当前所有的数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql> select user(); #查看当前的登陆用户
+----------------+
| user() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)
[root@yangwenbo mysql]# mysqladmin -uroot password '971108' #为mysql设置密码
[root@yangwenbo mysql]# mysql #已经无法直接登录
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@yangwenbo mysql]# mysql -uroot -p971108
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.5.32 MySQL Community Server (GPL)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
[root@yangwenbo /]# yum install -y pcre-devel openssl-devel gcc gcc-c++ make curl
[root@yangwenbo /]# rpm -qa pcre-devel openssl-devel gcc gcc-c++ make
openssl-devel-1.0.1e-15.el6.x86_64
gcc-4.4.7-4.el6.x86_64
gcc-c++-4.4.7-4.el6.x86_64
pcre-devel-7.8-6.el6.x86_64
make-3.81-20.el6.x86_64
curl-7.19.7-37.el6_4.x86_64
[root@yangwenbo /]# useradd -s /sbin/nologin -M www
[root@yangwenbo /]# id www
uid=500(www) gid=500(www) groups=500(www)
[root@yangwenbo yang]# ls
nginx-1.10.2.tar.gz
[root@yangwenbo yang]# tar xf nginx-1.10.2.tar.gz -C /usr/src/
[root@yangwenbo yang]#cd /usr/src/nginx-1.10.2
[root@yangwenbo nginx-1.10.2]# ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
以下省略。。。
[root@Nginx ngyangwenboinx-1.10.2]# make && make install
以下省略。。。
[root@yangwenbo nginx-1.10.2]# ln -s /usr/local/nginx/sbin/* /usr/local/sbin/
[root@yangwenbo nginx-1.10.2]# /usr/local/nginx/sbin/nginx
- HTTP服务器和动态脚本语言间通信的接口或工具。
- 可把动态语言解析和HTTP服务器分离开。
- Nginx,Apache,Lighttpd,以及多数动态语言都支持FastCGI。
- FastCGI接口方式采用C/S结构,分为客户端(HTTP服务器)和服务器端(动态语言解析服务器)
- PHP动态语言服务器端可以启动多个FastCGI的守护进程(例如php-fpm(fcgi process mangement))
- HTTP服务器通过(例如Nginx fastcgi_pass)FastCGI客户端和动态语言FastCGI服务器端通信(例如php-fpm)
Nginx不支持对外部动态程序的直接调用或者解析,所有的外部程序(包括PHP)必须通过FastCGI接口来调用。FastCGI接口在Linux下是socket,为了调用CGI程序,还需要一个FastCGI的wrapper(可以理解为用于启动另一个程序的程序),这个wrappper绑定在某个固定的socket上,如端口或文件socket。当Nginx将CGI请求发送给这个socket的时候,通过FastCGI接口,wrapper接收到请求,然后派生出一个新的线程,这个线程调用解释器或外部程序处理脚本来读取返回的数据;接着,wrapper再将返回的数据通过FastCGI接口,沿着固定的socket传递给Nginx;最后,Nginx将返回的数据发送给客户端,这就是Nginx+FastCGI的整个运作过程。
FastCGI的主要优点是把动态语言和HTTP服务器分离开来,使Nginx专门处理静态请求及向后转发的动态请求,而PHP/PHP-FPM服务器则专门解析PHP动态请求。
[root@yangwenbo ~]# ls -ld /usr/local/nginx
drwxr-xr-x. 11 root root 4096 Aug 24 23:57 /usr/local/nginx
[root@yangwenbo ~]# ls -ld /usr/local/mysql
lrwxrwxrwx. 1 mysql mysql 12 Aug 24 22:58 /usr/local/mysql -> mysql-5.5.32
[root@yangwenbo ~]# netstat -antup | grep -E "80|3306"
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 6250/nginx
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 1664/mysqld
wget
[root@yangwenbo ~]# yum -y install wget
[root@yangwenbo ~]# rpm -qa wget
wget-1.12-1.8.el6.x86_64
[root@yangwenbo ~]# wget 127.0.0.1 #测试Nginx
--2018-08-25 00:08:52-- http://127.0.0.1/
Connecting to 127.0.0.1:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 612 [text/html]
Saving to: “index.html”
100%[======================================================>] 612 --.-K/s in 0s
2018-08-25 00:08:52 (106 MB/s) - “index.html” saved [612/612]
[root@yangwenbo ~]# mysql -uroot -p971108 #测试MySQL
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.5.32 MySQL Community Server (GPL)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> exit
Bye
[root@yangwenbo ~]# rpm -qa zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel
zlib-devel-1.2.3-29.el6.x86_64
[root@yangwenbo ~]# rpm -qa freetype-devel libpng-devel gd libcurl-devel libxslt-devel
- 每个lib一般都会存在对应的以“*-devel”命名的包,安装lib对应的-devel包后,对应的lib包就会自动安装好,例如安装gd-devel时就会安装gd。
- 这些lib库不是必须安装的,但是目前的企业环境下一般都需要安装。否则,PHP程序运行时会出现问题,例如验证码无法显示等。
[root@yangwenbo ~]# yum -y install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel
[root@yangwenbo ~]# rpm -qa zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel
zlib-devel-1.2.3-29.el6.x86_64
libxml2-devel-2.7.6-14.el6.x86_64
libjpeg-turbo-devel-1.2.1-1.el6.x86_64
#这里仅缺少libiconv-devel包
------------------------------------------------
[root@yangwenbo ~]# yum -y install freetype-devel libpng-devel gd libcurl-devel libxslt-devel
[root@yangwenbo ~]# rpm -qa freetype-devel libpng-devel gd libcurl-devel libxslt-devel
libcurl-devel-7.19.7-37.el6_4.x86_64
freetype-devel-2.3.11-14.el6_3.1.x86_64
libxslt-devel-1.1.26-2.el6_3.1.x86_64
gd-2.0.35-11.el6.x86_64
libpng-devel-1.2.49-1.el6_2.x86_64
[root@yangwenbo rpm]# pwd
/root/rpm
[root@yangwenbo rpm]# wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
--2018-08-25 00:21:11-- http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
Resolving ftp.gnu.org... 208.118.235.20, 2001:4830:134:3::b
Connecting to ftp.gnu.org|208.118.235.20|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4984397 (4.8M) [application/x-gzip]
Saving to: “libiconv-1.14.tar.gz”
100%[======================================================>] 4,984,397 46.9K/s in 84s
2018-08-25 00:22:36 (58.0 KB/s) - “libiconv-1.14.tar.gz” saved [4984397/4984397]
[root@yangwenbo rpm]# ls
libiconv-1.14.tar.gz #libiconv库
mcrypt-2.6.8-10.el6.x86_64.rpm
libmcrypt-2.5.8-9.el6.x86_64.rpm
mhash-0.9.9.9-3.el6.x86_64.rpm
libmcrypt-devel-2.5.8-9.el6.x86_64.rpm
nginx-1.10.2.tar.gz
[root@yangwenbo rpm]# tar xf libiconv-1.14.tar.gz -C /usr/src/
[root@yangwenbo rpm]# cd /usr/src/libiconv-1.14/srclib
[root@yangwenbo srclib]# sed -i -e '/gets is a security/d' ./stdio.in.h
[root@yangwenbo srclib]# cd /usr/src/libiconv-1.14/
[root@yangwenbo libiconv-1.14]# ./configure --prefix=/usr/local/libiconv && make && make install
#以下省略。。。
[root@yangwenbo libiconv-1.14]# cd /etc/yum.repos.d/
[root@yangwenbo yum.repos.d]# ls
bak CentOS-Media.repo
[root@yangwenbo yum.repos.d]# mv * /tmp/
[root@yangwenbo yum.repos.d]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
--2018-08-25 00:30:19-- http://mirrors.aliyun.com/repo/epel-6.repo
Resolving mirrors.aliyun.com... 42.81.12.220, 42.81.12.221, 42.81.12.217, ...
Connecting to mirrors.aliyun.com|42.81.12.220|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 664 [application/octet-stream]
Saving to: “/etc/yum.repos.d/epel.repo”
100%[======================================================>] 664 --.-K/s in 0s
2018-08-25 00:30:19 (59.9 MB/s) - “/etc/yum.repos.d/epel.repo” saved [664/664]
[root@yangwenbo yum.repos.d]# ls
epel.repo
#清除缓存,建立新缓存省略。。。
[root@yangwenbo yum.repos.d]# yum -y install libmcrypt-devel
[root@yangwenbo yum.repos.d]# rpm -qa libmcrypt-devel
libmcrypt-devel-2.5.8-9.el6.x86_64
[root@yangwenbo yum.repos.d]# yum -y install mhash
[root@yangwenbo yum.repos.d]# rpm -qa mhash
mhash-0.9.9.9-3.el6.x86_64
[root@yangwenbo yum.repos.d]# yum -y install mcrypt
[root@yangwenbo yum.repos.d]# rpm -qa mcrypt
mcrypt-2.6.8-10.el6.x86_64
[root@yangwenbo yuanmabao]# pwd
/root/yuanmabao
[root@yangwenbo yuanmabao]# ls
libiconv-1.14.tar.gz nginx-1.10.2.tar.gz wordpress-4.7.4-zh_CN.tar.gz
mysql-5.5.32-linux2.6-x86_64.tar.gz php-5.3.28.tar.gz
[root@yangwenbo yuanmabao]# tar xf php-5.3.28.tar.gz -C /usr/src/
[root@yangwenbo yuanmabao]# cd /usr/src/php-5.3.28/
[root@yangwenbo php-5.3.28]# ./configure --prefix=/usr/local/php5.3.28 --with-mysql=/usr/local/mysql --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-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --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-zip --enable-soap --enable-short-tags --enable-zend-multibyte --enable-static --with-xsl --with-fpm-user=www --with-fpm-group=www --enable-ftp
表示指定PHP的安装路径为/usr/local/php5.3.28
表示需要指定MySQL的安装路径,安装PHP需要的MySQL相关内容。当然,如果没有MySQL软件包,也可以不单独安装,这样的情况可使用--with-mysql=mysqlnd替代--with-mysql=/usr/local/mysql,因为PHP软件里已经自带了连接MySQL的客户端工具。
nginx表示指定PHP-FPM进程管理的用户为www,此处最好和Nginx服务用户统一
表示指定PHP-FPM进程管理的组为www,此处最好与Nginx服务用户组统一。
表示激活PHP-FPM方式服务,即以FastCGIF方式运行PHP服务。
[root@yangwenbo php-5.3.28]# ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/
[root@yangwenbo php-5.3.28]# touch ext/phar/phar.phar
[root@yangwenbo php-5.3.28]# make
#以下省略。。。
Build complete.
Don't forget to run 'make test'.
[root@yangwenbo php-5.3.28]# make install
#以下省略。。。
[root@yangwenbo ~]# ln -s /usr/local/php5.3.28/ /usr/local/php
[root@yangwenbo ~]# ls -l /usr/local/php
lrwxrwxrwx. 1 root root 21 Aug 25 01:41 /usr/local/php -> /usr/local/php5.3.28/
[root@yangwenbo ~]# cd /usr/src/php-5.3.28/
[root@yangwenbo php-5.3.28]# ls php.ini*
php.ini-development php.ini-production
[root@yangwenbo php-5.3.28]# cp php.ini-production /usr/local/php/lib/php.ini
[root@yangwenbo php-5.3.28]# ls -l /usr/local/php/lib/php.ini
-rw-r--r--. 1 root root 69627 Aug 25 01:43 /usr/local/php/lib/php.ini
[root@yangwenbo php-5.3.28]# cd /usr/local/php/etc/
[root@yangwenbo etc]# ls
pear.conf php-fpm.conf.default
[root@yangwenbo etc]# cp php-fpm.conf.default php-fpm.conf
[root@yangwenbo etc]# /usr/local/php/sbin/php-fpm
[root@yangwenbo etc]# ps -ef | grep php-fpm
root 75930 1 0 01:45 ? 00:00:00 php-fpm: master process (/usr/local/php5.3.28/etc/php-fpm.conf)
www 75931 75930 0 01:45 ? 00:00:00 php-fpm: pool www
www 75932 75930 0 01:45 ? 00:00:00 php-fpm: pool www
root 75940 1137 0 01:48 pts/0 00:00:00 grep php-fpm
[root@yangwenbo extra]# pwd
/usr/local/nginx/conf/extra
[root@yangwenbo extra]# cat www.conf
server {
listen 80;
server_name www.boke.com;
location / {
root /var/www/html/blogcom;
index index.php index.html index.htm;
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}
location ~ .*\.(php|php5)?$ {
root /var/www/html/blogcom;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
[root@yangwenbo html]# cd /usr/local/nginx/conf/
[root@yangwenbo conf]# egrep -v "#|^$" nginx.conf.default > nginx.conf
[root@yangwenbo conf]# pwd
/usr/local/nginx/conf
[root@yangwenbo conf]# cat nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
include extra/www.conf;
}
[root@yangwenbo extra]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@yangwenbo extra]# /usr/local/nginx/sbin/nginx -s reload
[root@yangwenbo extra]# service iptables stop
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
[root@yangwenbo var]# mkdir -p /var/www/html/blogcom/
[root@yangwenbo var]# cd /var/www/html/blogcom/
[root@yangwenbo blogcom]# echo "<?php phpinfo(); ?>" >test_info.php
[root@yangwenbo blogcom]# cat test_info.php
<?php phpinfo(); ?>
192.168.43.228 www.boke.com
[root@yangwenbo blogcom]# pwd
/var/www/html/blogcom
[root@yangwenbo blogcom]# cat test_mysql.php
<?php
//$link_id=mysql_connect('主机名','用户','密码');
$link_id=mysql_connect('localhost','root','971108');
if($link_id){
echo "MySQL welcomes Yang wenbo";
}else{
echo mysql_error();
}
?>
/etc/init.d/mysqld start
/usr/local/nginx/sbin/nginx
/usr/local/php/sbin/php-fpm
service iptables stop
[root@yangwenbo conf]# mysql -uroot -p971108 #登录Mysql数据库
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.5.32 MySQL Community Server (GPL)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database wordpress; #创建一个数据库,名字为wordpress
Query OK, 1 row affected (0.02 sec)
mysql> show databases like 'wordpress'; #查看wordpress数据库
+----------------------+
| Database (wordpress) |
+----------------------+
| wordpress |
+----------------------+
1 row in set (0.01 sec)
mysql> grant all on wordpress.* to wordpress@'localhost' identified by '971108'; #localhost为客户端地址
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges; #刷新权限,使得创建用户生效
Query OK, 0 rows affected (0.00 sec)
mysql> show grants for wordpress@'localhost'; #查看用户对应权限
+-----------------------------------------------------------------------------------------------+
| Grants for wordpress@localhost |
+-----------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'wordpress'@'localhost' IDENTIFIED BY PASSWORD '*2E086B4AB841306370F090F3973AC88BDAA569D3' |
| GRANT ALL PRIVILEGES ON `wordpress`.* TO 'wordpress'@'localhost'
+-----------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
mysql> select user,host from mysql.user; #查看数据库里创建的wordpress用户
+-----------+-----------+
| user | host |
+-----------+-----------+
| root | 127.0.0.1 |
| root | localhost |
| wordpress | localhost | #只允许本机通过wordpress用户访问数据库
+-----------+-----------+
7 rows in set (0.00 sec)
[root@yangwenbo extra]# pwd
/usr/local/nginx/conf/extra
[root@yangwenbo extra]# cat www.conf
server {
listen 80;
server_name www.boke.com;
location / {
root /var/www/html/blogcom;
index install.php index.html index.htm;
} #补充一个首页文件install.php
location ~ .*\.(php|php5)?$ {
root /var/www/html/blogcom;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
[root@yangwenbo extra]# /usr/local/nginx/sbin/nginx -s reload
#平滑重启nginx
/var/www/html/blogcom
,操作命令如下:
[root@yangwenbo yuanmabao]# pwd
/root/yuanmabao
[root@yangwenbo yuanmabao]# ls
wordpress-4.7.4-zh_CN.tar.gz #浏览www.wordpress.org下载博客程序
[root@yangwenbo yuanmabao]# tar xf wordpress-4.7.4-zh_CN.tar.gz #解压缩
[root@yangwenbo yuanmabao]# ls
wordpress wordpress-4.7.4-zh_CN.tar.gz
[root@yangwenbo yuanmabao]# cd /var/www/html/blogcom/
[root@yangwenbo blogcom]# ls
test_info.php test_mysql.php
[root@yangwenbo blogcom]# rm -rf * #删除无用文件(可删可不删)
[root@yangwenbo blogcom]# cd ~/yuanmabao/
[root@yangwenbo yuanmabao]# mv wordpress/* /var/www/html/blogcom/
#把wordpress目录里的内容移动到blogcom根目录下
[root@yangwenbo yuanmabao]# cd /var/www/html/blogcom/
[root@yangwenbo blogcom]# ls -l
#完整的blogcom程序内容(这时可以查看所有blogcom程序内容的属主与属组)
total 188
-rw-r--r--. 1 nobody 65534 418 Sep 25 2013 index.php
-rw-r--r--. 1 nobody 65534 19935 Jan 3 2017 license.txt
-rw-r--r--. 1 nobody 65534 6956 Apr 23 2017 readme.html
-rw-r--r--. 1 nobody 65534 5447 Sep 28 2016 wp-activate.php
drwxr-xr-x. 9 nobody 65534 4096 Apr 23 2017 wp-admin
-rw-r--r--. 1 nobody 65534 364 Dec 19 2015 wp-blog-header.php
-rw-r--r--. 1 nobody 65534 1627 Aug 29 2016 wp-comments-post.php
-rw-r--r--. 1 nobody 65534 2930 Apr 23 2017 wp-config-sample.php
drwxr-xr-x. 5 nobody 65534 4096 Apr 23 2017 wp-content
-rw-r--r--. 1 nobody 65534 3286 May 25 2015 wp-cron.php
drwxr-xr-x. 18 nobody 65534 12288 Apr 23 2017 wp-includes
-rw-r--r--. 1 nobody 65534 2422 Nov 21 2016 wp-links-opml.php
-rw-r--r--. 1 nobody 65534 3301 Oct 25 2016 wp-load.php
-rw-r--r--. 1 nobody 65534 33939 Nov 21 2016 wp-login.php
-rw-r--r--. 1 nobody 65534 8048 Jan 11 2017 wp-mail.php
-rw-r--r--. 1 nobody 65534 16255 Apr 7 2017 wp-settings.php
-rw-r--r--. 1 nobody 65534 29896 Oct 19 2016 wp-signup.php
-rw-r--r--. 1 nobody 65534 4513 Oct 15 2016 wp-trackback.php
-rw-r--r--. 1 nobody 65534 3065 Sep 1 2016 xmlrpc.php
[root@yangwenbo blogcom]# chown -R www.www /var/www/html/blogcom
#授权用户访问(WWW为程序用户)
[root@yangwenbo blogcom]# ls -l #最终博客目录和权限
total 188
-rw-r--r--. 1 www www 418 Sep 25 2013 index.php
-rw-r--r--. 1 www www 19935 Jan 3 2017 license.txt
-rw-r--r--. 1 www www 6956 Apr 23 2017 readme.html
-rw-r--r--. 1 www www 5447 Sep 28 2016 wp-activate.php
drwxr-xr-x. 9 www www 4096 Apr 23 2017 wp-admin
-rw-r--r--. 1 www www 364 Dec 19 2015 wp-blog-header.php
-rw-r--r--. 1 www www 1627 Aug 29 2016 wp-comments-post.php
-rw-r--r--. 1 www www 2930 Apr 23 2017 wp-config-sample.php
drwxr-xr-x. 5 www www 4096 Apr 23 2017 wp-content
-rw-r--r--. 1 www www 3286 May 25 2015 wp-cron.php
drwxr-xr-x. 18 www www 12288 Apr 23 2017 wp-includes
-rw-r--r--. 1 www www 2422 Nov 21 2016 wp-links-opml.php
-rw-r--r--. 1 www www 3301 Oct 25 2016 wp-load.php
-rw-r--r--. 1 www www 33939 Nov 21 2016 wp-login.php
-rw-r--r--. 1 www www 8048 Jan 11 2017 wp-mail.php
-rw-r--r--. 1 www www 16255 Apr 7 2017 wp-settings.php
-rw-r--r--. 1 www www 29896 Oct 19 2016 wp-signup.php
-rw-r--r--. 1 www www 4513 Oct 15 2016 wp-trackback.php
-rw-r--r--. 1 www www 3065 Sep 1 2016 xmlrpc.php
/archives/%post_id%.html
#说明:%post_id%是数据库对应博文内容的唯一ID,例如423
[root@yangwenbo extra]# cat www.conf
server {
listen 80;
server_name www.boke.com;
location / {
root /var/www/html/blogcom;
index index.php index.html index.htm;
if (-f $request_filename/index.html){ #代码
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){ #代码
rewrite (.*) $1/index.php; #代码
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}
location ~ .*\.(php|php5)?$ {
root /var/www/html/blogcom;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
[root@yangwenbo extra]# /usr/local/nginx/sbin/nginx -t #检查语法
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@yangwenbo extra]# /usr/local/nginx/sbin/nginx -s reload #平滑重启nginx