centos7利用yum安装lnmp的教程(linux+nginx+php7.1+mysql5.7)
前言
本文主要介绍的是基于centos7进行yum安装lnmp(linux+nginx+php7.1+mysql5.7)的相关教程,文中将一步步介绍的非常详细,下面话不多说了,来一起看看详细的介绍吧。
步骤如下:
yum的安装
yumupdate
yum安装nginx
安装nginx最新源
yumlocalinstallhttp://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm yumrepolistenabled|grep"nginx*"
安装nginx
yum-yinstallnginx
启动nginx
servicenginxstart
设置nginx服务器开机自启动
systemctlenablenginx.service
检查开机自动是否设置成功
systemctllist-dependencies|grepnginx
浏览器中输入公网ip,检测是否安装成功
http://00.00.00.00/
使用yum安装mysql5.7
安装mysql源
yum-ylocalinstallhttp://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm yumrepolistenabled|grep"mysql.*-community.*"
安装mysql
yum-yinstallmysql-community-serverinstallmysql-community-devel
启动mysql
servicemysqldstart
检查mysql启动是否正常
servicemysqldstatus或者ps-ef|grepmysql
设置mysqld服务开机自启动
systemctlenablemysqld.service
检查mysqld开机自启动是否设置成功
systemctllist-dependencies|grepmysqld
mysql5.7以后的争强了安全机制,所以使用yum安装,启动会系统会自动生成一个随机的密码,修改mysql密码
查看mysql的随机密码
grep'temporarypassword'/var/log/mysqld.log
使用查询得到的随机密码在终端登录
mysql-uroot-p更改密码(mysql文档规定,密码必须包括大小写字母数字加特殊符号>8位) ALTERUSER'root'@'localhost'IDENTIFIEDBY'Yourpassword';
退出mysql客户端,用刚才修改的密码登录确保密码修改成功
exit; mysql-uroot-p
安装php7.1
安装php源
rpm-Uvhhttps://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm rpm-Uvhhttps://mirror.webtatic.com/yum/el7/webtatic-release.rpm
检查源是否安装成功
yumrepolistenabled|grep"webtatic*"
安装php扩展源
yum-yinstallphp71wphp71w-fpm yum-yinstallphp71w-mbstringphp71w-commonphp71w-gdphp71w-mcrypt yum-yinstallphp71w-mysqlphp71w-xmlphp71w-cliphp71w-devel yum-yinstallphp71w-pecl-memcachedphp71w-pecl-redisphp71w-opcache
验证php7.1.x和扩展是否安装成功
验证php是否安装成功
php-v
验证对应的扩展是否安装成功
php-m
设置php-fpm并检测php-fpm的运行状态
启动php-fpm
servicephp-fpmstar
检查启动是否成功
servicephp-fpmstatus
设置开机自启动
systemctlenablephp-fpm.service
检查开机自启动是否设置成功
systemctllist-dependencies|grepphp-fpm ps-ef|grepphp-fpm
nginx配置如下:
server{ listen80; server_nameyouserver; indexindex.htmlindex.php; root/home/public; #charsetkoi8-r; #access_loglogs/host.access.logmain; location/{ indexindex.htmlindex.htmindex.php; try_files$uri$uri//index.php?$query_string; } error_page404/404.html; #redirectservererrorpagestothestaticpage/50x.html # error_page500502503504/50x.html; location=/50x.html{ roothtml; } #proxythePHPscriptstoApachelisteningon127.0.0.1:80 # #location~.php${ #proxy_passhttp://127.0.0.1; #} #passthePHPscriptstoFastCGIserverlisteningon127.0.0.1:9000 # location~.php${ root/home/public; fastcgi_pass127.0.0.1:9000; fastcgi_indexindex.php; fastcgi_paramSCRIPT_FILENAME/home/public$fastcgi_script_name; includefastcgi_params; } #denyaccessto.htaccessfiles,ifApache'sdocumentroot #concurswithnginx'sone # location~/.ht{ denyall; } }
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对毛票票的支持。