linux-运维进阶-28 LNMP动态网站架构

linux-运维进阶-28 LNMP动态网站架构

LNMP动态网站架构

LNMP动态网站部署架构是一套由Linux + Nginx + MySQL + PHP组成的动态网站系统解决方案。LNMP中的字母L是Linux系统的意思,不仅可以是RHEL、CentOS、Fedora,还可以是Debian、Ubuntu等系统

开发环境的部署

在使用源码包安装服务程序之前,首先要让安装主机具备编译程序源码的环境,他需要具备C语言、C++语言、Perl语言的编译器,以及各种常见的编译支持函数库程序。因此请先配置妥当Yum软件仓库,然后把下面列出的这些软件包都统统安装上

[root@localhost src]# yum install -y apr* autoconf automake bc bison bzip2 bzip2* compat* cpp curl curl-devel elfutils-libelf-devel flex fontconfig fontconfig-devel freetype freetype* freetype-devel gcc gcc-c++ gd gettext gettext-devel glibc kernel kernel-headers keyutils keyutils-libs-devel krb5-devel libcom_err-devel libpng libpng-devel libjpeg* libsepol-devel libselinux-devel libstdc++-devel libtool* libgomp libxml2 libxml2-devel libXpm* libtifflibtiff* make mpfr ncurses* ntp ncurses-devel openssl openssl-devel patch pcre-devel perlphp-common php-gd policycoreutils telnet t1lib t1lib* nasm nasm* wget zlib-devel unzip

下载软件包

下载安装LNMP动态网站部署架构所需的16个软件源码包和1个用于检查效果的论坛网站系统软件包

