编译安装LNMP准备工作安装gccyum-yinstallgcc-c++1,installnginxinstallpcre-develyum-yinstallpcre-develinstallgzipyum-yinstallzlib-develinstallopensslyum-yinstallopenssl-devel下载nginxnginx官方下载地址http://nginx.org/en/download.html获取最新稳定版wgethttp://nginx.org/download/nginx-1.12.1.tar.gz解压nginx压缩包tarzxvfnginx-1.12.1.tar.gz进入目录cdnginx-1.12.1编译安装./configure然后make&&install会安装到/usr/local/nginx默认nginx相关命令startnginx/usr/local/nginx/sbin/nginx查看nginx是否启动ps-ef|grepnginx2,installmariadbMariadb是MYSQL数据库的一个分支,主要由开源社区维护,使用GPL许可证。开发该分支的原因之一是:Oracle收购MySQL后,存在关闭MySQL的潜在风险。mariaDB完全兼容MySQL,可以替代mysql。installmariaDByum-yinstallmariadb-servermariadb相关操作startservicemariadbstart(systemctlstartmariadb)stopservicemysqldstop(systemctlstopmariadb)restartservicemysqldrestart(systemctlrestartmariadb)setbootstartsystemctlenablemariadbmysql-uroot进入默认没有密码,给root设置一个密码,马上生效setpasswordfor'root'@'localhost'=password('mypassword')3、安装PHP获取PHP,可以自己选择php版本http://php.net/这里使用7.1.9wget-Ophp-7.1.9.tar.gzhttp://am1.php.net/get/php-7.1.9.tar.gz/from/this/mirror解压缩tarzxvfphp-7.1。9.tar.gz进入目录cdphp-7.1.9安装编译需要的依赖包yum-yinstalllibxml2libxml2-developensslopenssl-develcurl-devellibjpeg-devellibpng-develfreetype-devellibmcrypt-devellibxsltlibxslt-devel安装过程中,发现无法安装libmcrypt扩展。可以使用以下方法1、安装第三方yum源wgethttp://www.atomicorp.com/installers/atomicsudosh./atomic2。使用yum命令安装sudoyuminstallphp-mcryptsudoyuminstalllibmcryptsudoyuminstalllibmcrypt-devel开始配置./configure\--prefix=/usr/local/php\--with-config-file-path=/etc\--enable-fpm\--with-fpm-user=www-data\--with-fpm-group=www-data\--enable-inline-optimization\--disable-debug\--disable-rpath\--enable-shared\--enable-soap\--with-libxml-dir\--with-xmlrpc\--with-openssl\--with-mcrypt\--with-mhash\--with-pcre-regex\--with-sqlite3\--with-zlib\--enable-bcmath\--with-iconv\--with-bz2\--enable-calendar\--with-curl\--with-cdb\--enable-dom\--enable-exif\--enable-fileinfo\--enable-filter\--with-pcre-dir\--enable-ftp\--with-gd\--with-openssl-dir\--with-jpeg-dir\--with-png-dir\--with-zlib-dir\--with-freetype-dir\--enable-gd-native-ttf\--enable-gd-jis-conv\--with-gettext\--with-gmp\--with-mhash\--enable-json\--enable-mbstring\--enable-mbregex\--enable-mbregex-backtrack\--with-libmbfl\--with-onig\--启用pdo\--with-mysqli=mysqlnd\--with-pdo-mysql=mysqlnd\--with-zlib-dir\--with-pdo-sqlite\--with-readline\--启用会话\--enable-shmop\--enable-simplexml\--enable-sockets\--enable-sysvmsg\--en能够-sysvsem\--enable-sysvshm\--enable-wddx\--with-libxml-dir\--with-xsl\--enable-zip\--enable-mysqlnd-compression-support\--with-pear\--enable-opcache编译安装php比较耗内存。如果服务器内存较小,可能会编译失败。可以考虑设置swap分区创建swap挂载点mkdir/opt/images/rm-rf/opt/images/swap设置挂载swap的大小,64M*32=2GBddif=/dev/zeroof=/opt/images/swapbs=64Mcount=32mkswap/opt/images/swapenableswapswapon/opt/images/swap继续下一步(php编译安装完成后,可以关闭swap,删除挂载的文件swapoff/opt/images/swaprm-f/opt/images/swap)正式安装,会稍微长一点make&&makeinstall配置php环境变量在PATH=$PATH:/usr/local/php/binexportPATHvim/etc/profile结束并保存,使其立即生效source/etc/profile查看PHP版本php-v配置nginx支持php-fpmphp-fpm相关配置PHP-FPM是一个PHPFastCGI管理器PHP-FPM提供了一个更好的PHP进程管理方式,可以有效的控制内存和进程,可以平滑的重新加载PHP配置。新版PHP集成了PHP-FPM,可以直接使用。php的默认安装位置在/usr/local/php。先设置php-fpm的运行用户。创建一个web用户用户组,设置为www-data,可以自己设置(其实配置的时候已经设置成www-data了)groupaddwww-datauseradd-gwww-datawww-datacopyaphp-fpm配置文件cd/usr/local/php/etccpphp-fpm.conf.defaultphp-fpm.conf打开配置文件vimphp-fpm.conf打开后,移到最后,会发现所有.conf会导入php-fpm.d目录下的配置文件打开php-fpm.d目录,复制默认配置文件打开修改cdphp-fpm.dcpwww.conf.defaultwww.confvimwww.conf的默认用户组为www,修改为我们新添加的www-data用户,保存退出,重启php-fpm服务/usr/local/php/sbin/php-fpmphp-fpm默认使用9000端口,使用如下命令可以用来检查是否有netstat-lnt|grep9000nginx相关配置启动成功打开nginx配置文件vim/usr/local/nginx/conf/nginx.conf修改第一行用户组注释去掉nobody改成www-data添加index.php,这样nginx默认使用index.php配置入口页面的php-fpm模块。主要修改69行的/scripts为$document_root及以上,保存退出查看相关配置是否正确/usr/local/nginx/sbin/nginx-t显示正确,重启nginx/usr/local/nginx/sbin/nginx-sreload切换到nginx下的html目录(默认代码目录)新建index.php然后访问对应地址(你的服务器地址)是否可以run127.0.0.1/index.php可以直接用curl测试。为了方便查看,这里输出了hello。worldcurllocalhost/hello.php的输出没有问题,php运行成功。
