CentOS   发布时间:2019-10-31  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了在阿里云Centos下LNMP环境搭建大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

 首先,需要安装C语言的编译环境,因为Nginx是C语言编写的。通常大多数Linux都会默认安装GCC,如果没有的话,可以如下安装。

安装make:

yum -y install gcc automake autoconf libtool make

查看make是否安装

title="在阿里云Centos下LNMP环境搭建" alt="在阿里云Centos下LNMP环境搭建" src="https://cn.js-code.com/res/2019/02-10/23/5a1b48fe050883a3be806c8fedac0684.png" >

安装g++:

yum install gcc gcc-c++

查看gcc安装情况

title="在阿里云Centos下LNMP环境搭建" alt="在阿里云Centos下LNMP环境搭建" src="https://cn.js-code.com/res/2019/02-10/23/b6a2000b6354fb32a91832adccf9767e.png" >

PCRE库:

Nginx需要PCRE(Perl Compatible Regular Expression),因为Nginx的Rewrite模块和http核心模块都会使用到PCRE正则表达式语法。其下载地址为,我们也可以通过yum来安装。

yum install pcre pcre-devel

查看pcre安装情况

在阿里云Centos下LNMP环境搭建

zlib库:

zlib库提供了压缩算法,Nginx很多地方都会用到gzip算法。其下载地址为,也可以通过yum安装。

yum install zlib zlib-devel

查看zlib安装情况

title="在阿里云Centos下LNMP环境搭建" alt="在阿里云Centos下LNMP环境搭建" src="https://cn.js-code.com/res/2019/02-10/23/947c963759dc3e1afdde5f74f848a4de.png" >

OpenSSL:

Nginx中如果服务器提供安全页面,就需要用到OpenSSL库。其下载地址为,也可以通过yum安装。

在阿里云Centos下LNMP环境搭建