[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# wget https://www.linuxprobe.com/Software/cmake-2.8.11.2.tar.gz
[root@localhost src]# wget https://www.linuxprobe.com/Software/cmake-2.8.11.2.tar.gz
[root@localhost src]# wget https://www.linuxprobe.com/Software/freetype-2.5.3.tar.gz
[root@localhost src]# wget https://www.linuxprobe.com/Software/jpegsrc.v9a.tar.gz
[root@localhost src]# wget https://www.linuxprobe.com/Software/libgd-2.1.0.tar.gz
[root@localhost src]# wget https://www.linuxprobe.com/Software/libmcrypt-2.5.8.tar.gz
[root@localhost src]# wget https://www.linuxprobe.com/Software/libpng-1.6.12.tar.gz
[root@localhost src]# wget https://www.linuxprobe.com/Software/libvpx-v1.3.0.tar.bz2
[root@localhost src]# wget https://www.linuxprobe.com/Software/mysql-5.6.19.tar.gz
[root@localhost src]# wget https://www.linuxprobe.com/Software/nginx-1.6.0.tar.gz
[root@localhost src]# wget https://www.linuxprobe.com/Software/openssl-1.0.1h.tar.gz
[root@localhost src]# wget https://www.linuxprobe.com/Software/php-5.5.14.tar.gz
[root@localhost src]# wget https://www.linuxprobe.com/Software/pcre-8.35.tar.gz
[root@localhost src]# wget https://www.linuxprobe.com/Software/t1lib-5.1.2.tar.gz
[root@localhost src]# wget https://www.linuxprobe.com/Software/tiff-4.0.3.tar.gz
[root@localhost src]# wget https://www.linuxprobe.com/Software/yasm-1.2.0.tar.gz
[root@localhost src]# wget https://www.linuxprobe.com/Software/zlib-1.2.8.tar.gz
[root@localhost src]# ls
cmake-2.8.11.2.tar.gz    libgd-2.1.0.tar.gz      mysql-5.6.19.tar.gz    php-5.5.14.tar.gz   zlib-1.2.8.tar.gz
cmake-2.8.11.2.tar.gz.1  libmcrypt-2.5.8.tar.gz  nginx-1.6.0.tar.gz     t1lib-5.1.2.tar.gz
freetype-2.5.3.tar.gz    libpng-1.6.12.tar.gz    openssl-1.0.1h.tar.gz  tiff-4.0.3.tar.gz
jpegsrc.v9a.tar.gz       libvpx-v1.3.0.tar.bz2   pcre-8.35.tar.gz       yasm-1.2.0.tar.gz
[root@localhost src]# 

安装cmake

CMake是Linux系统中一款常用的编译工具。要想通过源码包安装服务程序,就一定要严格遵守上面总结的安装步骤—下载及解压源码包文件、编译源码包代码、生成二进制安装程序、运行二进制的服务程序安装包。

[root@localhost src]# tar xzvf cmake-2.8.11.2.tar.gz 
[root@localhost src]# cd cmake-2.8.11.2
[root@localhost cmake-2.8.11.2]# ./configure 
[root@localhost cmake-2.8.11.2]# make
[root@localhost cmake-2.8.11.2]# make install

配置MySQL服务

[root@localhost cmake-2.8.11.2]# cd ..
[root@localhost src]# useradd mysql -s /sbin/nologin
[root@localhost src]# mkdir -p /usr/local/mysql/var
[root@localhost src]# chown -Rf mysql:mysql /usr/local/mysql

接下来解压、编译、安装MySQL数据库服务程序。在编译数据库时使用的是cmake命令,其中,

-DCMAKE_INSTALL_PREFIX参数用于定义数据库服务程序的保存目录,

-DMYSQL_DATADIR参数用于定义真实数据库文件的目录,

-DSYSCONFDIR则是定义MySQL数据库配置文件的保存目录。(编译时间较长,为了防止ssh断开,建议screen运行!)

[root@localhost src]# tar xzvf mysql-5.6.19.tar.gz
[root@localhost src]# cd mysql-5.6.19
[root@localhost mysql-5.6.19]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/var -DSYSCONFDIR=/etc
[root@localhost mysql-5.6.19]# make
[root@localhost mysql-5.6.19]# make install

为了让MySQL数据库程序正常运转起来,需要先删除/etc目录中的默认配置文件。

然后在MySQL数据库程序的保存目录scripts内找到一个名为mysql_install_db的脚本程序。

执行这个脚本程序并使用–user参数指定MySQL服务的对应账号名称(在前面步骤已经创建)。

使用–basedir参数指定MySQL服务程序的保存目录。

使用–datadir参数指定MySQL真实数据库的文件保存目录。

这样即可生成系统数据库文件,也会生成出新的MySQL服务配置文件。

[root@linuxprobe mysql-5.6.19]# rm -rf /etc/my.cnf
[root@linuxprobe mysql-5.6.19]# cd /usr/local/mysql
[root@linuxprobe mysql]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/var

把系统新生成的MySQL数据库配置文件链接到/etc目录中,然后把程序目录中的开机程序文件复制到/etc/rc.d/init.d目录中,以便通过service命令来管理MySQL数据库服务程序。记得把数据库脚本文件的权限修改成755以便于让用户有执行该脚本的权限:

[root@localhost mysql]# ln -s my.cnf /etc/my.cnf
[root@localhost mysql]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@localhost mysql]# chmod 755 /etc/rc.d/init.d/mysqld

编辑刚复制的MySQL数据库脚本文件,把第46、47行的basedir与datadir参数分别修改为MySQL数据库程序的保存目录和真实数据库的文件内容。

[root@localhost mysql]# vim /etc/rc.d/init.d/mysqld 
46行 basedir=/usr/local/mysql
47行 datadir=/usr/local/mysql/var

启动mysql,并且设置开机启动

[root@localhost mysql]# service mysqld start
Starting MySQL. SUCCESS! 
[root@localhost mysql]# chkconfig mysqld on

把命令所保存的目录永久性地定义到PATH变量中,需要编辑/etc/profile文件并写入追加的命令目录,这样当物理设备在下一次重启时就会永久生效了。如果不想通过重启设备的方式来生效,也可以使用source命令加载一下/ect/profile文件,此时新的PATH变量也可以立即生效了。

[root@localhost mysql]# vim /etc/profile
74行本来是空行,现在插入: export PATH=$PATH:/usr/local/mysql/bin
[root@localhost mysql]# source /etc/profile

MySQL数据库服务程序还会调用到一些程序文件和函数库文件。由于当前是通过源码包方式安装MySQL数据库,因此现在也必须以手动方式把这些文件链接过来。

[root@linuxprobe mysql]# mkdir /var/lib/mysql
[root@linuxprobe mysql]# ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
[root@linuxprobe mysql]# ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
[root@linuxprobe mysql]# ln -s /usr/local/mysql/include/mysql /usr/include/mysql

