Loading

搭建LNMP环境

下载软件包

百度云地址下载地址:http://pan.baidu.com/s/1eSfWNoY

一共有17个包

 [root@localhost lnmp]# ls /usr/local/src/lnmp
libgd-2.1.0.tar.gz      mysql-5.6.19.tar.gz    php-5.5.14.tar.gz cmake-2.8.11.2.tar.gz  
libmcrypt-2.5.8.tar.gz  1lib-5.1.2.tar.gz Discuz_X3.2_SC_GBK.zip    libpng-1.6.12.tar.gz   
nginx-1.6.0.tar.gz     tiff-4.0.3.tar.gz libvpx-v1.3.0.tar.bz2     yasm-1.2.0.tar.gz
openssl-1.0.1h.tar.gz freetype-2.5.3.tar.gz   zlib-1.2.8.tar.gz jpegsrc.v9a.tar.gz   pcre-8.35.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 libXrender gettext gettext-devel glibc kernel kernel-headers keyutils keyutils-libs-devel krb5-devel libcom_err-devel libjpeg-turbo libpng libpng-devel libjpeg* libsepol-devel libselinux-devellibstdc++-devel libtool* libgomp libXau-devel 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

 

安装配置mysql服务

1. 安装cmake编译工具

cd /usr/local/src/lnmp
tar xzvf cmake-2.8.11.2.tar.gz
cd cmake-2.8.11.2/
./configure
make
make install

2.创建用于执行mysql服务程序的帐号:

useradd mysql -s /sbin/nologin

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

mkdir -p /usr/local/mysql/var
chown -Rf mysql:mysql /usr/local/mysql

4.安装Mysql服务程序

cd /usr/local/src/lnmp
tar xzvf mysql-5.6.19.tar.gz
cd mysql-5.6.19/
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/var -DSYSCONFDIR=/etc
make
make install

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

rm -rf /etc/my.cnf

6.生成系统数据库

cd /usr/local/mysql
./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/var

7.创建配置文件的软连接文件my.cnf

ln -s /usr/local/mysql/my.cnf /etc/my.cnf 

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

cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod 755 /etc/rc.d/init.d/mysqld
chkconfig mysqld on

9.编辑启动项的配置文件:

vim /etc/init.d/mysqld

basedir=/usr/local/mysql
datadir=/usr/local/mysql/var

10.启动mysqld服务程序:

service mysqld start

11.把mysql服务程序命令目录添加到环境变量中

echo "export PATH=$PATH:/usr/local/mysql/bin" >>/etc/profile
source /etc/profile

12.将mysqld服务程序的库文件链接到默认的位置:

mkdir /var/lib/mysql
ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
ln -s /usr/local/mysql/include/mysql /usr/include/mysql
ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock

13.初始化mysqld服务程序:

[root@lnmp 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...

 

安装nginx服务

1.安装PCRE(Perl兼容的正则表达式库)

cd /usr/local/src/lnmp/
mkdir /usr/local/pcre
tar xzvf pcre-8.35.tar.gz
cd pcre-8.35
./configure --prefix=/usr/local/pcre
make
make install

2.安装openssl服务程序

cd /usr/local/src/lnmp/
mkdir /usr/local/openssl
tar xzvf openssl-1.0.1h.tar.gz
cd openssl-1.0.1h
./config --prefix=/usr/local/openssl
make
make install

3.把openssl服务程序命令目录添加到环境变量

//将配置文件最下面的参数追加参数为:
echo "export PATH=$PATH:/usr/local/mysql/bin:/usr/local/openssl/bin" >>/etc/profile
source /etc/profile

4.安装zlib数据压缩函数库

cd /usr/local/src/lnmp/
tar xf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure --prefix=/usr/local/zlib
make
make install

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

useradd www -s /sbin/nologin

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

cd /usr/local/src/lnmp/
tar xf nginx-1.6.0.tar.gz
cd 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/lnmp/openssl-1.0.1h --with-zlib=/usr/local/src/lnmp/zlib-1.2.8 --with-pcre=/usr/local/src/lnmp/pcre-8.35
make
make install
 

7.创建nginx程序脚本

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

8.给脚本执行权限,并使它开机启动

chmod 755 /etc/rc.d/init.d/nginx
chkconfig nginx on

9.启动nginx服务,并访问

 service nginx start

 

安装配置php服务

1.安装yasm汇编器

 

cd /usr/local/src/lnmp
tar zxvf yasm-1.2.0.tar.gz
cd yasm-1.2.0
./configure
make
make install

 

2.安装libmcrypt加密算法扩展库

cd /usr/local/src/lnmp
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make
make install

3.安装libvpx视频编码器

cd /usr/local/src/lnmp
tar xjvf libvpx-v1.3.0.tar.bz2
cd libvpx-v1.3.0
./configure --prefix=/usr/local/libvpx --enable-shared --enable-vp9
make
make install

4.安装Tiff标签图像文件格式

cd /usr/local/src/lnmp
tar zxvf tiff-4.0.3.tar.gz
cd tiff-4.0.3
./configure --prefix=/usr/local/tiff --enable-shared
make
make install

5.安装libpng图片(png格式)函数库

cd /usr/local/src/lnmp
tar zxvf libpng-1.6.12.tar.gz
cd libpng-1.6.12
./configure --prefix=/usr/local/libpng --enable-shared
make
make install

6.安装freetype字体引擎

cd /usr/local/src/lnmp
tar zxvf freetype-2.5.3.tar.gz
cd freetype-2.5.3
./configure --prefix=/usr/local/freetype --enable-shared
make
make install

安装jpeg

tar zxvf jpegsrc.v9a.tar.gz
cd jpeg-9a
./configure --prefix=/usr/local/jpeg --enable-shared
make
make install

  

7.安装libgd图像处理程序

cd /usr/local/src/lnmp
tar zxvf libgd-2.1.0.tar.gz
cd 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
make
make install

8.安装t1lib图片生成函数库

cd /usr/local/src/lnmp
tar zxvf t1lib-5.1.2.tar.gz
cd t1lib-5.1.2
./configure --prefix=/usr/local/t1lib --enable-shared
make
make install

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

cd /usr/local/src/lnmp
ln -s /usr/lib64/libltdl.so /usr/lib/libltdl.so
cp -frp /usr/lib64/libXpm.so* /usr/lib/

10.安装php服务程序

cd /usr/local/src/lnmp
tar -zvxf php-5.5.14.tar.gz
cd php-5.5.14
export LD_LIBRARY_PATH=/usr/local/libgd/lib
./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
make
make install

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

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

删除默认的php配置文件:

rm -rf /etc/php.ini

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

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
ln -s /usr/local/php/etc/php-fpm.conf /etc/php-fpm.conf
ln -s /usr/local/php/etc/php.ini /etc/php.ini

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

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@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 +x /etc/rc.d/init.d/php-fpm
[root@localhost php-5.5.14]# chkconfig php-fpm on

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

 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:

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服务程序:

service nginx restart
service php-fpm start

 

 

搭建discuz论坛

 

cd /usr/local/src/lnmp
unzip Discuz_X3.2_SC_GBK.zip
rm -rf /usr/local/nginx/html/{index.html,50x.html}
mv upload/* /usr/local/nginx/html/
chown -Rf www:www /usr/local/nginx/html
chmod -Rf 755 /usr/local/nginx/html

 

第1步,接受许可协议:

第2步,检查部署环境:

第3步,选择全新安装discuzX论坛:

第4步,填写数据库与论坛管理员信息:

第5步,等待安装完毕:

第6步,访问论坛主页面:

 

posted @ 2016-08-28 11:48  头痛不头痛  阅读(533)  评论(0编辑  收藏  举报