/bin/bash改为/sbin/nologin就不让ssh登录了(vi打开文件后是命令模式状态,要用i或者a命令才可进入可编辑的状态,保存文件要按esc,这样就会退回vi的命令模式。按完esc后输入冒号(英文的),然后就转换到了末行模式了,末行模式决定是否保存文件。末行模式下可以按x来保存,x命令可以保存编辑好的文件。也可以用到wq来保存,如果是q!则不保存,

进入nginx官网,找到最新版本的tar.gz包的链接,执行以下动作。

执行./configure,把软件安装到/usr/local目录,用conf、etc、sbin、run等进行归类管理。


--pid-path=/usr/local/nginx/run/nginx.--with---user=--group=--with---without---without---without-mail_smtp_module

最后三项为禁用nginx作为邮件代理服务器,建议想搭建邮件服务器的同志去阅读nginx搭建邮件服务器的教程。检查./configure结果,看看有没有报错,有没有缺少模块,如果一切OK,那么往下继续,如果感觉不对,可以用./configure –help认真阅读一下。

安装完了,但是nginx还没有运行

运行Nginx:

Nginx会默认安装在/usr/local/nginx目录,我们cd到/usr/local/nginx/sbin/目录,存在一个Nginx二进制可执行文件。直接运行就可以启动Nginx。运行成功后打开浏览器访问此机器的IP,出现如下画面即为成功。

在阿里云Centos下LNMP环境搭建

title="在阿里云Centos下LNMP环境搭建" alt="在阿里云Centos下LNMP环境搭建" src="https://cn.js-code.com/res/2019/02-10/23/de19814a6766686f304bd9479632f65e.png" >

检查mysql源是否安装成功 

l.*-community.*”

title="在阿里云Centos下LNMP环境搭建" alt="在阿里云Centos下LNMP环境搭建" src="https://cn.js-code.com/res/2019/02-10/23/e1bb670b0953e2e47ef6d9168e380277.png" >

出现这个就表示安装成功了

安装mysql

title="在阿里云Centos下LNMP环境搭建" alt="在阿里云Centos下LNMP环境搭建" src="https://cn.js-code.com/res/2019/02-10/23/a88fbc5239bad97d4cd4abb2654c26e0.png" >

title="在阿里云Centos下LNMP环境搭建" alt="在阿里云Centos下LNMP环境搭建" src="https://cn.js-code.com/res/2019/02-10/23/7396baf3b8fe6cd9a4e65c0b4c5a80ba.png" >

这个过程中会提示安装一些相关的软件,点击“y”就可以了。

这样mysql就安装成功了

然后启动mysql

systemctl status mysqld

title="在阿里云Centos下LNMP环境搭建" alt="在阿里云Centos下LNMP环境搭建" src="https://cn.js-code.com/res/2019/02-10/23/84949a36934a196db448437743195b1f.png" >

出现上面的这个,那么恭喜你,你已经成功的安装完毕了mysql。

设置开机启动

<span style="color: #008000">#<span style="color: #008000"> systemctl daemon-reload

将mysql启动之后,开始进行一些基本信息的设置。输入设置命令:

title="在阿里云Centos下LNMP环境搭建" alt="在阿里云Centos下LNMP环境搭建" src="https://cn.js-code.com/res/2019/02-10/23/30f3cd93906bcddf3709f8e6fce280e5.png" >

然后继续回车:

title="在阿里云Centos下LNMP环境搭建" alt="在阿里云Centos下LNMP环境搭建" src="https://cn.js-code.com/res/2019/02-10/23/e3e64d79189df560859567a741142484.png" >

设置之后 确认密码,然后回车:

title="在阿里云Centos下LNMP环境搭建" alt="在阿里云Centos下LNMP环境搭建" src="https://cn.js-code.com/res/2019/02-10/23/b5fc1194f636b4faae6fa05dd840d316.png" >

选择否后 回车,继续下一步:

title="在阿里云Centos下LNMP环境搭建" alt="在阿里云Centos下LNMP环境搭建" src="https://cn.js-code.com/res/2019/02-10/23/7e470ec9177c5622d694e0d9ee951adc.png" >

选择否之后,继续回车下一步:

title="在阿里云Centos下LNMP环境搭建" alt="在阿里云Centos下LNMP环境搭建" src="https://cn.js-code.com/res/2019/02-10/23/2158f65a78035a1d1cf42e25792fa2e0.png" >

选择否之后继续回车下一步:

title="在阿里云Centos下LNMP环境搭建" alt="在阿里云Centos下LNMP环境搭建" src="https://cn.js-code.com/res/2019/02-10/23/fe3438e1cda518020775bce4f8f2519d.png" >

设置成功后就OK了。

至此mysql就安装成功了。

好麻烦,好累,好坑啊!!!!

 安装php7

下载php7源码包

php7.tar.gz http://cn2.php.net/get/php-7.0.1.tar.gz/from/this/mirror

解压源码包

php7.tar.gz

进入目录

php-7.0.1

安装php 依赖包

接下来要进行编译前的配置,我们需要提供php-fpm相关参数

php --with-config-file-path=/etc --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --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 --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib-dir --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir --with-xsl --enable-zip --enable-mysqlnd-compression-support --with-pear --enable-opcache

配置无误后执行:

title="在阿里云Centos下LNMP环境搭建" alt="在阿里云Centos下LNMP环境搭建" src="https://cn.js-code.com/res/2019/02-10/23/b504de4097a74a2d1997e8d8e9db2b45.png" >

添加 php 命令到环境变量:

# vim /etc/profile

在末尾加入:

PATH=:/usr/local/php/

要使改动立即生效执行:

source /etc/profile

查看环境变量:

title="在阿里云Centos下LNMP环境搭建" alt="在阿里云Centos下LNMP环境搭建" src="https://cn.js-code.com/res/2019/02-10/23/92c2a98f5be890d5e3ef8e6d8f748598.png" >

4191158 locate lineguid-smhbOkfUBGchEbHd" data-author-name="Ordinary-road">4191158 font-size-3">可以看到php的bin目录已经在环境变量里面了
4191158 locate lineguid-B0D1yq1C7wfE31n0" data-author-name="Ordinary-road">4191158 font-size-3">查看php版本:
4191158 locate lineguid-B0D1yq1C7wfE31n0" data-author-name="Ordinary-road">
php -v

title="在阿里云Centos下LNMP环境搭建" alt="在阿里云Centos下LNMP环境搭建" src="https://cn.js-code.com/res/2019/02-10/23/1846b3cb2ce04ba5daeb1ea560BAC897.png" >

配置php-fpm:

php.ini-production /etc/php.iniphp/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.confphp/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.confphp-fpm /etc/init.d/php-fpmphp-fpm
4191158 locate lineguid-gC7hUQfbINcM12Co" data-author-name="Ordinary-road">4191158 font-size-3">由于php-fpm4191158 font-color-27 font-size-3">走的是9000端口,外网是无法访问的,我们需要在Nginx的配置文件中增加代理的规则,即可让用户在访问80端口,请求php的时候,交由后端的fpm去执行。
4191158 locate lineguid-lpe4BFwXVRnmtItV" data-author-name="Ordinary-road">4191158 font-size-3">启动php-fpm:
4191158 locate lineguid-lpe4BFwXVRnmtItV" data-author-name="Ordinary-road">
php-fpm start

title="在阿里云Centos下LNMP环境搭建" alt="在阿里云Centos下LNMP环境搭建" src="https://cn.js-code.com/res/2019/02-10/23/d7064b678372bdc40ea2fa45f8faa205.png" >

配置nginx虚拟机:

LOCATIOn ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000i_index index.php; fastcgi_param SCRIPT_FILename /t_name

将script 改为$document_root即可。

重启nginx:

service nginx reload

然后就OK了。

大佬总结

以上是大佬教程为你收集整理的在阿里云Centos下LNMP环境搭建全部内容,希望文章能够帮你解决在阿里云Centos下LNMP环境搭建所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: