PHP 动态语言以及搭建 blog 和 bbs 论坛 荐

栏目: PHP · 发布时间: 5年前

内容简介:4、准备工作:安装 PHP 前需要的准备环境:检查安装 PHP 所需的 lib 库:先确认 PHP 程序会调用的一些 lib 库是否已经安装:

1、CGI 以及 FastCGI 介绍:

1、CGI全称“通用网关接口”(Common Gateway Interface),用于HTTP服务器与其他服务器上的程序服务通信交流的一种工具,CGI程序须运行在网络服务器上。

主要缺点:性能差。

2、FastCGI是一个可伸缩地、高速地在HTTP服务器和动态脚本语言间通信的接口(FastCGI接口在 linux 下是socket)这个socket可以是文件socket,也可以是ip socket。

主要优点:FastCGI接口方式采用C/S架构,把动态语言和HTTP服务器分离开来。

重要特点总结:

1)、FastCGI是HTTP服务器和动态脚本语言间通讯的接口或工具。

2)、FastCGI优点是把动态语言解析和HTTP服务器分离开来。

3)、Nginx、Apache、lighttpd以及多数动态语言都支持FastCGI。

4)、FastCGI接口方式采用C/S结构,分为客户端(HTTP服务器)和服务端(动态语言解析服务器)。

5)、 PHP 动态语言服务端可以启动多个FastCGI的守护进程。

6)、http服务器通过(例:Nginx fastcgi_pass)FastCGI客户端和动态语言FastCGI服务端通信(例:php-fpm)。

2、Nginx FastCGI的运行原理

Nginx不支持对外部动态程序的直接调用或者解析,所有的外部程序(包括PHP)必须通过FastCGI接口调用。FastCGI接口在linux下是socket,(这个socket可以是文件socket,也可以是ip socket)。为了调用CGI程序,还需要一个FastCGI的wrapper(wrapper可以理解为用于启动另一个程序的程序),这个wrapper绑定在某个固定socket上,如端口或者文件socket。当nginx将CGI请求发送给这个socket的时候,通过FastCGI接口,wrapper接收到请求,然后派生出一个新的线程,这个线程调用解释器或外部程序处理脚本并读取返回数据;接着,wrapper再将返回的数据通过FastCGI接口,沿着固定的socker传递给Nginx;最后,Nginx将返回的数据发送给客户端,这就是Nginx+FastCGI的整个运作过程。

PHP 动态语言以及搭建 blog 和 bbs 论坛 荐

3、检查 Nginx 和 MySQL :

[root@lnmp02 ~]# ls -ld /application/mysql/
drwxr-xr-x 13 root root 4096 Dec 22 02:03 /application/mysql/
[root@lnmp02 ~]# ls -ld /application/nginx/
drwxr-xr-x 11 root root 4096 Dec 18 22:59 /application/nginx/
[root@lnmp02 ~]# netstat -lntup|grep -E "80|3306"
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      1767/mysqld  
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      2946/nginx

4、准备工作:安装 PHP 前需要的准备环境:

检查安装 PHP 所需的 lib 库:

先确认 PHP 程序会调用的一些 lib 库是否已经安装:

[root@lnmp02 ~]# rpm -qa zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel
zlib-devel-1.2.3-29.el6.x86_64
[root@lnmp02 ~]# rpm -qa freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel
提示:这些 lib 库不是必须安装的,但是目前的企业环境下一般都需要安装。否则 PHP 程序运行时会出现问题,例如验证码无法显示等。

安装相关的 lib 软件包:

[root@lnmp02 ~]# yum install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel -y
[root@lnmp02 ~]# yum install freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel -y

安装后的结果如下:

[root@lnmp02 ~]# rpm -qa zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel  
libjpeg-turbo-devel-1.2.1-3.el6_5.x86_64
zlib-devel-1.2.3-29.el6.x86_64
libxml2-devel-2.7.6-21.el6_8.1.x86_64
提示:缺少了  libiconv-devel  包【默认的 yum 源没有此包】
[root@lnmp02 ~]# rpm -qa freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel
libpng-devel-1.2.49-2.el6_7.x86_64
freetype-devel-2.3.11-17.el6.x86_64
gd-devel-2.0.35-11.el6.x86_64
libcurl-devel-7.19.7-53.el6_9.x86_64
libxslt-devel-1.1.26-2.el6_3.1.x86_64
提示:通过编辑 /etc/yum.conf,把 keepcache 改为等于 1 ,可以把每次yum安装包保存下来,不改此处默认安装后将会删除包。
[root@lnmp02 ~]# cat /etc/yum.conf
[main]   
cachedir=/var/cache/yum/$basearch/$releasever    #  修改为 1 后默认存放 yum 包的路径。
keepcache=0   #  此处默认是 0 (安装后删除)
安装 yum 无法安装的 libiconv 库:
mkdir -p /home/oldboy/tools
cd  /home/oldboy/tools
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
echo $?
tar zxf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
make
make install
cd ../
提示:复制多行命令,一次执行即可。

