LNMP源码安装

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,高可用系列 2核4GB
简介: wget http://down.linuxprobe.com/Tools/cmake-2.8.11.2.tar.gzwget http://down.
wget http://down.linuxprobe.com/Tools/cmake-2.8.11.2.tar.gz
wget http://down.linuxprobe.com/Tools/Discuz_X3.2_SC_GBK.zip
wget http://down.linuxprobe.com/Tools/freetype-2.5.3.tar.gz
wget http://down.linuxprobe.com/Tools/jpegsrc.v9a.tar.gz
wget http://down.linuxprobe.com/Tools/libgd-2.1.0.tar.gz
wget http://down.linuxprobe.com/Tools/libmcrypt-2.5.8.tar.gz
wget http://down.linuxprobe.com/Tools/libpng-1.6.12.tar.gz
wget http://down.linuxprobe.com/Tools/libvpx-v1.3.0.tar.bz2
wget http://down.linuxprobe.com/Tools/mysql-5.6.19.tar.gz
wget http://down.linuxprobe.com/Tools/nginx-1.6.0.tar.gz
wget http://down.linuxprobe.com/Tools/openssl-1.0.1h.tar.gz
wget http://down.linuxprobe.com/Tools/php-5.5.14.tar.gz
wget http://down.linuxprobe.com/Tools/pcre-8.35.tar.gz
wget http://down.linuxprobe.com/Tools/t1lib-5.1.2.tar.gz
wget http://down.linuxprobe.com/Tools/tiff-4.0.3.tar.gz
wget http://down.linuxprobe.com/Tools/yasm-1.2.0.tar.gz
wget http://down.linuxprobe.com/Tools/zlib-1.2.8.tar.gz

yum install -y apr* autoconf automake bison bzip2 bzip2* compat* cpp curl curl-devel 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* libtiff libtiff* make mpfr ncurses* ntp openssl openssl-devel patch pcre-devel perl php-common php-gd policycoreutils telnet t1lib t1lib* nasm nasm* wget zlib-devel


[root@linuxprobe ~]# iptables -F
[root@linuxprobe ~]# firewall-cmd --permanent --add-service=mysql
success
[root@linuxprobe ~]# firewall-cmd --permanent --add-service=http
success
[root@linuxprobe ~]# firewall-cmd --reload
success

下载所有需要使用的软件包到/usr/local/src目录(17个文件):

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

安装编译工具及库文件(需要安装的程序比较多,请复制全!):

[root@linuxprobe ~]# yum install -y apr* autoconf automake bison bzip2 bzip2* compat* cpp curl curl-devel 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* libtiff libtiff* make mpfr ncurses* ntp openssl openssl-devel patch pcre-devel perl php-common php-gd policycoreutils telnet t1lib t1lib* nasm nasm* wget zlib-devel
Loaded plugins: langpacks, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
………………省略部分安装过程………………
Installing:
 apr                         x86_64       1.4.8-3.el7               rhel7       103 k
 apr-devel                   x86_64       1.4.8-3.el7               rhel7       188 k
 apr-util                    x86_64       1.5.2-6.el7               rhel7        92 k
 apr-util-devel              x86_64       1.5.2-6.el7               rhel7        76 k
 autoconf                    noarch       2.69-11.el7               rhel7       701 k
 automake                    noarch       1.13.4-3.el7              rhel7       679 k
 bison                       x86_64       2.7-4.el7                 rhel7       578 k
 bzip2-devel                 x86_64       1.0.6-12.el7              rhel7       218 k
 compat-dapl                 x86_64       1:1.2.19-3.el7            rhel7       109 k
 compat-db-headers           noarch       4.7.25-27.el7             rhel7        48 k
 compat-db47                 x86_64       4.7.25-27.el7             rhel7       795 k
 compat-gcc-44               x86_64       4.4.7-8.el7               rhel7        10 M
 compat-gcc-44-c++           x86_64       4.4.7-8.el7               rhel7       6.3 M
 compat-glibc                x86_64       1:2.12-4.el7              rhel7       1.2 M
 compat-glibc-headers        x86_64       1:2.12-4.el7              rhel7       452 k
 compat-libcap1              x86_64       1.10-7.el7                rhel7        19 k
 compat-libf2c-34            x86_64       3.4.6-32.el7              rhel7       155 k
 compat-libgfortran-41       x86_64       4.1.2-44.el7              rhel7       142 k
 compat-libtiff3             x86_64       3.9.4-11.el7              rhel7       135 k
 compat-openldap             x86_64       1:2.3.43-5.el7            rhel7       174 k
 cpp                         x86_64       4.8.2-16.el7              rhel7       5.9 M
 fontconfig-devel            x86_64       2.10.95-7.el7             rhel7       128 k
 freetype-devel              x86_64       2.4.11-9.el7              rhel7       355 k
 gcc                         x86_64       4.8.2-16.el7              rhel7        16 M
 gcc-c++                     x86_64       4.8.2-16.el7              rhel7       7.1 M
 gettext-devel               x86_64       0.18.2.1-4.el7            rhel7       315 k
 kernel-headers              x86_64       3.10.0-123.el7            rhel7       1.4 M
 keyutils-libs-devel         x86_64       1.5.8-3.el7               rhel7        37 k
 krb5-devel                  x86_64       1.11.3-49.el7             rhel7       611 k
 libXpm-devel                x86_64       3.5.10-5.1.el7            rhel7        36 k
 libcom_err-devel            x86_64       1.42.9-4.el7              rhel7        30 k
 libcurl-devel               x86_64       7.29.0-19.el7             rhel7       296 k
 libjpeg-turbo-devel         x86_64       1.2.90-5.el7              rhel7        99 k
 libpng-devel                x86_64       2:1.5.13-5.el7            rhel7       122 k
 libselinux-devel            x86_64       2.2.2-6.el7               rhel7       174 k
 libsepol-devel              x86_64       2.1.9-3.el7               rhel7        71 k
 libstdc++-devel             x86_64       4.8.2-16.el7              rhel7       1.5 M
 libtiff-devel               x86_64       4.0.3-14.el7              rhel7       471 k
 libtool                     x86_64       2.4.2-20.el7              rhel7       588 k
 libtool-ltdl-devel          x86_64       2.4.2-20.el7              rhel7       167 k
 libxml2-devel               x86_64       2.9.1-5.el7               rhel7       1.0 M
 mpfr                        x86_64       3.1.1-4.el7               rhel7       203 k
 nasm                        x86_64       2.10.07-7.el7             rhel7       402 k
 ncurses-devel               x86_64       5.9-13.20130511.el7       rhel7       713 k
 ncurses-term                noarch       5.9-13.20130511.el7       rhel7       543 k
 ntp                         x86_64       4.2.6p5-18.el7            rhel7       539 k
 openssl-devel               x86_64       1:1.0.1e-34.el7           rhel7       1.2 M
 patch                       x86_64       2.7.1-8.el7               rhel7       110 k
 pcre-devel                  x86_64       8.32-12.el7               rhel7       477 k
 php-common                  x86_64       5.4.16-21.el7             rhel7       559 k
 php-gd                      x86_64       5.4.16-21.el7             rhel7       122 k
 t1lib                       x86_64       5.1.2-14.el7              rhel7       166 k
 telnet                      x86_64       1:0.17-59.el7             rhel7        63 k
 zlib-devel                  x86_64       1.2.7-13.el7              rhel7        49 k
