Centos6.8编译安装LNMP环境

前端之家收集整理的这篇文章主要介绍了Centos6.8编译安装LNMP环境前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  • 所需软件包:

[root@Zabbix_ServerTools]#pwd
/usr/local/Tools
[root@Zabbix_ServerTools]#ll
total156480
-rw-r--r--1rootroot5490501Feb242016cmake-3.0.2.tar.gz#MysqL编译工具
-rw-r--r--1rootroot2301350Feb242016freetype-2.5.4.tar.gz#gd库需要
-rw-r--r--1rootroot1000034Feb242016jpegsrc.v9a.tar.gz#gd库需要
-rw-r--r--1rootroot2330322Feb242016libgd-2.1.0.tar.gz#gd库安装包
-rw-r--r--1rootroot1335178Feb242016libmcrypt-2.5.8.tar.gz#PHP扩展
-rw-r--r--1rootroot1479720Sep213:51libpng-1.6.25.tar.gz#gd库需要
-rw-r--r--1rootroot1310159Feb242016libpng-1.6.7.tar.gz
-rw-r--r--1rootroot2084229Feb242016libvpx-v1.3.0.tar.bz2#gd库需要
-rw-r--r--1rootroot33009070Feb242016MysqL-5.6.21.tar.gz
-rw-r--r--1rootroot804164Aug242015Nginx-1.6.2.tar.gz
-rw-r--r--1rootroot4432964Aug242015openssl-1.0.1j.tar.gz#Nginx扩展
-rw-r--r--1rootroot2009464Aug242015pcre-8.36.tar.gz#支持Nginx伪静态
-rw-r--r--1rootroot17514721Feb242016PHP-5.6.3.tar.gz
-rw-r--r--1rootroot1872534Feb242016t1lib-5.1.2.tar.gz#PHP扩展
-rw-r--r--1rootroot2051630Feb242016tiff-4.0.3.tar.gz#gd库需要
-rw-r--r--1rootroot1492156Feb242016yasm-1.3.0.tar.gz#PHP扩展
-rw-r--r--1rootroot571091Aug242015zlib-1.2.8.tar.gz#Nginx扩展
[root@Zabbix_ServerTools]#


  • 安装编译工具及库文件(使用yum命令安装)

[root@Zabbix_ServerTools]#yuminstall-yapr*autoconfautomakebisonbzip2bzip2*cloog-pplcompat*cppcurlcurl-develfontconfigfontconfig-develfreetypefreetype*freetype-develgccgcc-c++gtk+-develgdgettextgettext-develglibckernelkernel-headerskeyutilskeyutils-libs-develkrb5-devellibcom_err-devellibpnglibpng*libpng-devellibjpeg*libsepol-devellibselinux-devellibstdc++-devellibtool*libgomplibxml2libxml2-devellibXpm*libX*libtifflibtiff*makempfrncurses*ntpopensslnasmnasm*openssl-develpatchpcre-develperlPHP-commonPHP-gdpolicycoreutilsppltelnett1libt1lib*wgetzlib-devel

安装cmake

[root@Zabbix_ServerTools]#tarzxvfcmake-3.0.2.tar.gz
[root@Zabbix_ServerTools]#cdcmake-3.0.2
[root@Zabbix_Servercmake-3.0.2]#./configure
[root@Zabbix_Servercmake-3.0.2]#make&&makeinstall

安装MysqL

[root@Zabbix_ServerTools]#groupaddMysqL#添加MysqL组
[root@Zabbix_ServerTools]#useradd-gMysqLMysqL-s/bin/false#创建用户MysqL并加入到MysqL组,不允许MysqL用户直接登录系统
[root@Zabbix_ServerTools]#mkdir-p/app/data/MysqL#MysqL数据库存放目录
[root@Zabbix_ServerTools]#chown-RMysqL:MysqL/app/data/MysqL/#设置MysqL数据库存放目录权限
[root@Zabbix_ServerTools]#mkdir/app/MysqL#MysqL安装目录
[root@Zabbix_ServerTools]#tarzxvfMysqL-5.6.21.tar.gz
[root@Zabbix_ServerTools]#cdMysqL-5.6.21
[root@Zabbix_ServerMysqL-5.6.21]#cmake.-DCMAKE_INSTALL_PREFIX=/app/MysqL/-DMysqL_DATADIR=/app/data/MysqL/-DSYSCONFDIR=/etc/#配置
[root@Zabbix_ServerMysqL-5.6.21]#make&&makeinstall
[root@Zabbix_ServerMysqL-5.6.21]#mv/etc/my.cnf{,20160902bak}#删除或者改名系统默认的配置文件(可能有)
[root@Zabbix_ServerMysqL]#./scripts/MysqL_install_db--user=MysqL--basedir=/app/MysqL/--datadir=/app/data/MysqL/#生成MysqL系统数据库
[root@Zabbix_ServerMysqL]#ln-s/app/MysqL/my.cnf/etc/my.cnf#添加到/etc目录的软连接
[root@Zabbix_ServerMysqL]#cp./support-files/MysqL.server/etc/rc.d/init.d/MysqLd#把MysqL加入系统启动
[root@Zabbix_ServerMysqL]#chmod755/etc/rc.d/init.d/MysqLd
[root@Zabbix_ServerMysqL]#chkconfigMysqLdon
[root@Zabbix_ServerMysqL]#vim/etc/rc.d/init.d/MysqLd
basedir=/app/MysqL#MysqL程序安装路径
datadir=/app/data/MysqL#MysqL数据库存放目录
[root@Zabbix_ServerMysqL]#serviceMysqLdstart
[root@Zabbix_ServerMysqL]#vim/etc/profile
exportPATH=$PATH:/app/MysqL/bin/#把MysqL服务加入系统环境变量:在最后添加下面这一行
[root@Zabbix_ServerMysqL]#source/etc/profile
#下面这两行把myslq的库文件链接到系统默认的位置,这样你在编译类似PHP等软件时可以不用指定MysqL的库文件地址。
[root@Zabbix_ServerMysqL]#ln-s/app/MysqL/lib/MysqL/usr/lib/MysqL
[root@Zabbix_ServerMysqL]#ln-s/app/MysqL/include/MysqL/usr/include/MysqL
[root@Zabbix_ServerMysqL]#mkdir/var/lib/MysqL
[root@Zabbix_ServerMysqL]#ln-s/tmp/MysqL.sock/var/lib/MysqL/MysqL.sock
[root@Zabbix_ServerMysqL]#MysqL_secure_installation#设置MysqL密码,根据提示按Y回车输入2次密码,我这里直接把密码设置成Zabbix,方便记忆。

安装pcre

[root@Zabbix_ServerMysqL]#cd/usr/local/Tools/
[root@Zabbix_ServerTools]#mkdir/app/pcre
[root@Zabbix_ServerTools]#tarzxvfpcre-8.36.tar.gz
[root@Zabbix_Serverpcre-8.36]#./configure--prefix=/app/pcre/
[root@Zabbix_Serverpcre-8.36]#make&&makeinstall

安装openssl

[root@Zabbix_Serverpcre-8.36]#cd..
[root@Zabbix_ServerTools]#mkdir/app/openssl
[root@Zabbix_ServerTools]#tarzxvfopenssl-1.0.1j.tar.gz
[root@Zabbix_ServerTools]#cdopenssl-1.0.1j
[root@Zabbix_Serveropenssl-1.0.1j]#./config--prefix=/app/openssl/
[root@Zabbix_Serveropenssl-1.0.1j]#make&&makeinstall
[root@Zabbix_Serveropenssl-1.0.1j]#vim/etc/profile
exportPATH=$PATH:/app/openssl/bin/
[root@Zabbix_Serveropenssl-1.0.1j]#source/etc/profile

安装zlib

[root@Zabbix_Serveropenssl-1.0.1j]#cd/usr/local/Tools/
[root@Zabbix_ServerTools]#mkdir/app/zlib
[root@Zabbix_ServerTools]#tarzxvfzlib-1.2.8.tar.gz
[root@Zabbix_ServerTools]#cdzlib-1.2.8
[root@Zabbix_Serverzlib-1.2.8]#./configure--prefix=/app/zlib/
[root@Zabbix_Serverzlib-1.2.8]#make&&makeinstall

安装Nginx

[root@Zabbix_Serverzlib-1.2.8]#cd/usr/local/Tools/
[root@Zabbix_ServerTools]#groupaddwww
[root@Zabbix_ServerTools]#useradd-gwwwwww-s/bin/false
[root@Zabbix_ServerTools]#tarzxvfNginx-1.6.2.tar.gz
[root@Zabbix_ServerTools]#cdNginx-1.6.2
[root@Zabbix_ServerNginx-1.6.2]#./configure--prefix=/app/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/Tools/openssl-1.0.1j--with-zlib=/usr/local/Tools/zlib-1.2.8--with-pcre=/usr/local/Tools/pcre-8.36
[root@Zabbix_ServerNginx-1.6.2]#make&&makeinstall
[root@Zabbix_ServerNginx-1.6.2]#/app/Nginx/sbin/Nginx#启动Nginx
[root@Zabbix_ServerNginx-1.6.2]#ps-ef|grepNginx
root24771017:10?00:00:00Nginx:masterprocess/app/Nginx/sbin/Nginx
www24782477017:10?00:00:00Nginx:workerprocess
root24806918017:10pts/000:00:00grepNginx
[root@Zabbix_ServerNginx-1.6.2]#