安装 libmcrypt 库:

配置 epel 第三方 yum 源:

[root@lnmp02 tools]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo

安装对应的 libmcrypt-devel 包并查看:

[root@lnmp02 tools]# yum install libmcrypt-devel -y
[root@lnmp02 tools]# rpm -qa libmcrypt-devel
libmcrypt-devel-2.5.8-9.el6.x86_64

安装 mhash 加密扩展库:

[root@lnmp02 tools]# yum install mhash mhash-devel -y   #  需要提前安装 epel 第三方 yum 源。
[root@lnmp02 tools]# rpm -qa mhash mhash-devel      #  查看结果如下。
mhash-devel-0.9.9.9-3.el6.x86_64
mhash-0.9.9.9-3.el6.x86_64

安装 mcrypt 加密扩展库:

[root@lnmp02 tools]# yum install mcrypt -y     #  需要提前安装 epel 第三方 yum 源。
[root@lnmp02 tools]# rpm -qa mcrypt      #  查看结果如下。
mcrypt-2.6.8-10.el6.x86_64

5、开始安装 PHP 服务:【php-5.3.27】

[root@lnmp02 ~]# cd /home/oldboy/tools
[root@lnmp02 tools]# rz -y
[root@lnmp02 tools]# ll
total 202672
 .....................省略若干...................
-rw-r--r--  1 root root  15008639 Dec 25  2017 php-5.3.27.tar.gz
[root@lnmp02 tools]# tar xf php-5.3.27.tar.gz

配置 PHP 软件:

[root@lnmp02 php-5.3.27]#./configure \
--prefix=/application/php5.3.27 \
--with-mysql=/application/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=nginx \
--with-fpm-group=nginx \
--enable-ftp
提示:出现 :Thank you for using PHP. 表示配置成功,正确输出。
[root@lnmp02 php-5.3.27]# ln -s /application/mysql/lib/libmysqlclient.so.18 /usr/lib64/
[root@lnmp02 php-5.3.27]# touch ext/phar/phar.phar
[root@lnmp02 php-5.3.27]# make
提示: 以下内容是正确的提示:
Build complete.
Don't forget to run 'make test'.

安装 PHP 生成文件到系统:

[root@lnmp02 php-5.3.27]# make install      #  下面是正确的提示[ 表示安装成功 ] 。
/home/oldboy/tools/php-5.3.27/build/shtool install -c ext/phar/phar.phar /application/php5.3.27/bin
ln -s -f /application/php5.3.27/bin/phar.phar /application/php5.3.27/bin/phar
Installing PDO headers:          /application/php5.3.27/include/php/ext/pdo/

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

① 设置软链接方便访问:

[root@lnmp02 php-5.3.27]# ln -s /application/php5.3.27/ /application/php
[root@lnmp02 php-5.3.27]# ls -l /application/php
lrwxrwxrwx 1 root root 23 Dec 23 16:45 /application/php -> /application/php5.3.27/

② 查看 PHP 配置默认模板文件:

[root@lnmp02 php-5.3.27]# pwd
/home/oldboy/tools/php-5.3.27
[root@lnmp02 php-5.3.27]# ls -l php.ini*
-rw-r--r-- 1 101 101 69606 Jul 11  2013 php.ini-development     #  开发环境的配置文件。
-rw-r--r-- 1 101 101 69627 Jul 11  2013 php.ini-production     #  生产环境的配置文件。
[root@lnmp02 php-5.3.27]# diff php.ini*
521c521
< error_reporting = E_ALL | E_STRICT
 > error_reporting = E_ALL & ~E_DEPRECATED
