CentOS 7上源码编译安装和配置LNMP Web+phpMyAdmin服务器环境

前端之家收集整理的这篇文章主要介绍了CentOS 7上源码编译安装和配置LNMP Web+phpMyAdmin服务器环境前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

什么是LNMP

LNMP(别名LEMP)是指由Linux,Nginx,MysqL/MariaDB,PHP/Perl/Python组合成的动态Web应用程序和服务器,它是一组Web应用程序的基础软件包,在这个基础环境上我们可以搭建任何使用PHP/Perl/Python等语言的动态网站,如商务网站、博客、论坛和开源Web应用程序软件等,它是互联网上被广泛使用的Web网站架构之一。

部署方式

从网站规模大小(访问流量、注册用户)角度来看,LNMP架构可以使用单机部署方式和集群部署方式。单机部署方式即所有的软件都部署在一台Linux服务器上;集群部署方式可以将Nginx网络服务器,MysqL/MariaDB数据库PHP软件分开安装到不同的服务器上,它们彼此之间通过TCP网络协议相互通信协助工作,以及对外提供Web应用访问服务。因此,当单台服务器不能满足性能要求时,可以使用集群方式部署。

本教程将指导您如何在RHEL 7/CentOS 7以及Fedora 23/24/25等衍生版本中使用Nginx 1.10,MariaDB 10PHP 6安装LNMP应用服务器环境。(在其他系统如SUSEUbuntu中源码编译安装LNMP同样可以参考本教程。)


前提要求

准备2RHEL 7CentOS 7服务器,一台用于安装MariaDB,另一台用于安装NginxPHP。当然你也可以仅仅使用1台服务器部署LNMP以通过实验来验证LNMP

HOSTNAME IP OS NODE

hming-server217-mdb

10.0.6.217 CentOS 7.2 x86_64 MariaDB
hming-server218-web 10.0.6.218 CentOS 7.2 x86_64 MariaDB,PHP


主软件包(源码包)

DB mariadb-10.1.20.tar.gz

PHP PHP-5.6.30.tar.bz2

Nginx Nginx-1.10.2.tar.gz


注意:主软件包在这之前我已经提前下载好了,可能并不是最新和稳定版,你也可以根据你的需求选择其他版本。


依赖软件


源码编译安装LNMP有许多依赖软件(如gccmake)是必要的,一般可以通过YUM软件管理程序来安装,另外小部分需要源码编译安装。


通过yum安装gccgcc-c++make等必需软件包

  1. #yuminstall-ygccgcc-c++makeautomake


安装MariaDB


1. 使用yum安装gccmakebisonncurses-devel等依赖软件包

  1. #yuminstallzlib-develncursesncurses-develbison


2.安装cmakecmake是编译MysqL/MariaDB的必要工具(MysqL5.6/MariaDB 10及以后的版本) 你可以在网站https://cmake.org/中下载cmake软件包

将软件包上传/usr/local/src目录下,然后解压cmake包,cdcmake目录执行./bootstrap脚本进行安装,同时可以使用--prefix=<install dir>选项指定安装的目录。

  1. #tar-zxfcmake-3.7.2.tar.gz
  2. #cdcmake-3.7.2/
  3. #./bootstrap--prefix=/usr/local/cmake
  4. #make&&makeinstall


当安装完之后,你可以使用执行/usr/local/cmake/bin/cmake --version查看安装的cmake版本

  1. [root@hming-server217-mdb~]#/usr/local/cmake/bin/cmake--version
  2. cmakeversion3.7.2
  3.  
  4. CMakesuitemaintainedandsupportedbyKitware(kitware.com/cmake).