./configure时:--with-openssl=/usr/local/src/openssl-1.0.1j --with-zlib=/usr/local/src/zlib-1.2.8 --with-pcre=/usr/local/src/pcre-8.36指向的是源码包解压的路径,而不是安装的路径,否则会报错

[root@Zabbix_ServerNginx-1.6.2]#vim/etc/rc.d/init.d/Nginx#添加Nginx启动文件
#!/bin/sh

#

#Nginx-thisscriptstartsandstopstheNginxdaemon

#

#chkconfig:-8515

#description:NginxisanHTTP(S)server,HTTP(S)reverse\

#proxyandIMAP/POP3proxyserver

#processname:Nginx

#config:/etc/Nginx/Nginx.conf

#config:/app/Nginx/conf/Nginx.conf

#pidfile:/app/Nginx/logs/Nginx.pid

#Sourcefunctionlibrary.

./etc/rc.d/init.d/functions

#Sourcenetworkingconfiguration.

./etc/sysconfig/network

#Checkthatnetworkingisup.

["$NETWORKING"="no"]&&exit0

Nginx="/app/Nginx/sbin/Nginx"

prog=$(basename$Nginx)

Nginx_CONF_FILE="/app/Nginx/conf/Nginx.conf"

[-f/etc/sysconfig/Nginx]&&./etc/sysconfig/Nginx

lockfile=/var/lock/subsys/Nginx

make_dirs(){

#makerequireddirectories

user=`$Nginx-V2>&1|grep"configurearguments:"|sed's/[^*]*--user=\([^]*\).*/\1/g'-`

if[-z"`grep$user/etc/passwd`"];then

useradd-M-s/bin/nologin$user

fi

options=`$Nginx-V2>&1|grep'configurearguments:'`

foroptin$options;do

if[`echo$opt|grep'.*-temp-path'`];then

value=`echo$opt|cut-d"="-f2`

if[!-d"$value"];then

#echo"creating"$value

mkdir-p$value&&chown-R$user$value

fi

fi

done

}

start(){

[-x$Nginx]||exit5

[-f$Nginx_CONF_FILE]||exit6

make_dirs

echo-n$"Starting$prog:"

daemon$Nginx-c$Nginx_CONF_FILE

retval=$?

echo

[$retval-eq0]&&touch$lockfile

return$retval

}

stop(){

echo-n$"Stopping$prog:"

killproc$prog-QUIT

retval=$?

echo

[$retval-eq0]&&rm-f$lockfile

return$retval

}

restart(){

#configtest||return$?

stop

sleep1

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/null2>&1

}

case"$1"in

start)

rh_status_q&&exit0

$1

;;

stop)

rh_status_q||exit0

$1

;;

restart|configtest)

$1

;;

reload)

rh_status_q||exit7

$1

;;

force-reload)

force_reload

;;

status)

rh_status

;;

condrestart|try-restart)

rh_status_q||exit0

;;

*)

echo$"Usage:$0{start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"

exit2

esac
[root@Zabbix_ServerNginx-1.6.2]#chmod775/etc/rc.d/init.d/Nginx
[root@Zabbix_ServerNginx-1.6.2]#chkconfigNginxon
[root@Zabbix_ServerNginx-1.6.2]#/etc/rc.d/init.d/Nginxrestart
[root@Zabbix_ServerNginx-1.6.2]#cp/etc/sysconfig/iptables{,20160902bak}
[root@Zabbix_ServerNginx-1.6.2]#vim/etc/sysconfig/iptables
-AINPUT-mstate--stateNEW-mtcp-ptcp--dport22-jACCEPT
-AINPUT-mstate--stateNEW-mtcp-ptcp--dport80-jACCEPT
[root@Zabbix_ServerNginx-1.6.2]#/etc/rc.d/init.d/iptablesrestart

在浏览器中打开服务器IP地址,会看到下面的界面,说明Nginx安装成功。

wKioL1fJQ7XiqFE1AAB8s6sGoIE899.png

安装yasm

[root@Zabbix_ServerNginx-1.6.2]#cd/usr/local/Tools/
[root@Zabbix_ServerTools]#tarzxvfyasm-1.3.0.tar.gz
[root@Zabbix_ServerTools]#cdyasm-1.3.0
[root@Zabbix_Serveryasm-1.3.0]#./configure
[root@Zabbix_Serveryasm-1.3.0]#make&&makeinstall