538c538
< display_errors = On
> display_errors = Off
549c549
< display_startup_errors = On
> display_startup_errors = Off
.....................省略若干........................
提示:从对比结果可以看出,开发环境更多的是开启日志、调试信息,而生产环境都是关闭状态。

③ 拷贝 PHP 配置文件到 PHP 默认目录,并改名为 php.ini :

[root@lnmp02 php-5.3.27]# cp php.ini-production /application/php/lib/php.ini
[root@lnmp02 php-5.3.27]# ls -l /application/php/lib/php.ini
-rw-r--r-- 1 root root 69627 Dec 23 17:20 /application/php/lib/php.ini
提示:优化 PHP 解析就编辑该配置文件,对该文件的优化说明:待讲解。

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

[root@lnmp02 php-5.3.27]# cd /application/php/etc/   #  该配置文件的默认路径。    
[root@lnmp02 etc]# ll
total 28
-rw-r--r-- 1 root root  1232 Dec 23 16:33 pear.conf
-rw-r--r-- 1 root root 21683 Dec 23 16:33 php-fpm.conf.default
[root@lnmp02 etc]# cp php-fpm.conf.default php-fpm.conf     #  备份并改名为系统默认识别的配置文件。
[root@lnmp02 etc]# ll
total 52
-rw-r--r-- 1 root root  1232 Dec 23 16:33 pear.conf
-rw-r--r-- 1 root root 21683 Dec 23 17:30 php-fpm.conf    #  配置文件。
-rw-r--r-- 1 root root 21683 Dec 23 16:33 php-fpm.conf.default

启动 PHP 服务(FastCGI 方式):

[root@lnmp02 etc]# /application/php/sbin/php-fpm     #  启动 PHP 的命令。
[root@lnmp02 etc]# ps -ef|grep php-fpm    #  查看进程(一个主进程,多个子进程)。
root     128462      1  0 17:47 ?        00:00:00 php-fpm: master process (/application/php5.3.27/etc/php-fpm.conf)
nginx    128463 128462  0 17:47 ?        00:00:00 php-fpm: pool www
nginx    128464 128462  0 17:47 ?        00:00:00 php-fpm: pool www
root     128466  12526  0 17:48 pts/1    00:00:00 grep php-fpm
[root@lnmp02 etc]# lsof -i :9000     #  默认 9000 端口提供服务。
COMMAND    PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
php-fpm 128462  root    7u  IPv4 115538      0t0  TCP localhost:cslistener (LISTEN)
php-fpm 128463 nginx    0u  IPv4 115538      0t0  TCP localhost:cslistener (LISTEN)
php-fpm 128464 nginx    0u  IPv4 115538      0t0  TCP localhost:cslistener (LISTEN)

6、nginx与PHP连接配置与测试:

[root@lnmp02 blog]# cat /application/nginx/conf/extra/blog.conf 
    server {
        listen       80;
        server_name  blog.etiantian.org;
        location / {
                        root   html/blog;
            index  index.html index.htm;
        }
                location ~ .*\.(php|php5)?$ {
                        root   html/blog;
                        fastcgi_pass 127.0.0.1:9000;
                        fastcgi_index index.php;
                        include fastcgi.conf;
                }
            access_log logs/access_blog.log main; 
    }

在/application/nginx/html/blog里写入PHP脚本:

[root@lnmp02 blog]# cat phpinfo.php 
<?php
phpinfo();
?>

然后在网页上查blog.etiantian.org/phpinfo.php

7、PHP与 mysql 连接测试:

在/application/nginx/html/blog里写入PHP脚本:

[root@lnmp02 blog]# cat test_mysql.php 
<?php
        $link_id=mysql_connect('localhost','root','123456') or mysql_error();
        if($link_id){
                    echo "mysql successful by oldboy !";
        }else{
                echo mysql_error();
        }
?>

8、部署 blog 程序服务:

1、开源博客程序 WordPress 介绍:

WordPress 是一套利用 PHP 语言和 MySQL 数据库开发的开源免费的 blog (博客,网站)程序,用户可以在支持 PHP 环境和 MySQL 数据库的服务器上建立 blog 站点。它的功能非常强大,拥有众多插件,易于扩充功能。目前 WordPress 已经成为搭建 blog 平台的主流,很多发布平台都是根据 WordPress 二次开发的。想拥有自己的 blog,购买域名及空间,搭建 LNMP 环境,部署 WordPress 程序后就可以实现了。

2、WordPress 博客程序的搭建准备:

① 登录 MySQL 数据库、创建一个专用数据库 WordPress 用于存放 blog 数据:

[root@lnmp02 blog]# mysql -uroot -p
mysql> create database wordpress;
Query OK, 1 row affected (0.04 sec)
mysql> show databases;           
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| wordpress          |
+--------------------+

② 创建一个专用的 WordPress blog 管理用户:

mysql> grant all on wordpress.* to wordpress@'localhost' identified by '123456';
Query OK, 0 rows affected (0.09 sec)
提示:当数据库和 PHP 服务不在一台机器上,可以执行如下命令授权:
# grant all on wordpress.* to wordpress@'mysql-server-IP’' identified by '123456';
mysql> flush privileges;     #  刷新权限。
Query OK, 0 rows affected (0.06 sec)
mysql> show grants for wordpress@'localhost';   #  查看用户对应的权限。
+------------------------------------------------------------------------------------------------------------------+
| Grants for wordpress@localhost                                                                                   |
+------------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'wordpress'@'localhost' IDENTIFIED BY PASSWORD '*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9' |
| 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 用户访问数据库(特指 blog 库)。
+-----------+-----------+
3 rows in set (0.00 sec)

③ Nginx 及 PHP 环境配置准备:

[root@lnmp02 blog]# pwd
/application/nginx/html/blog
[root@lnmp02 ~]# rz -y
[root@lnmp02 blog]# ll
total 9896
-rw-r--r-- 1 root root 10130710 Dec 26  2017 wordpress-4.9.1-zh_CN.tar.gz
[root@lnmp02 blog]# tar xf wordpress-4.9.1-zh_CN.tar.gz
[root@lnmp02 blog]# ll
total 9900
drwxr-xr-x 5 nobody nfsnobody     4096 Nov 30 20:20 wordpress
-rw-r--r-- 1 root   root      10130710 Dec 26  2017 wordpress-4.9.1-zh_CN.tar.gz
[root@lnmp02 blog]# /bin/mv wordpress-4.9.1-zh_CN.tar.gz  /home/oldboy/tools   #  移走包备份。  
[root@lnmp02 blog]# ll
total 4
drwxr-xr-x 5 nobody nfsnobody 4096 Nov 30 20:20 wordpress
[root@lnmp02 blog]# mv wordpress/* .    #  把上面 wordpress 目录内容移动到当前 blog 根目录。
[root@lnmp02 blog]# ls -l    #  完整的 blog 程序内容。
total 192
-rw-r--r--  1 nobody nfsnobody   418 Sep 25  2013 index.php
-rw-r--r--  1 nobody nfsnobody 19935 Jan  3  2017 license.txt
-rw-r--r--  1 nobody nfsnobody  7001 Nov 30 20:20 readme.html
drwxr-xr-x  2 nobody nfsnobody  4096 Dec 25 08:33 wordpress
-rw-r--r--  1 nobody nfsnobody  5434 Sep 23 20:21 wp-activate.php
drwxr-xr-x  9 nobody nfsnobody  4096 Nov 30 20:20 wp-admin
-rw-r--r--  1 nobody nfsnobody   364 Dec 19  2015 wp-blog-header.php
-rw-r--r--  1 nobody nfsnobody  1627 Aug 29  2016 wp-comments-post.php
-rw-r--r--  1 nobody nfsnobody  2930 Nov 30 20:20 wp-config-sample.php
drwxr-xr-x  5 nobody nfsnobody  4096 Nov 30 20:20 wp-content
-rw-r--r--  1 nobody nfsnobody  3669 Aug 20 12:37 wp-cron.php
drwxr-xr-x 18 nobody nfsnobody 12288 Nov 30 20:20 wp-includes
-rw-r--r--  1 nobody nfsnobody  2422 Nov 21  2016 wp-links-opml.php
-rw-r--r--  1 nobody nfsnobody  3306 Aug 22 19:52 wp-load.php
-rw-r--r--  1 nobody nfsnobody 36583 Oct 13 10:10 wp-login.php
-rw-r--r--  1 nobody nfsnobody  8048 Jan 11  2017 wp-mail.php
-rw-r--r--  1 nobody nfsnobody 16246 Oct  4 08:20 wp-settings.php
-rw-r--r--  1 nobody nfsnobody 30071 Oct 19 01:36 wp-signup.php
-rw-r--r--  1 nobody nfsnobody  4620 Oct 24 06:12 wp-trackback.php
-rw-r--r--  1 nobody nfsnobody  3065 Sep  1  2016 xmlrpc.php
[root@lnmp02 blog]# rm -fr wordpress/   #  删掉没用的目录(已被掏空)。
[root@lnmp02 html]# ls -ld blog/
drwxr-xr-x 5 root root 4096 Dec 25 08:46 blog/   #   blog 站点目录需要授权 Nginx 和 PHP 访问。
[root@lnmp02 html]# chown -R nginx.nginx blog/   #  此授权方法不是特别安全。★★★★★
[root@lnmp02 html]# ls -ld blog/
drwxr-xr-x 5 nginx nginx 4096 Dec 25 08:46 blog/
[root@lnmp02 html]# cd blog/
[root@lnmp02 blog]# ll     #  blog 程序所有内容属主属组都改为 nginx 了。
total 188
-rw-r--r--  1 nginx nginx   418 Sep 25  2013 index.php
-rw-r--r--  1 nginx nginx 19935 Jan  3  2017 license.txt
...............................省略若干行.......................................
-rw-r--r--  1 nginx nginx  4620 Oct 24 06:12 wp-trackback.php
-rw-r--r--  1 nginx nginx  3065 Sep  1  2016 xmlrpc.php

PHP 服务控制权限防止***安全方案详解:权限体系示意图:

[root@lnmp02 blog]# pwd
/application/nginx/html/blog
[root@lnmp02 blog]# cd ../
[root@lnmp02 html]# chown -R root.root blog/     #  先把 站点目录的权限都给 root 。
[root@lnmp02 html]# find ./blog/ -type f|xargs chmod 644   #  所有的文件权限都给 644。
[root@lnmp02 html]# find ./blog/ -type d|xargs chmod 755   #  所有的目录权限都给 755。
[root@lnmp02 html]# mkdir blog/wp-content/uploads   #  创建上传目录。
提示:如果不知道上传目录是什么,就上传一个文件,系统会自动生成上传目录。
[root@lnmp02 html]# chown -R nginx.nginx blog/wp-content/uploads  # 授权该目录为 nginx 。

选择前文配置好的支持 LNMP 的 blog 域名对应的虚拟主机:

[root@lnmp02 conf]# cd /application/nginx/conf/extra/
[root@lnmp02 extra]# ll
total 16
-rw-r--r-- 1 root root 332 Dec 21 14:58 bbs.conf
-rw-r--r-- 1 root root 524 Dec 25 05:14 blog.conf
-rw-r--r-- 1 root root 168 Dec 21 00:52 status.conf
-rw-r--r-- 1 root root 463 Dec 21 16:01 www.conf
[root@lnmp02 extra]# vi blog.conf
[root@lnmp02 extra]# cat blog.conf   
    server {
        listen       80;
        server_name  blog.etiantian.org;
        root   html/blog;
        location / {
            index index.php  index.html index.htm;    #  补充一个首页文件 index.php 。   
        }
        location ~ .*\.(php|php5)?$ {
            root html/blog;
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_index  index.php;
            include fastcgi.conf;
        }
        # access_log  logs/access_blog.log  main;
        access_log  logs/access_blog.log  main gzip buffer=32k flush=5s;
        # access_log off;
    }
[root@lnmp02 extra]# ../../sbin/nginx -t   #  检查语法。
[root@lnmp02 extra]# ../../sbin/nginx -s reload    #  重新加载。

开始安装 blog 博客程序:

① 在浏览器访问 blog.eitantian.org。【提前做好 hosts 或 DNS 解析】

② 单击上图 "现在就开始" 按钮,在出现的页面填入如下内容:

③ 单击结尾 "提交" 按钮继续:

④ 拷贝滚动条内容,手动创建上图提示的 wp-config.php 文件:

[root@lnmp02 blog]# vi wp-config.php
[root@lnmp02 blog]# ll wp-config.php
-rw-r--r-- 1 root root 3114 Dec 25 10:17 wp-config.php
[root@lnmp02 blog]# mysql -uroot -p123456   #  登录数据库。
mysql> use wordpress   #  切到 wordpress 库。
Database changed
mysql> show tables;      #  查看数据表【无】。
Empty set (0.00 sec)

⑤ 点击上图 "开始安装" 按钮:【初始安装,生成表】