初始化数据库

  • 设置root管理员在数据库中的密码值(注意,该密码并非root管理员在系统中的密码,这里的密码值默认应该为空,可直接按回车键)。
  • 设置root管理员在数据库中的专有密码。
  • 随后删除匿名账户,并使用root管理员从远程登录数据库,以确保数据库上运行的业务的安全性。
  • 删除默认的测试数据库,取消测试数据库的一系列访问权限。
  • 刷新授权列表,让初始化的设定立即生效。
[root@localhost ~]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
[root@localhost ~]#

登录数据库

[root@localhost ~]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 5.5.60-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [DBaaa]> exit
Bye
[root@localhost ~]#

配置nginx服务

解决相关的软件依赖关系

提供Perl语言兼容的正则表达式库的软件包pcre

[root@localhost ~]# cd /usr/local/src
[root@localhost src]# tar xzvf pcre-8.35.tar.gz
[root@localhost src]# cd pcre-8.35
[root@localhost pcre-8.35]# ./configure --prefix=/usr/local/pcre --enable-utf8
[root@localhost pcre-8.35]# make
[root@localhost pcre-8.35]# make install

openssl软件包是用于提供网站加密证书服务的程序文件,在安装该程序时需要自定义服务程序的安装目录,以便于稍后调用它们的时候更可控。

[root@localhost pcre-8.35]# cd /usr/local/src
[root@localhost src]# tar xzvf openssl-1.0.1h.tar.gz 
[root@localhost src]# cd openssl-1.0.1h
[root@localhost openssl-1.0.1h]# ./config --prefix=/usr/local/openssl
[root@localhost openssl-1.0.1h]# make
[root@localhost openssl-1.0.1h]# make install

openssl软件包安装后默认会在/usr/local/openssl/bin目录中提供很多的可用命令,我们需要像前面的操作那样,将这个目录添加到PATH环境变量中,并写入到配置文件中,最后执行source命令以便让新的PATH环境变量内容可以立即生效

[root@localhost openssl-1.0.1h]# vim /etc/profile
74行改为: export PATH=$PATH:/usr/local/openssl/bin:/usr/local/openssl/bin
[root@localhost openssl-1.0.1h]# source /etc/profile

zlib软件包是用于提供压缩功能的函数库文件。其实Nginx服务程序调用的这些服务程序无需深入了解,只要大致了解其作用就已经足够了

[root@localhost openssl-1.0.1h]# cd /usr/local/src/
[root@localhost src]# tar xzvf zlib-1.2.8.tar.gz
[root@localhost src]# cd zlib-1.2.8
[root@localhost zlib-1.2.8]# ./configure --prefix=/usr/local/zlib
[root@localhost zlib-1.2.8]# make
[root@localhost zlib-1.2.8]# make install

创建一个用于执行Nginx服务程序的账户。账户名称可以自定义

[root@localhost zlib-1.2.8]# cd ..
[root@localhost src]# useradd www -s /sbin/nologin

其中,–prefix参数用于定义服务程序稍后安装到的位置,

–user与–group参数用于指定执行Nginx服务程序的用户名和用户组。

在使用参数调用openssl、zlib、pcre软件包时,请写出软件源码包的解压路径,而不是程序的安装路径

[root@localhost src]# tar xzvf nginx-1.6.0.tar.gz 
[root@localhost src]# cd nginx-1.6.0
[root@localhost nginx-1.6.0]# ./configure --prefix=/usr/local/nginx --without-http_memcached_module --user=www --group=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-openssl=/usr/local/src/openssl-1.0.1h --with-zlib=/usr/local/src/zlib-1.2.8 --with-pcre=/usr/local/src/pcre-8.35
[root@localhost nginx-1.6.0]# make
[root@localhost nginx-1.6.0]# make install

要想启动Nginx服务程序以及将其加入到开机启动项中,也需要有脚本文件。

[root@localhost nginx-1.6.0]# curl https://raw.githubusercontent.com/xcracker/linux_shell/master/init.d/nginx > /etc/rc.d/init.d/nginx
[root@localhost nginx-1.6.0]# chmod 755 /etc/rc.d/init.d/nginx 
[root@localhost nginx-1.6.0]# /etc/rc.d/init.d/nginx restart
Reloading systemd:     [  确定  ]
Starting nginx (via systemctl): [  确定  ]
[root@localhost nginx-1.6.0]# chkconfig nginx on
[root@localhost nginx-1.6.0]# firewall-cmd --add-port=80/tcp --permanent 
success
[root@localhost nginx-1.6.0]# firewall-cmd --reload
success
[root@localhost nginx-1.6.0]#