安装libmcrypt

[root@Zabbix_Serveryasm-1.3.0]#cd..
[root@Zabbix_ServerTools]#tarzxvflibmcrypt-2.5.8.tar.gz
[root@Zabbix_ServerTools]#cdlibmcrypt-2.5.8
[root@Zabbix_Serverlibmcrypt-2.5.8]#./configure
[root@Zabbix_ServerTools]#cdlibmcrypt-2.5.8
[root@Zabbix_Serverlibmcrypt-2.5.8]#./configure

安装libvpx

[root@Zabbix_Serverlibmcrypt-2.5.8]#cd../
[root@Zabbix_ServerTools]#tarxvflibvpx-v1.3.0.tar.bz2
[root@Zabbix_Serverlibvpx-v1.3.0]#cdlibvpx-v1.3.0
[root@Zabbix_Serverlibvpx-v1.3.0]#./configure--prefix=/app/libvpx--enable-shared--enable-vp9
[root@Zabbix_Serverlibvpx-v1.3.0]#make&&makeinstall

安装tiff

[root@Zabbix_Serverlibvpx-v1.3.0]#cd..
[root@Zabbix_ServerTools]#tarzxvftiff-4.0.3.tar.gz
[root@Zabbix_ServerTools]#cdtiff-4.0.3
[root@Zabbix_Servertiff-4.0.3]#./configure--prefix=/app/tiff--enable-shared
[root@Zabbix_Servertiff-4.0.3]#make&&makeinstall

安装libpng

[root@Zabbix_Servertiff-4.0.3]#cd..
[root@Zabbix_ServerTools]#tarzxvflibpng-1.6.25.tar.gz
[root@Zabbix_ServerTools]#cdlibpng-1.6.25
[root@Zabbix_Serverlibpng-1.6.25]#./configure--prefix=/app/libpng--enable-shared
[root@Zabbix_Serverlibpng-1.6.25]#make&&makeinstall

安装freetype

[root@Zabbix_Serverlibpng-1.6.25]#cd..
[root@Zabbix_ServerTools]#tarzxvffreetype-2.5.4.tar.gz
[root@Zabbix_ServerTools]#cdfreetype-2.5.4
[root@Zabbix_Serverfreetype-2.5.4]#./configure--prefix=/app/freetype--enable-shared
[root@Zabbix_Serverfreetype-2.5.4]#make&&makeinstall

安装jpeg

[root@Zabbix_Serverfreetype-2.5.4]#cd..
[root@Zabbix_ServerTools]#tarzxvfjpegsrc.v9a.tar.gz
[root@Zabbix_ServerTools]#cdjpeg-9a/
[root@Zabbix_Serverjpeg-9a]#./configure--prefix=/app/jpeg--enable-shared
[root@Zabbix_Serverjpeg-9a]#make&&makeinstall

安装libgd

[root@Zabbix_Serverjpeg-9a]#cd..
[root@Zabbix_ServerTools]#tarzxvflibgd-2.1.0.tar.gz
[root@Zabbix_ServerTools]#cdlibgd-2.1.0
[root@Zabbix_Serverlibgd-2.1.0]#./configure--prefix=/app/libgd--enable-shared--with-jpeg=/app/jpeg/--with-png=/app/libpng/--with-freetype=/app/freetype/--with-fontconfig=/app/freetype/--with-xpm=/usr/--with-tiff=/app/tiff/--with-vpx=/app/libvpx/
[root@Zabbix_Serverlibgd-2.1.0]#make&&makeinstall

安装t1lib

[root@Zabbix_Serverlibgd-2.1.0]#cd..
[root@Zabbix_ServerTools]#tarzxvft1lib-5.1.2.tar.gz
[root@Zabbix_ServerTools]#cdt1lib-5.1.2
[root@Zabbix_Servert1lib-5.1.2]#./configure--prefix=/app/t1lib--enable-shared
[root@Zabbix_Servert1lib-5.1.2]#makewithout_doc
[root@Zabbix_Servert1lib-5.1.2]#makeinstall

安装PHP

[root@Zabbix_Servert1lib-5.1.2]#cd..
[root@Zabbix_ServerTools]#cp-frp/usr/lib64/libltdl.so*/usr/lib/
[root@Zabbix_ServerTools]#cp-frp/usr/lib64/libXpm.so*/usr/lib/

如果系统是64位,请执行以上两条命令,否则安装PHP会出错(32位系统不需要执行)

