300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > CentOS 6.5编译安装Nginx+MySQL+PHP

CentOS 6.5编译安装Nginx+MySQL+PHP

时间:2022-06-13 07:24:04

相关推荐

CentOS 6.5编译安装Nginx+MySQL+PHP

一、配置防火墙,开启80端口、3306端口,关闭SELINUX

[root@Zabbix~]#vim/etc/sysconfig/iptables-AINPUT-ilo-jACCEPT-AINPUT-mstate--stateNEW-mtcp-ptcp--dport22-jACCEPT-AINPUT-mstate--stateNEW-mtcp-ptcp--dport80-jACCEPT-AINPUT-mstate--stateNEW-mtcp-ptcp--dport3306-jACCEPT-AINPUT-jREJECT--reject-withicmp-host-prohibited[root@Zabbix~]#vim/etc/selinux/config#disabled-NoSELinuxpolicyisloaded.SELINUX=disabled#SELINUXTYPE=cantakeoneofthesetwovalues:#targeted-Targetedprocessesareprotected,#mls-MultiLevelSecurityprotection.SELINUXTYPE=targeted[root@Zabbix~]#reboot

二、软件包下载

[root@Zabbix~]#cd/usr/local/src/[root@Zabbixsrc]#lscmake-3.0.2.tar.gzMySQL编译工具libgd-2.1.0.tar.gzgd库安装包libvpx-v1.3.0.tar.bz2gd库需要openssl-1.0.1j.tar.gznginx扩展t1lib-5.1.2.tar.gzphp扩展zlib-1.2.8.tar.gznginx扩展freetype-2.5.4.tar.gzgd库需要libmcrypt-2.5.8.tar.gzphp扩展mysql-5.6.21.tar.gzpcre-8.36.tar.gz支持nginx伪静态tiff-4.0.3.tar.gzgd库需要jpegsrc.v9a.tar.gzgd库需要libpng-1.6.7.tar.gzgd库需要nginx-1.6.2.tar.gzphp-5.6.3.tar.gzyasm-1.3.0.tar.gzphp扩展[root@Zabbixsrc]#

三、安装编译工具及库文件

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

四、安装MySQL

1、安装cmake

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

2、安装MySQL

[root@Zabbixcmake-3.0.2]#groupaddmysql[root@Zabbixcmake-3.0.2]#useradd-gmysqlmysql-s/sbin/nologin[root@Zabbixcmake-3.0.2]#mkdir-p/opt/data/mysql#MySQL数据库存放目录[root@Zabbixcmake-3.0.2]#chown-Rmysql:mysql/opt/data/mysql/[root@Zabbixcmake-3.0.2]#mkdir-p/app/mysql#MySQL安装目录[root@Zabbixcmake-3.0.2]#cd..[root@Zabbixsrc]#tarzxvfmysql-5.6.21.tar.gz[root@Zabbixsrc]#cdmysql-5.6.21[root@Zabbixmysql-5.6.21]#cmake.-DCMAKE_INSTALL_PREFIX=/app/mysql-DMYSQL_DATADIR=/opt/data/mysql-DSYSCONFDIR=/etc[root@Zabbixmysql-5.6.21]#make&&makeinstall[root@Zabbixmysql-5.6.21]#rm-rf/etc/f#删除系统默认的配置文件[root@Zabbixmysql-5.6.21]#cd/app/mysql/#进入MySQL安装目录[root@Zabbixmysql]#./scripts/mysql_install_db--user=mysql--basedir=/app/mysql--datadir=/opt/data/mysql#生成mysql系统数据库[root@Zabbixmysql]#ln-s/app/mysql/f/etc/f#添加到/etc目录的软连接[root@Zabbixmysql]#cp./support-files/mysql.server/etc/rc.d/init.d/mysqld#把Mysql加入系统启动[root@Zabbixmysql]#chmod755/etc/rc.d/init.d/mysqld[root@Zabbixmysql]#chkconfigmysqldon[root@Zabbixmysql]#vim/etc/rc.d/init.d/mysqldbasedir=/app/mysqldatadir=/opt/data/mysql[root@Zabbixmysql]#servicemysqldstartStartingMySQL.[OK][root@Zabbixmysql]#[root@Zabbixmysql]#vim/etc/profileexportPATH=$PATH:/app/mysql/bin#把mysql服务加入系统环境变量:在最后添加下面这一行[root@Zabbixmysql]#source/etc/profile#把myslq的库文件链接到系统默认的位置,这样你在编译类似PHP等软件时可以不用指定mysql的库文件地址。[root@Zabbixmysql]#ln-s/app/mysql/include/mysql/usr/include/mysql[root@Zabbixmysql]#ln-s/app/mysql/lib/mysql/usr/lib/mysql[root@Zabbixmysql]#mkdir/var/lib/mysql[root@Zabbixmysql]#ln-s/tmp/mysql.sock/var/lib/mysql/mysql.sock[root@Zabbixmysql]#mysql_secure_installation#设置Mysql密码,根据提示回车、输入Y回车输入2次密码,一路回车[root@Zabbixmysql]#servicemysqldrestartShuttingdownMySQL.[OK]StartingMySQL.[OK][root@Zabbixmysql]#

五、安装Nginx

1、安装pcre

[root@Zabbixmysql]#cd/usr/local/src/[root@Zabbixsrc]#mkdir/app/pcre[root@Zabbixsrc]#tarzxvfpcre-8.36.tar.gz[root@Zabbixsrc]#cdpcre-8.36[root@Zabbixpcre-8.36]#./configure--prefix=/app/pcre[root@Zabbixpcre-8.36]#make&&makeinstall

2、安装openssl

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

3、安装zlib

[root@Zabbixopenssl-1.0.1j]#cd/usr/local/src/[root@Zabbixsrc]#mkdir/app/zlib[root@Zabbixsrc]#tarzxvfzlib-1.2.8.tar.gz[root@Zabbixsrc]#cdzlib-1.2.8[root@Zabbixzlib-1.2.8]#./configure--prefix=/app/zlib/[root@Zabbixzlib-1.2.8]#make&&makeinstall

4、安装Nginx

[root@Zabbixzlib-1.2.8]#cd/usr/local/src/[root@Zabbixsrc]#groupaddwww[root@Zabbixsrc]#useradd-gwwwwww-s/sbin/nologin[root@Zabbixsrc]#tarzxvfnginx-1.6.2.tar.gz[root@Zabbixsrc]#cdnginx-1.6.2[root@Zabbixnginx-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/src/openssl-1.0.1j--with-zlib=/usr/local/src/zlib-1.2.8--with-pcre=/usr/local/src/pcre-8.36[root@Zabbixnginx-1.6.2]#make&&makeinstall

注意:--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@Zabbixnginx-1.6.2]#cd/app/nginx/sbin/[root@Zabbixsbin]#./nginx#启动[root@Zabbixsbin]#ps-ef|grep-inginxroot234081012:21?00:00:00nginx:masterprocess./nginxwww2340923408012:21?00:00:00nginx:workerprocessroot23411223:22pts/000:00:00grep-inginx[root@Zabbixsbin]#./nginx-sreload#重启[root@Zabbixsbin]#./nginx-t-c/app/nginx/conf/nginx.conf#检查配置文件nginx:theconfigurationfile/app/nginx/conf/nginx.confsyntaxisoknginx:configurationfile/app/nginx/conf/nginx.conftestissuccessful[root@Zabbixsbin]#./nginx-v#查版本号nginxversion:nginx/1.6.2[root@Zabbixsbin]#./nginx-V#查编译配置nginxversion:nginx/1.6.2builtbygcc4.4.70313(RedHat4.4.7-16)(GCC)TLSSNIsupportenabledconfigurearguments:--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/src/openssl-1.0.1j--with-zlib=/usr/local/src/zlib-1.2.8--with-pcre=/usr/local/src/pcre-8.36[root@Zabbixsbin]#

5、设置nginx开机启动

[root@Zabbixsbin]#vim/etc/rc.d/init.d/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"]&&exit0nginx="/app/nginx/sbin/nginx"prog=$(basename$nginx)NGINX_CONF_FILE="/app/nginx/conf/nginx.conf"[-f/etc/sysconfig/nginx]&&./etc/sysconfig/nginxlockfile=/var/lock/subsys/nginxmake_dirs(){#makerequireddirectoriesuser=`$nginx-V2>&1|grep"configurearguments:"|sed's/[^*]*--user=\([^]*\).*/\1/g'-`if[-z"`grep$user/etc/passwd`"];thenuseradd-M-s/bin/nologin$userfioptions=`$nginx-V2>&1|grep'configurearguments:'`foroptin$options;doif[`echo$opt|grep'.*-temp-path'`];thenvalue=`echo$opt|cut-d"="-f2`if[!-d"$value"];then#echo"creating"$valuemkdir-p$value&&chown-R$user$valuefifidone}start(){[-x$nginx]||exit5[-f$NGINX_CONF_FILE]||exit6make_dirsecho-n$"Starting$prog:"daemon$nginx-c$NGINX_CONF_FILEretval=$?echo[$retval-eq0]&&touch$lockfilereturn$retval}stop(){echo-n$"Stopping$prog:"killproc$prog-QUITretval=$?echo[$retval-eq0]&&rm-f$lockfilereturn$retval}restart(){#configtest||return$?stopsleep1start}reload(){#configtest||return$?echo-n$"Reloading$prog:"killproc$nginx-HUPRETVAL=$?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"instart)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}"exit2esac[root@Zabbixsbin]#chmod+x/etc/rc.d/init.d/nginx[root@Zabbixsbin]#chkconfignginxon[root@Zabbixsbin]#servicenginxrestartStoppingnginx:[OK]Startingnginx:[OK][root@Zabbixsbin]#