3.安装完cmake编译工具之后,接下来我们安装MariaDB(你可以访问https://mariadb.org/下载MariaDB),首先创建MariaDB安装目录/usr/local/MysqL数据库服务器的数据目录/data/MysqL/webdata,并创建MysqL用户,并将/data/MysqL/webdata目录的所属主权限修改MysqL用户


创建安装目录和数据目录

  1. #mkdir/usr/local/MysqL
  2. #mkdir/data/MysqL/webdata-p


创建MysqL用户,并修改数据目录的权限

  1. #groupaddMysqL
  2. #useradd-r-gMysqL-s/sbin/nologinMysqL-M
  3. #chown-RMysqL:MysqL/data/MysqL/


4. 编译安装MariaDB,将MariaDB软件包解压后使用cmake进行编译,根据需求选择相应的编译参数进行编译(查看编译选项/usr/local/cmake/bin/cmake . -LH). (或者访问MariaDB编译安装帮助文档https://mariadb.com/kb/en/mariadb/compiling-mariadb-from-source/)

  1. [root@hming-server217-mdb/usr/local/src]#tar-zxfmariadb-10.1.20.tar.gz
  2. [root@hming-server217-mdb/usr/local/src]#cdmariadb-10.1.20/
  3.  
  4. [root@hming-server217-mdb/usr/local/src/mariadb-10.1.20]#/usr/local/cmake/bin/cmake.-DCMAKE_INSTALL_PREFIX=/usr/local/MysqL-DMysqL_DATADIR=/data/MysqL/webdata-DSYSCONFDIR=/etc-DMysqL_TCP_PORT=3306-DMysqL_USER=MysqL-DDEFAULT_CHARSET=utf8-DEXTRA_CHARSETS=all-DDEFAULT_COLLATION=utf8_general_ci-DMysqL_UNIX_ADDR=/data/MysqL/webdata/MysqL.sock-DWITH_INNOBASE_STORAGE_ENGINE=1-DWITH_MYISAM_STORAGE_ENGINE=1-DWITH_MEMORY_STORAGE_ENGINE=1-DWITH_PARTITION_STORAGE_ENGINE=1-DWITH_ARCHIVE_STORAGE_ENGINE=1-DENABLED_LOCAL_INFILE=1-DWITH_EMBEDDED_SERVER=1-DWITH_READLINE=1-DWITH_DEBUG=0


执行gmake gmake install进行最后的安装

  1. [root@hming-server217-mdb/usr/local/src/mariadb-10.1.20]#gmake
  2. [root@hming-server217-mdb/usr/local/src/mariadb-10.1.20]#gmakeinstall


5.配置MysqL环境变量,如果不配置默认系统找不到MysqL的可执行程序和命令,否则你必须使用全路径执行与MysqL相关的任何命令,查看系统默认的环境变量


使用export命令添加MysqL环境变量

  1. [root@hming-server217-mdb~]#exportPATH=$PATH:/usr/local/MysqL/bin
  2. [root@hming-server217-mdb~]#echo$PATH
  3. /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/MysqL/bin


最后将MysqL环境配置添加/etc/profile或者/etc/profile.d/自定义文件

  1. [root@hming-server217-mdb~]#echo"exportPATH=$PATH:/usr/local/MysqL/bin">/etc/profile.d/MysqL.sh
  2. [root@hming-server217-mdb~]#source/etc/profile.d/MysqL.sh


配置了环境变量,我们就可以直接在shell终端下执行MysqL命令,使用MysqL -V查看MysqL版本

  1. [root@hming-server217-mdb~]#MysqL-V
  2. MysqLVer15.1Distrib10.1.20-MariaDB,forLinux(x86_64)usingreadline5.1


6.添加MariaDB文件

  1. [root@hming-server217-mdb~]#echo"/usr/local/MysqL/lib">>/etc/ld.so.conf.d/mariadb-x86_64.conf


7.拷贝MariaDB服务启动脚本到/etc/init.d/目录中

  1. [root@hming-server217-mdb~]#cp/usr/local/MysqL/support-files/MysqL.server/etc/init.d/MysqLd
  2. [root@hming-server217-mdb~]#chmod755/etc/init.d/MysqLd
  3. [root@hming-server217-mdb~]#chkconfig--addMysqLd
  4. [root@hming-server217-mdb~]#chkconfigMysqLdon
  5. [root@hming-server217-mdb~]#systemctldaemon-reload


8. 执行初始化数据库脚本,安装MariaDB基础数据库(执行./MysqL_install_db --basedir=/usr/local/MysqL --datadir=/data/MysqL/webdata --user=MysqL --no-defaults)

  1. [root@hming-server217-mdb~]#cd/usr/local/MysqL/scripts/
  2. [root@hming-server217-mdb/usr/local/MysqL/scripts]#./MysqL_install_db--basedir=/usr/local/MysqL--datadir=/data/MysqL/webdata--user=MysqL--no-defaults
  3. [root@hming-server217-mdb/usr/local/MysqL/scripts]#ls/data/MysqL/webdata/
  4. aria_log.00000001ibdata1ib_logfile1performance_schema
  5. aria_log_controlib_logfile0MysqLtest


9.配置/etc/my.cnf,该文件MysqL服务的主要配置文件

  1. [root@hming-server217-mdb~]#cp/etc/my.cnf/etc/my.cnf.save
  2. [root@hming-server217-mdb~]#cat/etc/my.cnf
  3. [client]
  4. port=3306
  5. socket=/data/MysqL/webdata/MysqL.sock
  6. default-character-set=utf8
  7.  
  8. [MysqLd]
  9. port=3306
  10. user=MysqL
  11. basedir=/usr/local/MysqL
  12. datadir=/data/MysqL/webdata
  13. socket=/data/MysqL/webdata/MysqL.sock
  14. character-set-server=utf8
  15. external-locking=FALSE
  16. skip-name-resolv
  17. default-storage-engine=InnoDB
  18. back_log=1024
  19. transaction_isolation=REPEATABLE-READ
  20. max_connections=5000
  21. max_connect_errors=6000
  22. open_files_limit=65535
  23. table_open_cache=512
  24.  
  25. [MysqLdump]
  26. quick
  27. max_allowed_packet=32M
  28.  
  29. [MysqL]
  30. no-auto-rehash
  31. default-character-set=utf8
  32.  
  33. [MysqLd_safe]
  34. open-files-limit=8192
  35. log-error=/var/log/mariadb/mariadb.log
  36. pid-file=/var/run/mariadb/mariadb.pid


创建/var/log/mariadb/var/run/mariadb目录

  1. [root@hming-server217-mdb~]#mkdir/var/log/mariadb
  2. [root@hming-server217-mdb~]#mkdir/var/run/mariadb
  3. [root@hming-server217-mdb~]#chownMysqL:MysqL/var/log/mariadb
  4. [root@hming-server217-mdb~]#chownMysqL:MysqL/var/run/mariadb


10.启动MariaDB服务

  1. [root@hming-server217-mdb~]#systemctlstartMysqLd
  2. [root@hming-server217-mdb~]#systemctlstatusMysqLd
  3.  
  4. [root@hming-server217-mdb~]#systemctlstatusMysqLd
  5. MysqLd.service-LSB:startandstopMysqL
  6. Loaded:loaded(/etc/rc.d/init.d/MysqLd)
  7. Active:active(running)sinceFri2017-06-0223:53:09CST;3daysago
  8. Docs:man:systemd-sysv-generator(8)
  9. Process:27419ExecStop=/etc/rc.d/init.d/MysqLdstop(code=exited,status=0/SUCCESS)
  10. Process:27449ExecStart=/etc/rc.d/init.d/MysqLdstart(code=exited,status=0/SUCCESS)
  11. CGroup:/system.slice/MysqLd.service
  12. ├─27460/bin/sh/usr/local/MysqL/bin/MysqLd_safe--datadir=/data/MysqL/webdata--pid-file=/data/mysq...
  13. └─27595/usr/local/MysqL/bin/MysqLd--basedir=/usr/local/MysqL--datadir=/data/MysqL/webdata--plugi...
  14.  
  15. Jun0223:53:08hming-server217-mdbsystemd[1]:StartingLSB:startandstopMysqL...
  16. Jun0223:53:08hming-server217-mdbMysqLd[27449]:StartingMysqL.17060223:53:08MysqLd_safeLoggingto'/...og'.
  17. Jun0223:53:09hming-server217-mdbMysqLd[27449]:SUCCESS!
  18. Jun0223:53:09hming-server217-mdbsystemd[1]:StartedLSB:startandstopMysqL.
  19. Hint:Somelineswereellipsized,use-ltoshowinfull.


查看MariaDB服务进程

  1. [root@hming-server217-mdb~]#psaux|grepMysqL
  2. root274600.00.01153801744?S23:530:00/bin/sh/usr/local/MysqL/bin/MysqLd_safe--datadir=/data/MysqL/webdata--pid-file=/data/MysqL/webdata/hming-server217-mdb.pid
  3. MysqL275951.05.2120938099428?Sl23:530:00/usr/local/MysqL/bin/MysqLd--basedir=/usr/local/MysqL--datadir=/data/MysqL/webdata--plugin-dir=/usr/local/MysqL/lib/plugin--user=MysqL--log-error=/var/log/mariadb/mariadb.log--open-files-limit=8192--pid-file=/data/MysqL/webdata/hming-server217-mdb.pid--socket=/data/MysqL/webdata/MysqL.sock--port=3306
  4. root276270.00.0112644952pts/2S+23:530:00grep--color=autoMysqL


11.执行MysqL_secure_installation初始化数据库,设MysqL用户root密码

  1. [root@hming-server217-mdb~]#MysqL_secure_installation
  2.  
  3. NOTE:RUNNINGALLPARTSOFTHISSCRIPTISRECOMMENDEDFORALLMariaDB
  4. SERVERSINPRODUCTIONUSE!PLEASEREADEACHSTEPCAREFULLY!
  5.  
  6. InordertologintoMariaDBtosecureit,we'llneedthecurrent
  7. passwordfortherootuser.Ifyou'vejustinstalledMariaDB,and
  8. youhaven'tsettherootpasswordyet,thepasswordwillbeblank,soyoushouldjustpressenterhere.
  9.  
  10. Entercurrentpasswordforroot(enterfornone):
  11. OK,successfullyusedpassword,movingon...
  12.  
  13. SettingtherootpasswordensuresthatnobodycanlogintotheMariaDB
  14. rootuserwithouttheproperauthorisation.
  15.  
  16. Setrootpassword?[Y/n]y
  17. Newpassword:
  18. Re-enternewpassword:
  19. Passwordupdatedsuccessfully!
  20. Reloadingprivilegetables..
  21. ...Success!
  22.  
  23.  
  24. Bydefault,aMariaDBinstallationhasananonymoususer,allowinganyone
  25. tologintoMariaDBwithouthavingtohaveauseraccountcreatedfor
  26. them.Thisisintendedonlyfortesting,andtomaketheinstallation
  27. goabitsmoother.Youshouldremovethembeforemovingintoa
  28. productionenvironment.
  29.  
  30. Removeanonymoususers?[Y/n]y
  31. ...Success!
  32.  
  33. Normally,rootshouldonlybeallowedtoconnectfrom'localhost'.This
  34. ensuresthatsomeonecannotguessattherootpasswordfromthenetwork.
  35.  
  36. Disallowrootloginremotely?[Y/n]y
  37. ...Success!
  38.  
  39. Bydefault,MariaDBcomeswithadatabasenamed'test'thatanyonecan
  40. access.Thisisalsointendedonlyfortesting,andshouldberemoved
  41. beforemovingintoaproductionenvironment.
  42.  
  43. Removetestdatabaseandaccesstoit?[Y/n]y
  44. -Droppingtestdatabase...
  45. ...Success!
  46. -Removingprivilegesontestdatabase...
  47. ...Success!
  48.  
  49. Reloadingtheprivilegetableswillensurethatallchangesmadesofar
  50. willtakeeffectimmediately.
  51.  
  52. Reloadprivilegetablesnow?[Y/n]y
  53. ...Success!
  54.  
  55. Cleaningup...
  56.  
  57. Alldone!Ifyou'vecompletedalloftheabovesteps,yourMariaDB
  58. installationshouldnowbesecure.
  59.  
  60. ThanksforusingMariaDB!


12.登录MariaDB数据库

  1. [root@hming-server217-mdb~]#MysqL-uroot-p
  2. Enterpassword:
  3. WelcometotheMariaDBmonitor.Commandsendwith;or\g.
  4. YourMariaDBconnectionidis353
  5. Serverversion:10.1.20-MariaDBSourcedistribution
  6.  
  7. Copyright(c)2000,2016,Oracle,MariaDBCorporationAbandothers.
  8.  
  9. Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement.
  10.  
  11. MariaDB[(none)]>selectversion();
  12. +-----------------+
  13. |version()|
  14. +-----------------+
  15. |10.1.20-MariaDB|
  16. +-----------------+
  17. 1rowinset(0.00sec)
  18.  
  19. MariaDB[(none)]>


安装Nginx


1.安装依赖软件包

  1. [root@hming-server218-web~]#yuminstallgccgcc-c++zlibzlib-develpcrepcre-developenssl-develgdgd-develperl-develperl-ExtUtils-Embed


2.创建Nginx用户

  1. [root@hming-server218-web~]#groupaddNginx
  2. [root@hming-server218-web~]#useradd-gNginx-s/sbin/nologinNginx-M


3. 编译安装Nginx

  1. [root@hming-server218-web/usr/local/src]#tar-zxfNginx-1.10.2.tar.gz
  2. [root@hming-server218-web/usr/local/src]#cdNginx-1.10.2/
  3. [root@hming-server218-web/usr/local/src/Nginx-1.10.2]#./configure\
  4. --user=Nginx\
  5. --group=Nginx\
  6. --prefix=/usr/local/Nginx\
  7. --pid-path=/var/run/Nginx/Nginx.pid\
  8. --lock-path=/var/lock/subsys/Nginx\
  9. --with-http_stub_status_module\
  10. --with-pcre\
  11. --with-http_ssl_module\
  12. --with-mail_ssl_module\
  13. --with-http_gzip_static_module\
  14. --http-log-path=/var/log/Nginx/access.log\
  15. --error-log-path=/var/log/Nginx/error.log\
  16. --http-client-body-temp-path=/tmp/Nginx/client_body\
  17. --http-proxy-temp-path=/tmp/Nginx/proxy\
  18. --http-fastcgi-temp-path=/tmp/Nginx/fastcgi\
  19. --http-uwsgi-temp-path=/tmp/Nginx/uwsgi\
  20. --with-http_degradation_module\
  21. --with-http_realip_module\
  22. --with-http_addition_module\
  23. --with-http_sub_module\
  24. --with-http_perl_module\
  25. --with-http_image_filter_module=dynamic\
  26. --with-http_flv_module
  27.  
  28. [root@hming-server218-web/usr/local/src/Nginx-1.10.2]#make&&makeinstall


4. 启动Nginx服务

  1. [root@hming-server218-web~]#ln-s/usr/local/Nginx/sbin/Nginx/usr/local/sbin/
  2. [root@hming-server218-web~]#mkdir/tmp/Nginx
  3. [root@hming-server218-web~]#Nginx
  4. [root@hming-server218-web~]#ps-ef|grepNginx
  5. root279131000:49?00:00:00Nginx:masterprocessNginx
  6. Nginx2791427913000:49?00:00:00Nginx:workerprocess
  7. root2792322381000:49pts/100:00:00grep--color=autoNginx

5.添加防火墙

  1. [root@hming-server218-web~]#firewall-cmd--permanent--add-port=80/tcp
  2. success
  3. [root@hming-server218-web~]#firewall-cmd--reload
  4. success


6. 通过客户端访问http://10.0.6.218

wKiom1k1KC6TnB5QAAAswLN_yC0724.png


安装PHP


  1. 安装依赖软件包

  1. [root@hming-server218-web~]#yuminstallgccgcc-c++libtoollibxslt-devellibpnglibpng-develbzip2bzip2-devellibxml2-devellibXpm-devellibcurl-develcurllibmcryptexpatlibxsltfreetypefreetype-devellibmcrypt-develautoconflibpngzlib-develzlibnet-snmpnet-snmp-devel

2.安装libiconv

  1. [root@hming-server218-web~]#tar-zxflibiconv-1.15.tar.gz
  2. [root@hming-server218-web~]#cdlibiconv-1.15/
  3. [root@hming-server218-web~/libiconv-1.15]#./configure--prefix=/usr/local/libiconv
  4. [root@hming-server218-web~/libiconv-1.15]#make&&makeinstall
  5. [root@hming-server218-web~]#echo"/usr/local/libiconv/lib">>/etc/ld.so.conf
  6. [root@hming-server218-web~]#ldconfig


3.安装libmcrypt

  1. [root@hming-server218-web~]#tar-jxflibmcrypt-2.5.8.tar.bz2
  2. [root@hming-server218-web~]#cdlibmcrypt-2.5.8/
  3. [root@hming-server218-web~/libmcrypt-2.5.8]#./configure--prefix=/usr/local/libmcrypt
  4. [root@hming-server218-web~/libmcrypt-2.5.8]#make&&makeinstall

4. 安装 jpeg

  1. #tar-zxfjpegsrc.v9b.tar.gz
  2. #cdjpeg-9b/
  3. #mkdir/usr/local/jpeg9&&mkdir/usr/local/jpeg9/{bin,lib,include}
  4. #mkdir/usr/local/jpeg9/man/man1-p
  5. #cp-rf/usr/share/libtool/config/config.sub.&&cp-rf/usr/share/libtool/config/config.guess.
  6. cp:overwrite\u2018./config.sub\u2019?y
  7. cp:overwrite\u2018./config.guess\u2019?y
  8. #./configure--prefix=/usr/local/jpeg9--enable-shared--enable-static
  9. #make&&makeinstall


5.安装libgd

  1. [root@hming-server218-web~]#tar-zxflibgd-2.2.3.tar.gz
  2. [root@hming-server218-web~]#cdlibgd-2.2.3/
  3. [root@hming-server218-web~/libgd-2.2.3]#./configure--prefix=/usr/local/libgd2--with-zlib--with-jpeg=/usr/local/jpeg9--with-png--with-freetype
  4. [root@hming-server218-web~/libgd-2.2.3]#make&&makeinstall


6. 编译安装PHP

  1. [root@hming-server218-web~]#groupaddPHP-fpm
  2. [root@hming-server218-web~]#useradd-gPHP-fpm-s/sbin/nologinPHP-fpm-M
  3. [root@hming-server218-web~]#tar-jxfPHP-5.6.30.tar.bz2
  4. [root@hming-server218-web~]#cdPHP-5.6.30/
  5. [root@hming-server218-web~]#./configure\
  6. --prefix=/usr/local/PHP\
  7. --with-config-file-path=/usr/local/PHP/etc\
  8. --enable-fpm\
  9. --with-fpm-user=PHP-fpm\
  10. --with-fpm-group=PHP-fpm\
  11. --with-MysqL=/usr/local/MysqL\
  12. --with-MysqLi=/usr/local/MysqL/bin/MysqL_config\
  13. --with-jpeg-dir=/usr/local/jpeg9\
  14. --with-mcrypt=/usr/local/libmcrypt\
  15. --with-gd=/usr/local/libgd2\
  16. --with-iconv-dir=/usr/local/libiconv\
  17. --with-openssl-dir\
  18. --with-freetype-dir\
  19. --with-libxml-dir\
  20. --with-png-dir\
  21. --with-zlib\
  22. --with-curl\
  23. --with-mhash\
  24. --with-pear\
  25. --with-pcre-dir\
  26. --with-gettext\
  27. --enable-soap\
  28. --enable-gd-native-ttf\
  29. --enable-mbstring\
  30. --enable-exif\
  31. --enable-sockets\
  32. --enable-ftp\
  33. --disable-ipv6\
  34. --enable-bcmath\
  35. --enable-shmop\
  36. --with-snmp\
  37. --enable-sysvsem
  38.  
  39. [root@hming-server218-web~/PHP-5.6.30]#make
  40. [root@hming-server218-web~/PHP-5.6.30]#maketest
  41. [root@hming-server218-web~/PHP-5.6.30]#makeinstall


7.拷贝PHP.ini配置文件

  1. [root@hming-server218-web~/PHP-5.6.30]#cpPHP.ini-production/usr/local/PHP/etc/PHP.ini


8.修改PHP-fpm.conf配置文件

  1. [root@hming-server218-web~]#vim/usr/local/PHP/etc/PHP-fpm.conf
  2. [global]
  3. pid=/usr/local/PHP/var/run/PHP-fpm.pid
  4. error_log=/usr/local/PHP/var/log/PHP-fpm.log
  5. [www]
  6. listen=/var/lib/PHP/PHP-fcgi.sock
  7. user=PHP-fpm
  8. group=PHP-fpm
  9. listen.owner=Nginx
  10. listen.group=Nginx
  11. pm=dynamic
  12. pm.max_children=100
  13. pm.start_servers=20
  14. pm.min_spare_servers=5
  15. pm.max_spare_servers=35
  16. pm.max_requests=500
  17. rlimit_files=1024

9. 检查配置

  1. [root@hming-server218-web~]#/usr/local/PHP/sbin/PHP-fpm-t
  2. [05-Jun-201720:23:27]NOTICE:configurationfile/usr/local/PHP/etc/PHP-fpm.conftestissuccessful


10.拷贝启动脚本

  1. [root@hming-server218-web~]#cpPHP-5.6.30/sapi/fpm/init.d.PHP-fpm/etc/init.d/PHP-fpm
  2. [root@hming-server218-web~]#chmod755/etc/init.d/PHP-fpm
  3. [root@hming-server218-web~]#/etc/init.d/PHP-fpmstart
  4. StartingPHP-fpmdone


测试Nginx是否正常解析PHP脚本

1. 修改Nginx.conf配置文件

  1. userNginxNginx;
  2. worker_processes4;
  3. error_log/var/log/Nginx/error.lognotice;
  4. pid/var/run/Nginx/Nginx.pid;
  5. worker_rlimit_nofile65535;
  6.  
  7. events{
  8. useepoll;
  9. worker_connections65535;
  10. }
  11.  
  12. http{
  13. includemime.types;
  14. default_typeapplication/octet-stream;
  15. server_names_hash_bucket_size2048;
  16. server_names_hash_max_size4096;
  17.  
  18. log_formatmain'$remote_addr-$remote_user[$time_local]"$request"'
  19. '$status$body_bytes_sent"$http_referer"'
  20. '"$http_user_agent""$http_x_forwarded_for"';
  21.  
  22. access_log/var/log/Nginx/access.logmain;
  23.  
  24. sendfileon;
  25. tcp_nopushon;
  26. tcp_nodelayon;
  27. keepalive_timeout65;
  28.  
  29. client_header_timeout30;
  30. client_body_timeout3m;
  31. client_max_body_size10m;
  32. client_body_buffer_size256k;
  33.  
  34. send_timeout3m;
  35. connection_pool_size256;
  36. client_header_buffer_size32k;
  37. large_client_header_buffers464k;
  38. request_pool_size4k;
  39. output_buffers432k;
  40. postpone_output1460;
  41.  
  42. client_body_temp_path/tmp/Nginx/client_body;
  43. proxy_temp_path/tmp/Nginx/proxy;
  44. fastcgi_temp_path/tmp/Nginx/fastcgi;
  45.  
  46. gzipon;
  47. gzip_min_length1k;
  48. gzip_buffers416k;
  49. gzip_comp_level3;
  50. gzip_http_version1.1;
  51. gzip_typestext/plainapplication/x-javascripttext/csstext/htmapplication/xml;
  52. gzip_varyon;
  53.  
  54. fastcgi_connect_timeout300;
  55. fastcgi_send_timeout300;
  56. fastcgi_read_timeout300;
  57. fastcgi_buffer_size64k;
  58. fastcgi_buffers464k;
  59. fastcgi_busy_buffers_size128k;
  60. fastcgi_temp_file_write_size128k;
  61. fastcgi_intercept_errorson;
  62.  
  63. server{
  64. listen80;
  65. server_name10.0.6.218;
  66. charsetUTF8;
  67. indexindex.htmlindex.htmindex.PHPindex.jsp;
  68. root/usr/local/Nginx/html;
  69.  
  70. #access_loglogs/host.access.logmain;
  71.  
  72. location/{
  73. roothtml;
  74. indexindex.htmlindex.htm;
  75. }
  76.  
  77. #redirectservererrorpagestothestaticpage/50x.html
  78. error_page500502503504/50x.html;
  79. location=/50x.html{
  80. roothtml;
  81. }
  82.  
  83. #passthePHPscriptstoFastCGIserverlisteningon127.0.0.1:9000
  84. location~\.PHP${
  85. roothtml;
  86. fastcgi_passunix:/var/lib/PHP/PHP-fcgi.sock;
  87. fastcgi_indexindex.PHP;
  88. fastcgi_paramSCRIPT_FILENAME/usr/local/Nginx/html$fastcgi_script_name;
  89. includefastcgi_params;
  90. }
  91.  
  92. }
  93.  
  94. }


2.测试Nginx配置文件语法是否存在错误

  1. [root@hming-server218-web~]#Nginx-t
  2. Nginx:theconfigurationfile/usr/local/Nginx/conf/Nginx.confSyntaxisok
  3. Nginx:configurationfile/usr/local/Nginx/conf/Nginx.conftestissuccessful


3. 创建测试解析PHP脚本

  1. [root@hming-server218-web~]#vim/usr/local/Nginx/html/info.PHP
  2. <?PHP
  3. PHPinfo();
  4. ?>
  5.  
  6. [root@hming-server218-web~]#Nginx-sreload

4. 访问http://10.0.6.218/info.PHP

wKiom1k1LIfS7zXJAABr6LciKjA175.png

注意:该测试脚本仅用于我们查看当前安装的PHP支持的模块信息,在测试之后应当立即删除


安装PHPMyAdmin

PHPMyAdmin是一个使用PHP语言编写的免费软件,旨在通过Web界面管理MysqL数据库PHPMyAdmin支持MysqLMariaDB上的各种操作。用户可以通过Web界面执行数据库的常用操作(数据库管理,,字段,索引,用户,权限,视图,函数),以及直接执行任何sql语句。


1.创建PHPMyAdmin Web目录

  1. [root@hming-server218-web~]#mkdir/app/data/PHPMyAdmin-p

2.PHPMyAdmin软件包解压到/app/data/PHPMyAdmin 目录下

  1. #tar-zxfPHPMyAdmin-4.7.1-all-languages.tar.gz
  2. #cp-arPHPMyAdmin-4.7.1-all-languages/*/app/data/PHPMyAdmin/
  3. #chown-RNginx:Nginx/app/data/PHPMyAdmin
  4. #chown-RPHP-fpm:PHP-fpm/app/data/PHPMyAdmin


3.修改Nginx配置,创建一个server虚拟机配置文件

  1. http{
  2. ......
  3. #PHPMyAdmin
  4. server{
  5. listen8000;
  6. server_name10.0.6.218;
  7. charsetUTF8;
  8. indexindex.htmlindex.htmindex.PHPindex.jsp;
  9. root/app/data;
  10. access_log/var/log/Nginx/PHPMyAdmin.logmain;
  11.  
  12. location/PHPMyAdmin/{
  13. indexindex.htmlindex.htmindex.PHP;
  14. }
  15.  
  16. location~\.PHP${
  17. fastcgi_passunix:/var/lib/PHP/PHP-fcgi.sock;
  18. fastcgi_indexindex.PHP;
  19. fastcgi_paramSCRIPT_FILENAME/app/data$fastcgi_script_name;
  20. includefastcgi_params;
  21. }
  22. }
  23. }


4.创建数据库root用户权限,允许PHP服务器使用root用户管理数据服务器

  1. [root@hming-server217-mdb~]#MysqL-uroot-p
  2. Enterpassword:
  3. WelcometotheMariaDBmonitor.Commandsendwith;or\g.
  4. YourMariaDBconnectionidis13
  5. Serverversion:10.1.20-MariaDBSourcedistribution
  6.  
  7. Copyright(c)2000,MariaDBCorporationAbandothers.
  8.  
  9. Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement.
  10.  
  11. MariaDB[(none)]>selectuser,host,passwordfromMysqL.user;
  12. +------+-----------+-------------------------------------------+
  13. |user|host|password|
  14. +------+-----------+-------------------------------------------+
  15. |root|localhost|*84BB5DF4823DA319BBF86C99624479A198E6EEE9|
  16. |root|127.0.0.1|*84BB5DF4823DA319BBF86C99624479A198E6EEE9|
  17. |root|::1|*84BB5DF4823DA319BBF86C99624479A198E6EEE9|
  18. +------+-----------+-------------------------------------------+
  19. 3rowsinset(0.00sec)
  20.  
  21. MariaDB[(none)]>grantallprivilegeson*.*to'root'@'10.0.6.218'identifiedby'PHPMyAdmin_123';
  22. QueryOK,0rowsaffected(0.00sec)
  23.  
  24. MariaDB[(none)]>flushprivileges;
  25. QueryOK,0rowsaffected(0.00sec)


5. 配置防火墙规则

  1. #iptables-IINPUT-ptcp--dport3306-s10.0.6.0/24-jACCEPT
  2.  
  3. 或者
  4.  
  5. #firewall-cmd--permanent--add-rich-rule'rulefamily=ipv4sourceaddress=10.0.6.0/24portport=3306protocol=tcpaccept'


6.修改PHPMyAdmin配置文件

  1. #cp/app/data/PHPMyAdmin/libraries/config.default.PHP/app/data/PHPMyAdmin/libraries/config.default.PHP.save
  2. #vim/app/data/PHPMyAdmin/libraries/config.default.PHP
  3.  
  4. /**
  5. *The'cookie'auth_typeuseSAESalgorithmtoencryptthepassword.If
  6. *atleastoneserverconfigurationuses'cookie'auth_type,enterherea
  7. *passphrasethatwillbeusedbyAES.Themaximumlengthseemstobe46
  8. *characters.
  9. *
  10. *@globalstring$cfg['blowfish_secret']
  11. */
  12. $cfg['blowfish_secret']='123456';
  13.  
  14.  
  15. /**
  16. *MysqLhostnameorIPaddress
  17. *
  18. *@globalstring$cfg['Servers'][$i]['host']
  19. */
  20. $cfg['Servers'][$i]['host']='10.0.6.217';
  21.  
  22. /**
  23. *MysqLport-leaveblankfordefaultport
  24. *
  25. *@globalstring$cfg['Servers'][$i]['port']
  26. */
  27. $cfg['Servers'][$i]['port']='3306';
  28.  
  29. /**
  30. *Pathtothesocket-leaveblankfordefaultsocket
  31. *
  32. *@globalstring$cfg['Servers'][$i]['socket']
  33. */
  34. $cfg['Servers'][$i]['socket']='';
  35.  
  36.  
  37. /**
  38. *Authenticationmethod(validchoices:config,http,signonorcookie)
  39. *
  40. *@globalstring$cfg['Servers'][$i]['auth_type']
  41. */
  42. $cfg['Servers'][$i]['auth_type']='cookie';
  43.  
  44. /**
  45. *HTTPBasicAuthRealmnametodisplay(onlyusedwith'HTTP'auth_type)
  46. *
  47. *@globalstring$cfg['Servers'][$i]['auth_http_realm']
  48. */
  49. $cfg['Servers'][$i]['auth_http_realm']='';
  50.  
  51. /**
  52. *MysqLuser
  53. *
  54. *@globalstring$cfg['Servers'][$i]['user']
  55. */
  56. $cfg['Servers'][$i]['user']='root';
  57.  
  58. /**
  59. *MysqLpassword(onlyneededwith'config'auth_type)
  60. *
  61. *@globalstring$cfg['Servers'][$i]['password']
  62. */
  63. $cfg['Servers'][$i]['password']='PHPMyAdmin_123';


7. 登录PHPMyAdmin Web管理界面,打开http://10.0.6.218:8000/PHPMyAdmin/

wKioL1k1LtOjYflAAABRSY9XMcY416.png


输入数据库用户和密码

wKiom1k1LvuwWYS4AAC226Qplhw248.png


测试创建数据库

wKioL1k1LyaAiOBjAACQXd-EbIA418.png

wKioL1k1LzbjDUlwAABzorjVTrg315.png

猜你在找的CentOS相关文章