查看数据库,生成很多数据表:

mysql> show tables;
+-----------------------+
| Tables_in_wordpress   |
+-----------------------+
| ol_commentmeta        |
| ol_comments           |
| ol_links              |
| ol_options            |
| ol_postmeta           |
| ol_posts              |
| ol_term_relationships |
| ol_term_taxonomy      |
| ol_termmeta           |
| ol_terms              |
| ol_usermeta           |
| ol_users              |
+-----------------------+
12 rows in set (0.00 sec)
mysql> select * from ol_users;   #  查看 user 表,有一些用户信息 [ 略 ] 。

⑥ 到如下界面表示安装成功,点击登录:

输入用户及密码,如下所示:

⑦ 下图为登录后台后的界面,左边是管理菜单:

⑧ 开始写文章:[ 过程略 ]

⑨ 查看上传目录:

[root@lnmp02 blog]# ll wp-content/uploads/2017/12/
total 60
-rw-r--r-- 1 nginx nginx  4388 Dec 25 10:50  来自地球最帅的男人-科比-100x100.jpg
-rw-r--r-- 1 nginx nginx  7797 Dec 25 10:50  来自地球最帅的男人-科比-150x150.jpg
-rw-r--r-- 1 nginx nginx 15237 Dec 25 10:50 来自地球最帅的男人-科比-300x187.jpg
-rw-r--r-- 1 nginx nginx 26339 Dec 25 10:50 来自地球最帅的男人-科比.jpg

为博客程序配置实现 URL 伪静态:

实现此功能,首先要在 WordPress 后台依次单击设置--->固定链接--->自定义结构,然后输入下面的代码,并保存更改:/archives/%post_id%.html 如下图所示:

接着,在 nginx 的 blog 配置文件 server 容器中添加下面代码:

[root@lnmp02 extra]# vi blog.conf
[root@lnmp02 extra]# cat blog.conf                      
    server {
        listen       80;
        server_name  blog.etiantian.org;
        root   html/blog;
        location / {
            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 html/blog;
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_index  index.php;
            include fastcgi.conf;
        }
        # access_log  logs/access_blog.log  main;
        access_log  logs/access_blog.log  main gzip buffer=32k flush=5s;
        # access_log off;
    }

然后检查语法,重新加载 Nginx 服务,操作如下:

[root@lnmp02 extra]# /application/nginx/sbin/nginx -t
nginx: the configuration file /application/nginx-1.6.3/conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.6.3/conf/nginx.conf test is successful
[root@lnmp02 extra]# /application/nginx/sbin/nginx -s reload

最后,实现通过浏览器访问博客伪静态页面:

登陆数据库查看该博客在后台数据库的信息:

[root@lnmp02 extra]# mysql -uroot -p123456   #  登录数据库。
mysql> use wordpress;    #  切到博客数据库 WordPress 库。
Database changed
mysql> show tables;    #  展示所有数据表。
mysql> select * from ol_posts\G   # 查看 ol_posts 表,内容略。

9、部署bbs(机器:lnmp服务器和独立的mysql服务器)

首先在mysql里建立bbs库,然后授权。

mysql> create database bbs;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| bbs                |
| mysql              |
| performance_schema |
| wordpress          |
+--------------------+
5 rows in set (0.00 sec)

mysql> grant all on bbs.* to bbs@'192.168.153.%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> select user,host from mysql.user;
+-----------+---------------+
| user      | host          |
+-----------+---------------+
| root      | 127.0.0.1     |
| bbs       | 192.168.153.% |
| wordpress | 192.168.153.% |
| root      | localhost     |
+-----------+---------------+
4 rows in set (0.00 sec)

然后在lnmp服务器上配置bbs文件。

[root@lnmp02 bbs]# cat /application/nginx/conf/extra/bbs.conf   
        server {
                listen       80;
                server_name  bbs.etiantian.org;
                location / {
                    root   html/bbs;
                    index  index.php index.html index.htm;
            }
                location ~ .*\.(php|php5)?$ {
                        root   html/bbs;
                        fastcgi_pass 127.0.0.1:9000;
                        fastcgi_index index.php;
                        include fastcgi.conf;
            }
                access_log logs/access_bbs.log main;
        }

然后再网页上输入Discuz下载bbs