上面curl链接的网址存放着脚本代码,如下图:

浏览器打开服务器ip,查看是否成功

配置PHP服务

yasm源码包是一款常见的开源汇编器

[root@localhost nginx-1.6.0]# cd ..
[root@localhost src]# tar xzvf yasm-1.2.0.tar.gz 
[root@localhost src]# cd yasm-1.2.0
[root@localhost yasm-1.2.0]# ./configure 
[root@localhost yasm-1.2.0]# make
[root@localhost yasm-1.2.0]# make install

libmcrypt源码包是用于加密算法的扩展库程序

[root@localhost yasm-1.2.0]# cd ..
[root@localhost src]# tar xzvf libmcrypt-2.5.8.tar.gz
[root@localhost src]# cd libmcrypt-2.5.8
[root@localhost libmcrypt-2.5.8]# ./configure
[root@localhost libmcrypt-2.5.8]# make
[root@localhost libmcrypt-2.5.8]# make install

libvpx源码包是用于提供视频编码器的服务程序

[root@linuxprobe libmcrypt-2.5.8]# cd ..
[root@linuxprobe src]# tar xjvf libvpx-v1.3.0.tar.bz2
[root@linuxprobe src]# cd libvpx-v1.3.0
[root@linuxprobe libvpx-v1.3.0]# ./configure --prefix=/usr/local/libvpx --enable-shared --enable-vp9
[root@linuxprobe libvpx-v1.3.0]# make
[root@linuxprobe libvpx-v1.3.0]# make install

tiff源码包是用于提供标签图像文件格式的服务程序

[root@localhost libvpx-v1.3.0]# cd ..
[root@localhost src]# tar xzvf tiff-4.0.3.tar.gz 
[root@localhost src]# cd tiff-4.0.3
[root@localhost tiff-4.0.3]# ./configure --prefix=/usr/local/tiff --enable-shared
[root@localhost tiff-4.0.3]# make
[root@localhost tiff-4.0.3]# make install

libpng源码包是用于提供png图片格式支持函数库的服务程序

[root@localhost tiff-4.0.3]# cd ..
[root@localhost src]# tar xzvf libpng-1.6.12.tar.gz
[root@localhost src]# cd libpng-1.6.12
[root@localhost libpng-1.6.12]# ./configure --prefix=/usr/local/libpng --enable-shared
[root@localhost libpng-1.6.12]# make
[root@localhost libpng-1.6.12]# make install

freetype源码包是用于提供字体支持引擎的服务程序

[root@localhost libpng-1.6.12]# cd ..
[root@localhost src]# tar xzvf freetype-2.5.3.tar.gz 
[root@localhost src]# cd freetype-2.5.3
[root@localhost freetype-2.5.3]# ./configure --prefix=/usr/local/freetype --enable-shared
[root@localhost freetype-2.5.3]# make
[root@localhost freetype-2.5.3]# make install

jpeg源码包是用于提供jpeg图片格式支持函数库的服务程序

[root@localhost freetype-2.5.3]# cd ..
[root@localhost src]# tar xzvf jpegsrc.v9a.tar.gz 
[root@localhost src]# cd jpeg-9a
[root@localhost jpeg-9a]# ./configure --prefix=/usr/local/jpeg --enable-shared
[root@localhost jpeg-9a]# make
[root@localhost jpeg-9a]# make install

libgd源码包是用于提供图形处理的服务程序,在编译libgd源码包时,请记得写入的是jpeg、libpng、freetype、tiff、libvpx等服务程序在系统中的安装路径,即在上面安装过程中使用–prefix参数指定的目录路径

[root@localhost jpeg-9a]# cd ..
[root@localhost src]# tar xzvf libgd-2.1.0.tar.gz 
[root@localhost src]# cd libgd-2.1.0
[root@localhost libgd-2.1.0]# ./configure --prefix=/usr/local/libgd --enable-shared --with-jpeg=/usr/local/jpeg --with-png=/usr/local/libpng --with-freetype=/usr/local/freetype --with-fontconfig=/usr/local/freetype --with-xpm=/usr/ --with-tiff=/usr/local/tiff --with-vpx=/usr/local/libvpx
[root@localhost libgd-2.1.0]# make
[root@localhost libgd-2.1.0]# make install