Installing for dependencies:
 cyrus-sasl-devel            x86_64       2.1.26-17.el7             rhel7       309 k
 expat-devel                 x86_64       2.1.0-8.el7               rhel7        56 k
 gettext-common-devel        noarch       0.18.2.1-4.el7            rhel7       368 k
 git                         x86_64       1.8.3.1-4.el7             rhel7       4.3 M
 glibc-devel                 x86_64       2.17-55.el7               rhel7       1.0 M
 glibc-headers               x86_64       2.17-55.el7               rhel7       650 k
 libX11-devel                x86_64       1.6.0-2.1.el7             rhel7       979 k
 libXau-devel                x86_64       1.0.8-2.1.el7             rhel7        14 k
 libdb-devel                 x86_64       5.3.21-17.el7             rhel7        38 k
 libmpc                      x86_64       1.0.1-3.el7               rhel7        51 k
 libverto-devel              x86_64       0.2.5-4.el7               rhel7        12 k
 libxcb-devel                x86_64       1.9-5.el7                 rhel7       1.0 M
 libzip                      x86_64       0.10.1-8.el7              rhel7        49 k
 m4                          x86_64       1.4.16-9.el7              rhel7       256 k
 openldap-devel              x86_64       2.4.39-3.el7              rhel7       796 k
 perl-Data-Dumper            x86_64       2.145-3.el7               rhel7        47 k
 perl-Error                  noarch       1:0.17020-2.el7           rhel7        32 k
 perl-Git                    noarch       1.8.3.1-4.el7             rhel7        52 k
 perl-TermReadKey            x86_64       2.30-20.el7               rhel7        31 k
 perl-Test-Harness           noarch       3.28-2.el7                rhel7       302 k
 perl-Thread-Queue           noarch       3.02-2.el7                rhel7        17 k
 xorg-x11-proto-devel        noarch       7.7-8.el7.1               rhel7       281 k
 xz-devel                    x86_64       5.1.2-8alpha.el7          rhel7        44 k
………………省略部分安装过程………………
Complete!

安装cmake编译工具(解压与编译过程已省略):

[root@linuxprobe ~]# cd /usr/local/src
[root@linuxprobe src]# ls
zlib-1.2.8.tar.gz       libmcrypt-2.5.8.tar.gz  pcre-8.35.tar.gz
cmake-2.8.11.2.tar.gz   libpng-1.6.12.tar.gz    php-5.5.14.tar.gz
Discuz_X3.2_SC_GBK.zip  libvpx-v1.3.0.tar.bz2   t1lib-5.1.2.tar.gz
freetype-2.5.3.tar.gz   mysql-5.6.19.tar.gz     tiff-4.0.3.tar.gz
jpegsrc.v9a.tar.gz      nginx-1.6.0.tar.gz      yasm-1.2.0.tar.gz
libgd-2.1.0.tar.gz      openssl-1.0.1h.tar.gz
[root@linuxprobe src]# tar xzvf cmake-2.8.11.2.tar.gz
[root@linuxprobe src]# cd cmake-2.8.11.2/
[root@linuxprobe cmake-2.8.11.2]# ./configure
[root@linuxprobe cmake-2.8.11.2]# make 
[root@linuxprobe cmake-2.8.11.2]# make install
20.2.1 配置Mysql服务

在前面的章节中我们学习了MariaDB数据库管理系统,那么这次实验就学习下如何使用Mysql来管理数据库吧。
创建用于执行mysql服务程序的帐号:

[root@linuxprobe cmake-2.8.11.2]# cd ..
[root@linuxprobe src]# useradd mysql -s /sbin/nologin

创建数据库程序和文件的目录,并设置目录的所属与所组:

[root@linuxprobe src]# mkdir -p /usr/local/mysql/var
[root@linuxprobe src]# chown -Rf mysql:mysql /usr/local/mysql

安装Mysql服务程序(解压与编译过程已省略):

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

删除系统默认的配置文件:

[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

创建配置文件的软连接文件:

[root@linuxprobe mysql]# ln -s my.cnf /etc/my.cnf 

将mysqld服务程序添加到开机启动项:

[root@linuxprobe mysql]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@linuxprobe mysql]# chmod 755 /etc/rc.d/init.d/mysqld
[root@linuxprobe mysql]# chkconfig mysqld on

编辑启动项的配置文件:

[root@linuxprobe mysql]# vim /etc/rc.d/init.d/mysqld 
//分别修改第46与47行,basedir为程序安装路径,datadir为数据库存放目录。
basedir=/usr/local/mysql
datadir=/usr/local/mysql/var

重启mysqld服务程序:

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

把mysql服务程序命令目录添加到环境变量中(永久生效):