nginx更多配置见:RHEL6编译安装nginx、开机启动脚本

六、安装php

1、安装yasm

[root@Zabbixsbin]#cd/usr/local/src/[root@Zabbixsrc]#tarzxvfyasm-1.3.0.tar.gz[root@Zabbixsrc]#cdyasm-1.3.0[root@Zabbixyasm-1.3.0]#./configure[root@Zabbixyasm-1.3.0]#make&&makeinstall

2、安装libmcrypt

[root@Zabbixyasm-1.3.0]#cd/usr/local/src/[root@Zabbixsrc]#tarzxvflibmcrypt-2.5.8.tar.gz[root@Zabbixsrc]#cdlibmcrypt-2.5.8[root@Zabbixlibmcrypt-2.5.8]#./configure[root@Zabbixlibmcrypt-2.5.8]#make&&makeinstall

3、安装libvpx

[root@Zabbixlibmcrypt-2.5.8]#cd/usr/local/src/[root@Zabbixsrc]#tarxvflibvpx-v1.3.0.tar.bz2[root@Zabbixsrc]#cdlibvpx-v1.3.0[root@Zabbixlibvpx-v1.3.0]#./configure--prefix=/app/libvpx--enable-shared--enable-vp9[root@Zabbixlibvpx-v1.3.0]#make&&makeinstall

4、安装tiff

[root@Zabbixlibvpx-v1.3.0]#cd/usr/local/src/[root@Zabbixsrc]#tarzxvftiff-4.0.3.tar.gz[root@Zabbixsrc]#cdtiff-4.0.3[root@Zabbixtiff-4.0.3]#./configure--prefix=/app/tiff--enable-shared[root@Zabbixtiff-4.0.3]#make&&makeinstall

5、安装libpng

[root@Zabbixtiff-4.0.3]#cd/usr/local/src/[root@Zabbixsrc]#tarzxvflibpng-1.6.7.tar.gz[root@Zabbixsrc]#cdlibpng-1.6.7[root@Zabbixlibpng-1.6.7]#./configure--prefix=/app/libpng--enable-sharedconfigure:error:zlibnotinstalled[root@Zabbixlibpng-1.6.7]#exportLDFLAGS="-L/app/zlib/lib"[root@Zabbixlibpng-1.6.7]#exportCPPFLAGS="-I/app/zlib/include"[root@Zabbixlibpng-1.6.7]#make&&makeinstall

6、安装freetype

[root@Zabbixlibpng-1.6.7]#cd/usr/local/src/[root@Zabbixsrc]#tarzxvffreetype-2.5.4.tar.gz[root@Zabbixsrc]#cdfreetype-2.5.4[root@Zabbixfreetype-2.5.4]#./configure--prefix=/app/freetype-enable-sharedmake:Nothingtobedonefor`unix'.[root@Zabbixfreetype-2.5.4]#cdbuilds/unix/[root@Zabbixunix]#./configure--prefix=/app/freetype-enable-shared[root@Zabbixbuilds]#cd../..[root@Zabbixfreetype-2.5.4]#make[root@Zabbixfreetype-2.5.4]#makeinstallrmdir:failedtoremove`/app/freetype/include/freetype2/freetype/config':Nosuchfileordirectorymake:[install]Error1(ignored)rm-f/app/freetype/include/freetype2/freetype/*rmdir/app/freetype/include/freetype2/freetypermdir:failedtoremove`/app/freetype/include/freetype2/freetype':Nosuchfileordirectorymake:[install]Error1(ignored)[root@Zabbixfreetype-2.5.4]#

7、安装jpeg

[root@Zabbixfreetype-2.5.4]#cd/usr/local/src/[root@Zabbixsrc]#tarzxvfjpegsrc.v9a.tar.gz[root@Zabbixsrc]#cdjpeg-9a/[root@Zabbixjpeg-9a]#./configure--prefix=/app/jpeg--enable-shared[root@Zabbixjpeg-9a]#make&&makeinstall

8、安装libgd

[root@Zabbixjpeg-9a]#cd/usr/local/src/[root@Zabbixsrc]#tarzxvflibgd-2.1.0.tar.gz[root@Zabbixsrc]#cdlibgd-2.1.0[root@Zabbixlibgd-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@Zabbixlibgd-2.1.0]#make&&makeinstall