t1lib源码包是用于提供图片生成函数库的服务程序

安装后把/usr/lib64目录中的函数文件链接到/usr/lib目录中,以便系统能够顺利调取到函数文件

[root@localhost libgd-2.1.0]# cd ..
[root@localhost src]# tar xzvf t1lib-5.1.2.tar.gz 
[root@localhost src]# cd t1lib-5.1.2
[root@localhost t1lib-5.1.2]# ./configure --prefix=/usr/local/t1lib --enable-shared
[root@localhost t1lib-5.1.2]# make
[root@localhost t1lib-5.1.2]# make install
[root@localhost t1lib-5.1.2]# ln -s /usr/lib64/libltdl.so /usr/lib/libltdl.so
[root@localhost t1lib-5.1.2]# cp -frp /usr/lib64/libXpm.so* /usr/lib

此时终于把编译php服务源码包的相关软件包都已经安装部署妥当了。

在开始编译php源码包之前,先定义一个名为LD_LIBRARY_PATH的全局环境变量,该环境变量的作用是帮助系统找到指定的动态链接库文件,这些文件是编译php服务源码包的必须元素之一。

编译php服务源码包时,除了定义要安装到的目录以外,还需要依次定义配置php服务程序配置文件的保存目录、MySQL数据库服务程序所在目录、MySQL数据库服务程序配置文件所在目录,以及libpng、jpeg、freetype、libvpx、zlib、t1lib等服务程序的安装目录路径,并通过参数启动php服务程序的诸多默认功能

[root@localhost t1lib-5.1.2]# cd ..
[root@localhost src]# tar -xzvf php-5.5.14.tar.gz 
[root@localhost src]# cd php-5.5.14
[root@localhost php-5.5.14]# export LD_LIBRARY_PATH=/usr/local/libgd/lib
[root@localhost php-5.5.14]# ./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-mysql-sock=/tmp/mysql.sock --with-pdo-mysql=/usr/local/mysql --with-gd --with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/jpeg --with-freetype-dir=/usr/local/freetype --with-xpm-dir=/usr/ --with-vpx-dir=/usr/local/libvpx/ --with-zlib-dir=/usr/local/zlib --with-t1lib=/usr/local/t1lib --with-iconv --enable-libxml --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-opcache --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl --enable-ctype 
[root@localhost php-5.5.14]# make
[root@localhost php-5.5.14]# make install

在php源码包程序安装完成后,需要删除当前默认的配置文件,然后将php服务程序目录中相应的配置文件复制过来

[root@localhost php-5.5.14]# rm -rf /etc/php.ini
[root@localhost php-5.5.14]# ln -s /usr/local/php/etc/php.ini /etc/php.ini
[root@localhost php-5.5.14]# cp php.ini-production /usr/local/php/etc/php.ini
[root@localhost php-5.5.14]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@localhost php-5.5.14]# ln -s /usr/local/php/etc/php-fpm.conf /etc/php-fpm.conf

php-fpm.conf是php服务程序重要的配置文件之一,我们需要启用该配置文件中第25行左右的pid文件保存目录(去掉那一行备注),然后分别将第148和149行的user与group参数分别修改为www账户和用户组名称

[root@localhost php-5.5.14]# vim /usr/local/php/etc/php-fpm.conf
25行 pid = run/php-fpm.pid
148行 user = www
149行 group = www

配置妥当后便可把用于管理php服务的脚本文件复制到/etc/rc.d/init.d中了。为了能够执行脚本,请记得为脚本赋予755权限。最后把php-fpm服务程序加入到开机启动项中

[root@localhost php-5.5.14]# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
[root@localhost php-5.5.14]# chmod 755 /etc/rc.d/init.d/php-fpm
[root@localhost php-5.5.14]# chkconfig php-fpm on

为了安全,编辑php.ini配置文件,在305行的disable_functions参数后面追加上要禁止的功能。(注意:disable_functions = 后面直接接那一大串东西,不要回车换行!)

[root@localhost php-5.5.14]# vim /usr/local/php/etc/php.ini