[root@linuxprobe mysql]# vim /etc/profile
//在配置文件的最下面追加:
export PATH=$PATH:/usr/local/mysql/bin
[root@linuxprobe mysql]# source /etc/profile

////////////////////////////////////////可不操作////////////////////////////////////////////////////////////////////////////将mysqld服务程序的库文件链接到默认的位置:

[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 /usr/local/mysql/include/mysql /usr/include/mysql
[root@linuxprobe mysql]# ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

初始化mysqld服务程序:

[root@linuxprobe mysql]# mysql_secure_installation 
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, 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 MySQL
root user without the proper authorisation.
Set root password? [Y/n] y  
New password: 输入要为root用户设置的数据库密码。
Re-enter new password: 重复再输入一次密码。
Password updated successfully!
Reloading privilege tables..
 ... Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL 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(禁止root用户从远程登陆)
 ... Success!
By default, MySQL 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(删除test数据库并取消对其的访问权限)
 - 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!
All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
Cleaning up...

 

20.2.2 配置Nginx服务

Nginx是一款相当优秀的用于部署动态网站的服务程序,Nginx最初是为俄罗斯门户站点而设计的网站服务软件,作为一款轻量级的网站服务软件,因其稳定性和丰富的功能而深受信赖,但最最最被认可的是低系统资源、占用内存少并发能力强,目前国内如新浪、网易、腾讯等门户站均在使用,市场占有份额一直保持在15-16%左右(2015年最新数据)。
第20章 使用LNMP架构部署动态网站环境。第20章 使用LNMP架构部署动态网站环境。
Nginx程序的稳定性来自于它采用了分阶段的资源分配技术,使得CPU与内存占用率会非常低,所以使用Nginx程序部署动态网站环境不仅十分的稳定、高效,而且消耗更少的系统资源,丰富的模块功能也几乎与Apache程序数量相同,现在已经完全的支持了proxy、rewrite、mod_fcgi、ssl、vhosts等常用模块。而且还支持了热部署技术,即能够可以7*24不间断提供服务,即便运行数月也无须重启,而且还可以在不暂停服务的情况下直接对Nginx服务程序进行升级。

坦白来讲,虽然Nginx程序的代码质量非常高,代码很规范,技术成熟,模块扩展也很容易,但Nginx依然存在不少问题,比如Nginx是由俄罗斯人创建的,所以在资料文档方面还并不完善,中文教材的质量更是鱼龙混杂,但Nginx近年来增长势头迅猛,预测未来应该能够在轻量级HTTP服务器市场有不错的未来。

安装PCRE(Perl兼容的正则表达式库,解压与编译过程已省略):

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

安装openssl服务程序(解压与编译过程已省略):

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

把openssl服务程序命令目录添加到环境变量中(永久生效):

[root@linuxprobe pcre-8.35]# vim /etc/profile
//将配置文件最下面的参数追加参数为:
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/openssl/bin
[root@linuxprobe pcre-8.35]# source /etc/profile

安装zlib数据压缩函数库(解压与编译过程已省略):

[root@linuxprobe pcre-8.35]# cd /usr/local/src
[root@linuxprobe src]# mkdir /usr/local/zlib
[root@linuxprobe src]# tar xzvf zlib-1.2.8.tar.gz 
[root@linuxprobe src]# cd zlib-1.2.8
[root@linuxprobe zlib-1.2.8]# ./configure --prefix=/usr/local/zlib
[root@linuxprobe zlib-1.2.8]# make
[root@linuxprobe zlib-1.2.8]# make install

创建用于执行nginx服务的用户:

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

安装nginx服务程序(openssl,zlib,pcre要写成源码解压路径!!!):

[root@linuxprobe src]# tar xzvf nginx-1.6.0.tar.gz 
[root@linuxprobe src]# cd nginx-1.6.0/
[root@linuxprobe nginx-1.6.0]# ./configure --prefix=/usr/local/nginx --without-http_memcached_module --user=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@linuxprobe nginx-1.6.0]# make
[root@linuxprobe nginx-1.6.0]# make install

创建nginx程序脚本(将下面的参数直接复制进去即可):

[root@linuxprobe nginx-1.6.0]# vim /etc/rc.d/init.d/nginx
#!/bin/bash
# nginx - this script starts and stops the nginx daemon
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /usr/local/nginx/logs/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
        if [ -z "`grep $user /etc/passwd`" ]; then
                useradd -M -s /bin/nologin $user
        fi
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; do
        if [ `echo $opt | grep '.*-temp-path'` ]; then
                value=`echo $opt | cut -d "=" -f 2`
                if [ ! -d "$value" ]; then
                        # echo "creating" $value
                        mkdir -p $value && chown -R $user $value
                fi
        fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
#configtest || return $?
stop
sleep 1
start
}
reload() {
#configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
        rh_status_q && exit 0
        $1
        ;;
stop)
        rh_status_q || exit 0
        $1
        ;;