9、安装t1lib

[root@Zabbixlibgd-2.1.0]#cd/usr/local/src/[root@Zabbixsrc]#tarzxvft1lib-5.1.2.tar.gz[root@Zabbixsrc]#cdt1lib-5.1.2[root@Zabbixt1lib-5.1.2]#./configure--prefix=/app/t1lib--enable-shared[root@Zabbixt1lib-5.1.2]#makewithout_doc[root@Zabbixt1lib-5.1.2]#makeinstall

10、安装php

[root@Zabbixt1lib-5.1.2]#cd/usr/local/src/[root@Zabbixsrc]#cp-frp/usr/lib64/libltdl.so*/usr/lib/[root@Zabbixsrc]#cp-frp/usr/lib64/libXpm.so*/usr/lib/[root@Zabbixsrc]#tarzxvfphp-5.6.3.tar.gz[root@Zabbixphp-5.6.3]#exportLD_LIBRARY_PATH=/app/libgd/lib/[root@Zabbixphp-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@Zabbixphp-5.6.3]#make&&makeinstall[root@Zabbixphp-5.6.3]#cpphp.ini-production/app/php/etc/php.ini#复制php配置文件到安装目录[root@Zabbixphp-5.6.3]#rm-rf/etc/php.ini#删除系统自带配置文件[root@Zabbixphp-5.6.3]#ln-s/app/php/etc/php.ini/etc/php.ini#添加软链接到/etc目录[root@Zabbixphp-5.6.3]#cp/app/php/etc/php-fpm.conf.default/app/php/etc/php-fpm.conf#拷贝模板文件为php-fpm配置文件[root@Zabbixphp-5.6.3]#ln-s/app/php/etc/php-fpm.conf/etc/php-fpm.conf#添加软连接到/etc目录[root@Zabbixphp-5.6.3]#vim/app/php/etc/php-fpm.confuser=wwwgroup=wwwpid=run/php-fpm.pid[root@Zabbixphp-5.6.3]#cp/usr/local/src/php-5.6.3/sapi/fpm/init.d.php-fpm/etc/rc.d/init.d/php-fpm#拷贝php-fpm到启动目录[root@Zabbixphp-5.6.3]#chmod+x/etc/rc.d/init.d/php-fpm[root@Zabbixphp-5.6.3]#chkconfigphp-fpmon[root@Zabbixphp-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_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#列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。date.timezone=PRC#设置时区expose_php=Off#禁止显示php版本的信息short_open_tag=ON#支持php短标签opcache.enable=1#php支持opcode缓存opcache.enable_cli=1#php支持opcode缓存zend_extension=opcache.so#文末添加此行,开启opcode缓存功能[root@Zabbixphp-5.6.3]#

11、配置Nginx支持PHP

[root@Zabbixphp-5.6.3]#cp/app/nginx/conf/nginx.conf{,bak}[root@Zabbixphp-5.6.3]#vim/app/nginx/conf/nginx.confuserwwwwww;#首行user去掉注释,修改Nginx运行组为wwwwww;必须与/usr/local/php/etc/php-fpm.conf中的user,group配置相同,否则php运行出错location/{roothtml;indexindex.htmlindex.htmindex.php;#添加index.php}63#passthePHPscriptstoFastCGIserverlisteningon127.0.0.1:900064#取消FastCGIserver部分location的注释,65location~\.php${66roothtml;67fastcgi_pass127.0.0.1:9000;68fastcgi_indexindex.php;69fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;#fastcgi_param行的参数,改为$document_root$fastcgi_script_name,或者使用绝对路径70includefastcgi_params;71}[root@Zabbixphp-5.6.3]#/etc/init.d/nginxrestartStoppingnginx:[OK]Startingnginx:[OK][root@Zabbixphp-5.6.3]#/etc/init.d/php-fpmstartStartingphp-fpmdone[root@Zabbixphp-5.6.3]#

七、测试

[root@Zabbixphp-5.6.3]#cd/app/nginx/html/[root@Zabbixhtml]#ls50x.htmlindex.html[root@Zabbixhtml]#rm-rf*[root@Zabbixhtml]#vimindex.php<?phpphpinfo();?>[root@Zabbixhtml]#ll-ddrwxr-xr-x2rootroot4096Mar214:33.[root@Zabbixhtml]#chown-Rwww:www.[root@Zabbixhtml]#chmod-R700.[root@Zabbixhtml]#ll-ddrwx------2wwwwww4096Mar214:33.[root@Zabbixhtml]#

在浏览器中打开服务器IP地址,会看到下面的界面说明安装配置正常

CentOS 6.5编译安装Nginx+MySQL+PHP

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。