[root@lnmp02 bbs]# wget http://download.comsenz.com/DiscuzX/3.2/Discuz_X3.2_SC_UTF8.zip   
[root@lnmp02 bbs]# unzip Discuz_X3.2_SC_UTF8.zip
[root@lnmp02 bbs]# ll
总用量 12212
-rw-r--r--  1 root root 12486773 9月  13 11:08 Discuz_X3.2_SC_UTF8.zip
-rw-r--r--  1 root root       18 12月 19 06:23 index.html
drwxr-xr-x  2 root root     4096 12月 29 09:16 readme
drwxr-xr-x 12 root root     4096 12月 29 09:16 upload
drwxr-xr-x  4 root root     4096 12月 29 09:16 utility
[root@lnmp02 bbs]# rm -fr readme/ utility/
[root@lnmp02 bbs]# rm -f index.html 
[root@lnmp02 bbs]# mv Discuz_X3.2_SC_UTF8.zip /home/oldboy/tools/
[root@lnmp02 bbs]# mv upload/* .
授权:[root@lnmp02 html]# chown -R nginx.nginx bbs/
安全的话:[root@lnmp02 bbs]# chown -R nginx.nginx config/data/uc_*

安装完成后,再把mysql里bbs用户的权限改小。(安全)

mysql> drop user bbs@'192.168.153.%';
Query OK, 0 rows affected (0.00 sec)

mysql> select user,host from mysql.user;
+-----------+---------------+
| user      | host          |
+-----------+---------------+
| root      | 127.0.0.1     |
| wordpress | 192.168.153.% |
| root      | localhost     |
+-----------+---------------+
3 rows in set (0.00 sec)

mysql> grant insert,delete,update,select,drop on bbs.* to bbs@'192.168.153.%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

安装完成后,找到一下这个页面,安全起见,删除安装过的程序:

[root@lnmp02 bbs]# rm -fr install/
PHP 动态语言以及搭建 blog 和 bbs 论坛 荐

设置bbs伪静态:

首先找到

PHP 动态语言以及搭建 blog 和 bbs 论坛 荐

然后在下面的页面上全打上勾,提交。

PHP 动态语言以及搭建 blog 和 bbs 论坛 荐

然后在页面右上角找到以下页面,进去找nginx的配置。

PHP 动态语言以及搭建 blog 和 bbs 论坛 荐

最后将这些配置放到bbs配置文件里:

[root@lnmp02 extra]# cat bbs.conf 
        server {
                listen       80;
                server_name  bbs.etiantian.org;
                location / {
                    root   html/bbs;
                    index  index.php index.html index.htm;
                        rewrite ^([^\.]*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2 last;
                        rewrite ^([^\.]*)/article-([0-9]+)-([0-9]+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3 last;
                        rewrite ^([^\.]*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last;
                        rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3 last;
                        rewrite ^([^\.]*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3 last;
                        rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3 last;
                        rewrite ^([^\.]*)/blog-([0-9]+)-([0-9]+)\.html$ $1/home.php?mod=space&uid=$2&do=blog&id=$3 last;
                        rewrite ^([^\.]*)/(fid|tid)-([0-9]+)\.html$ $1/index.php?action=$2&value=$3 last;
                        rewrite ^([^\.]*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ $1/plugin.php?id=$2:$3 last;
                        if (!-e $request_filename) {
                                        return 404;
                        }
            }
                location ~ .*\.(php|php5)?$ {
                        root   html/bbs;
                        fastcgi_pass 127.0.0.1:9000;
                        fastcgi_index index.php;
                        include fastcgi.conf;
            }
                access_log logs/access_bbs.log main;
        }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

浴缸里的惊叹

浴缸里的惊叹

顾森 / 人民邮电出版社 / 2014-7 / 49.00元

《浴缸里的惊叹》是一本趣题集,里面的题目全部来自于作者顾森十余年来的精心收集,包括几何、组合、行程、数字、概率、逻辑、博弈、策略等诸多类别,其中既有小学奥数当中的经典题目,又有世界级的著名难题,但它们无一例外都是作者心目中的“好题”:题目本身简单而不容易,答案出人意料却又在情理之中,解法优雅精巧令人拍案叫绝。作者还有意设置了语言和情境两个类别的问题,希望让完全没有数学背景的读者也能体会到解题的乐趣......一起来看看 《浴缸里的惊叹》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

html转js在线工具
html转js在线工具

html转js在线工具