restart|configtest)
$1
;;
reload)
        rh_status_q || exit 7
        $1
        ;;
force-reload)
        force_reload
        ;;
status)
        rh_status
        ;;
condrestart|try-restart)
        rh_status_q || exit 0
        ;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
[root@linuxprobe nginx-1.6.0]# chmod 755 /etc/rc.d/init.d/nginx

重启nginx服务程序并添加到开机启动项:

[root@linuxprobe nginx-1.6.0]# /etc/rc.d/init.d/nginx restart
Restarting nginx (via systemctl):                          [  OK  ]
[root@linuxprobe nginx-1.6.0]# chkconfig nginx on

此时可以通过访问IP来判断nginx服务是否顺利运行:
第20章 使用LNMP架构部署动态网站环境。第20章 使用LNMP架构部署动态网站环境。

20.2.3 配置php服务

安装yasm汇编器(解压与编译过程已省略):

[root@linuxprobe nginx-1.6.0]# cd /usr/local/src
[root@linuxprobe src]# tar zxvf yasm-1.2.0.tar.gz
[root@linuxprobe src]# cd yasm-1.2.0
[root@linuxprobe yasm-1.2.0]# ./configure
[root@linuxprobe yasm-1.2.0]# make
[root@linuxprobe yasm-1.2.0]# make install

安装libmcrypt加密算法扩展库(解压与编译过程已省略):

[root@linuxprobe yasm-1.2.0]# cd /usr/local/src
[root@linuxprobe src]# tar zxvf libmcrypt-2.5.8.tar.gz
[root@linuxprobe src]# cd libmcrypt-2.5.8
[root@linuxprobe libmcrypt-2.5.8]# ./configure
[root@linuxprobe libmcrypt-2.5.8]# make
[root@linuxprobe libmcrypt-2.5.8]# make install

安装libvpx视频编码器(解压与编译过程已省略):

[root@linuxprobe libmcrypt-2.5.8]# cd /usr/local/src
[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@linuxprobe libvpx-v1.3.0]# cd /usr/local/src
[root@linuxprobe src]# tar zxvf tiff-4.0.3.tar.gz
[root@linuxprobe src]# cd tiff-4.0.3
[root@linuxprobe tiff-4.0.3]# ./configure --prefix=/usr/local/tiff --enable-shared
[root@linuxprobe tiff-4.0.3]# make
[root@linuxprobe tiff-4.0.3]# make install

安装libpng图片(png格式)函数库(解压与编译过程已省略):

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

安装freetype字体引擎(解压与编译过程已省略):

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

安装jpeg图片(jpeg格式)函数库(解压与编译过程已省略):

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

安装libgd图像处理程序(解压与编译过程已省略):

[root@linuxprobe jpeg-9a]# cd /usr/local/src
[root@linuxprobe src]# tar zxvf libgd-2.1.0.tar.gz
[root@linuxprobe src]# cd libgd-2.1.0
[root@linuxprobe 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@linuxprobe libgd-2.1.0]# make
[root@linuxprobe libgd-2.1.0]# make install

安装t1lib图片生成函数库(解压与编译过程已省略):