305行 disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restor e,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,g etservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,po six_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix_getppid,posix_getpwnam,posix_ getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_ setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname

编辑Nginx服务程序的主配置文件,

把第2行的井号(#)删除,然后在后面写上负责运行Nginx服务程序的账户名称和用户组名称;

在第45行的index参数后面写上网站的首页名称。

最后是将第65~71行参数前的井号(#)删除来启用参数,主要是修改第69行的脚本名称路径参数,

其中$document_root变量即为网站信息存储的根目录路径,若没有设置该变量,则Nginx服务程序无法找到网站信息,因此会提示“404页面未找到”的报错信息。

在确认参数信息填写正确后便可重启Nginx服务与php-fpm服务

[root@localhost php-5.5.14]# vim /usr/local/nginx/conf/nginx.conf
2行   user  www;
44行  root   /usr/local/nginx/html;
45行  index  index.html index.htm index.php;
65行  location ~ \.php$ {
66行  root  /usr/local/nginx/html;
67行  fastcgi_pass   127.0.0.1:9000;
68行  fastcgi_index  index.php;
69行  fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;
70行  include        fastcgi_params;
71行  }
[root@localhost php-5.5.14]# systemctl restart nginx
[root@localhost php-5.5.14]# systemctl restart php-fpm

要改动的地方上面也都写了,参考自网上的文章,如果你担心配错要检查的话,看下面配置文件原文:

user  www www;
worker_processes  1;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
    #access_log  logs/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    #gzip  on;
    server {
        listen       80;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {
            root   /usr/local/nginx/html;     #指定索引文件的目录
            index  index.html index.htm index.php;
        }
        #error_page  404              /404.html;
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
         }
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {                   #开启php解析
            root          /usr/local/nginx/html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
           # fastcgi_param  SCRIPT_FILENAME          script$fastcgi_script_name
          改为:
            fastcgi_param  SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;  #指定路径
            include         fastcgi_params;
        }
        # fastcgi_params;
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }

搭建Discuz论坛

为了检验LNMP动态网站环境是否配置妥当,可以使用在上面部署Discuz!系统,然后查看结果。如果能够在LNMP动态网站环境中成功安装使用Discuz!论坛系统,也就意味着这套架构是可用的。Discuz! X3.2是国内最常见的社区论坛系统,在经过十多年的研发后已经成为了全球成熟度最高、覆盖率最广的论坛网站系统之一。

Discuz! X3.2软件包的后缀是.zip格式,因此应当使用专用的unzip命令来进行解压。解压后会在当前目录中出现一个名为upload的文件目录,这里面保存的就是Discuz!论坛的系统程序。我们把Nginx服务程序网站根目录的内容清空后,就可以把这些这个目录中的文件都复制进去了。我们已经把Nginx服务程序的网站根目录的所有者和所属组修改为本地的www用户了,并为其赋予755权限以便于能够读、写、执行该论坛系统内的文件。

[root@localhost php-5.5.14]# cd /usr/local/src/
[root@localhost src]# wget http://download.comsenz.com/DiscuzX/3.2/Discuz_X3.2_SC_UTF8.zip
[root@localhost src]# unzip Discuz_X3.2_SC_UTF8.zip 
[root@localhost src]# rm -rf /usr/local/nginx/html/{index.html,50x.html}*
[root@localhost src]# mv upload/* /usr/local/nginx/html/
[root@localhost src]# chown -Rf www:www /usr/local/nginx/html
[root@localhost src]# chmod -Rf 755 /usr/local/nginx/html
[root@localhost src]# cd
[root@localhost ~]# firewall-cmd --add-port={80,3306}/tcp --permanent
Warning: ALREADY_ENABLED: 80:tcp
success
[root@localhost ~]# firewall-cmd --reload
success
[root@localhost ~]# setenforce 0
[root@localhost ~]# 

打开IP地址,加上/install,如果是下面这个样子,那九成九都是你的配置文件配置错了,需要再次检查:

vim /usr/local/nginx/conf/nginx.conf

如果你的配置文件正确,那么基本上不会有问题,可以开始安装Discuz论坛了。

浏览器敲入ip,它会跳转到http://192.168.141.132/install/,开始安装。

之前初始化mysql的时候你设置的root密码填上,另外再给你的论坛管理员admin想一个密码

论坛登录成功!本篇到此结束。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值