[root@Zabbix_ServerTools]#tarzxvfPHP-5.6.3.tar.gz
[root@Zabbix_ServerTools]#cdPHP-5.6.3
[root@Zabbix_ServerPHP-5.6.3]#exportLD_LIBRARY_PATH=/app/libgd/lib/
[root@Zabbix_ServerPHP-5.6.3]#./configure--prefix=/app/PHP--with-config-file-path=/app/PHP/etc--with-MysqL=/app/MysqL--with-MysqLi=/app/MysqL/bin/MysqL_config--with-MysqL-sock=/tmp/MysqL.sock--with-pdo-MysqL=/app/MysqL--with-gd--with-png-dir=/app/libpng--with-jpeg-dir=/app/jpeg--with-freetype-dir=/app/freetype--with-xpm-dir=/usr/--with-vpx-dir=/app/libvpx/--with-zlib-dir=/app/zlib--with-t1lib=/app/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@Zabbix_ServerPHP-5.6.3]#make&&makeinstall
[root@Zabbix_ServerPHP-5.6.3]#cpPHP.ini-production/app/PHP/etc/PHP.ini#复制PHP配置文件到安装目录
[root@Zabbix_ServerPHP-5.6.3]#rm-rf/etc/PHP.ini
[root@Zabbix_ServerPHP-5.6.3]#ln-s/app/PHP/etc/PHP.ini/etc/PHP.ini
[root@Zabbix_ServerPHP-5.6.3]#cp/app/PHP/etc/PHP-fpm.conf.default/app/PHP/etc/PHP-fpm.conf#拷贝模板文件PHP-fpm配置文件
[root@Zabbix_ServerPHP-5.6.3]#ln-s/app/PHP/etc/PHP-fpm.conf/etc/PHP-fpm.conf
[root@Zabbix_ServerPHP-5.6.3]#vim/app/PHP/etc/PHP-fpm.conf
user=www#设置PHP-fpm运行账号为www
group=www
pid=run/PHP-fpm.pid#取消前面的分号
[root@Zabbix_ServerPHP-5.6.3]#cp/usr/local/Tools/PHP-5.6.3/sapi/fpm/init.d.PHP-fpm/etc/rc.d/init.d/PHP-fpm
[root@Zabbix_ServerPHP-5.6.3]#chmod+x/etc/rc.d/init.d/PHP-fpm
[root@Zabbix_ServerPHP-5.6.3]#chkconfigPHP-fpmon
[root@Zabbix_ServerPHP-5.6.3]#vim/app/PHP/etc/PHP.ini
#disable_functions=passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,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#列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。我这里注释了
date.timezone=PRC#设置时区
expose_PHP=Off#禁止显示PHP版本的信息
short_open_tag=ON#支持PHP标签
opcache.enable=1#PHP支持opcode缓存
opcache.enable_cli#PHP支持opcode缓存
zend_extension=opcache.so#文末添加,开启opcode缓存功能
[root@Zabbix_ServerPHP-5.6.3]#vim/app/Nginx/conf/Nginx.conf#配置Nginx支持PHP
userwwwwww;#首行user去掉注释,修改Nginx运行组为wwwwww;必须与/usr/local/PHP/etc/PHP-fpm.conf中的user,group配置相同,否则PHP运行出错
location/{
roothtml;
indexindex.htmlindex.htmindex.PHP;#添加index.PHP
}
#passthePHPscriptstoFastCGIserverlisteningon127.0.0.1:9000
##取消FastCGIserver部分location的注释
location~\.PHP${
roothtml;
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.PHP;
fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;#fastcgi_param行的参数,改为$document_root$fastcgi_script_name,或者使用绝对路径
includefastcgi_params;
}
[root@Zabbix_ServerPHP-5.6.3]#/etc/init.d/Nginxrestart
[root@Zabbix_ServerPHP-5.6.3]#/etc/init.d/PHP-fpmrestart
[root@Zabbix_ServerPHP-5.6.3]#cd/app/Nginx/html/
[root@Zabbix_Serverhtml]#rm-rf*
[root@Zabbix_Serverhtml]#vimindex.PHP
<?PHP
PHPinfo();
?>
[root@Zabbix_Serverhtml]#chownwww:www-R/app/Nginx/html/
[root@Zabbix_Serverhtml]#chmod700/app/Nginx/html/-R

在浏览器中打开服务器IP地址,会看到PHP信息,说明配置正常

wKioL1fMvFKSH2b0AAB1U0m8_Is934.png

原文链接:https://www.f2er.com/centos/380894.html

猜你在找的CentOS相关文章