[root@linuxprobe cd libgd-2.1.0]# cd /usr/local/src
[root@linuxprobe src]# tar zxvf t1lib-5.1.2.tar.gz
[root@linuxprobe src]# cd t1lib-5.1.2
[root@linuxprobe t1lib-5.1.2]# ./configure --prefix=/usr/local/t1lib --enable-shared
[root@linuxprobe t1lib-5.1.2]# make
[root@linuxprobe t1lib-5.1.2]# make install

将函数库文件放至合适的位置:

[root@linuxprobe t1lib-5.1.2]# cd /usr/local/src
[root@linuxprobe src]# ln -s /usr/lib64/libltdl.so /usr/lib/libltdl.so
[root@linuxprobe src]# cp -frp /usr/lib64/libXpm.so* /usr/lib/

安装php服务程序(命令比较长,请一定要复制完整!!!):

[root@linuxprobe src]# tar -zvxf php-5.5.14.tar.gz
[root@linuxprobe src]# cd php-5.5.14
[root@linuxprobe php-5.5.14]# export LD_LIBRARY_PATH=/usr/local/libgd/lib
[root@linuxprobe 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@linuxprobe php-5.5.14]# make
[root@linuxprobe php-5.5.14]# make install

复制php服务程序的配置文件到安装目录:

[root@linuxprobe php-5.5.14]# cp php.ini-production /usr/local/php/etc/php.ini

删除默认的php配置文件:

[root@linuxprobe php-5.5.14]# rm -rf /etc/php.ini

创建php配置文件的软连接到/etc/目录中:

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

编辑php服务程序的配置文件:

[root@linuxprobe php-5.5.14]# vim /usr/local/php/etc/php-fpm.conf
//将第25行参数前面的分号去掉。
pid = run/php-fpm.pid
//修改第148和149行,将user与group修改为www。
user = www
group = www

添加php-fpm服务程序到开机启动项:

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

为了保障网站的安全性,禁用掉不安全的功能:

[root@linuxprobe php-5.5.14]# vim /usr/local/php/etc/php.ini
//修改第305行的disable_functions参数,追加参数为:
disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_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服务程序支持php:

[root@linuxprobe php-5.5.14]# vim /usr/local/nginx/conf/nginx.conf
//将第2行前面的#号去掉并修改为user www www ;
//将第45行参数修改为index index.html index.htm index.php;
//将第65-71行前面的#号去掉,修改为:
location ~ \.php$ {
  root           html;
  fastcgi_pass   127.0.0.1:9000;
  fastcgi_index  index.php;
  fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
  include        fastcgi_params;
  }

重启nginx与php-fpm服务程序:

[root@linuxprobe php-5.5.14]# systemctl restart nginx
[root@linuxprobe php-5.5.14]# systemctl restart php-fpm
20.4 搭建discuz论坛

将discuz论坛数据放至网站目录(解压过程已省略):

[root@linuxprobe ~ ]# cd /usr/local/src/
[root@linuxprobe src]# unzip Discuz_X3.2_SC_GBK.zip
[root@linuxprobe src]# rm -rf /usr/local/nginx/html/{index.html,50x.html}
[root@linuxprobe src]# mv upload/* /usr/local/nginx/html/
[root@linuxprobe src]# chown -Rf www:www /usr/local/nginx/html
[root@linuxprobe src]# chmod -Rf 755 /usr/local/nginx/html

相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
7月前
|
弹性计算 关系型数据库 MySQL
一键部署LNMP(源码安装版本)
【4月更文挑战第29天】
86 2
|
7月前
|
运维 应用服务中间件 Linux
LNMP详解(二)——Nginx源码安装与启动
LNMP详解(二)——Nginx源码安装与启动
44 2
|
监控 关系型数据库 应用服务中间件
|
Web App开发 监控 PHP
lnmp安装,zabbix源码安装安装教程
lnmp源码安装,zabbix源码安装,mysql基础
1912 0
|
关系型数据库 MySQL 应用服务中间件
|
SQL Web App开发 关系型数据库
|
关系型数据库 应用服务中间件 PHP
|
关系型数据库 MySQL 应用服务中间件
|
关系型数据库 应用服务中间件 测试技术