一步步yum安装LNMP,脱坑笔记!!!
更改国内yum源:
1.备份yum源文件,位置在/etc/yum.repos.d/CentOS-Base.repo
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo_bak
2.获取阿里的yum源:(centos7为例)
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
3.更新cache
yum makecache
4.更新该yum源下所有资源:
yum -y update
安装Nginx
1.更换nginx源为官网源(这步可省略)
To set up the yum repository for RHEL/CentOS, create the file named /etc/yum.repos.d/nginx.repo with the following contents: [nginx]
name=nginx repo
baseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/
gpgcheck=0
enabled=1
Replace “OS” with “rhel” or “centos”, depending on the distribution used, and “OSRELEASE” with “6” or “7”, for 6.x or 7.x versions, respectively.
2.安装并启动nginx:
查询nginx源、安装nginx、关闭防火墙、启动nginx
yum search nginx
yum -y install nginx
service iptables stop
service nginx start

安装PHP
如果打算安装5.X版本,直接yum install php就可以。
我这里安装PHP7.0,所以如下操作:
更新yum源、安装php7.0及许多依赖
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum install php70w-common php70w-fpm php70w-opcache php70w-gd php70w-mysqlnd php70w-mbstring php70w-pecl-redis php70w-pecl-memcached php70w-devel
安装OK后,php -v即可看到 php7的版本信息
那么问题来了,怎么验证nginx可以解析php呢?
在nginx默认启动位置/usr/share/nginx/html下,新建info.php。里面测试代码如下:
<?php
phpinfo();
?>
浏览器里访问http://服务器IP/info.php,发现浏览器直接下载了,还是打不开。怎么弄呢?继续往下看。
在/etc/nginx/conf.d/default.conf中,找到对应代码修改为如下代码:
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
重新启动nginx、php-fpm。然后重新访问上一步路径,效果如下:

这样子,php就安装完成了。继续安装mysql。
安装MySQL
执行以下命令:
yum -y install mysql mysql-server ,mysql-devel
有时候,会出现mysql-server找不到的错误。那么不急,再执行下面这条命令后即可。
rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
yum intsall mysql-server
安装成功后,启动mysql。并且修改密码为123.
service mysqld start
use mysql;
update user set password=password('123') where user='root' and host='localhost';
flush privileges;
最后测试下,php能否连接上呢?
在/usr/share/nginx/html下新建mysql.php
<?php
$conn=mysql_connect('localhost','root','123') ;
if($conn)
echo "OK";
else
echo "failed";
?>
结果是链接失败了,php-fpm错误日志显示没有mysql_connect()函数。怎么解决呢?
因为缺少php-mysql模块,所以安装命令为:
yum install php-mysql
最后特别需要说明的一点,PHP7以上版本不支持原来的mysql_connect函数。应该使用如下测试代码,我就陷坑好久!
<?php
$mysqli = new mysqli("localhost", "root", "password");
if(!$mysqli) {
echo"database error";
}else{
echo"php env successful";
}
$mysqli->close();
?>
至此,LNMP环境全部配置完成。快去建站吧!
一步步yum安装LNMP,脱坑笔记!!!的更多相关文章
- CentOS7使用yum安装LNMP环境以后无法打开php页面
CentOS7使用yum安装LNMP环境以后无法打开php页面 页面提示为File not found 查看nginx错误日志/var/log/nginx/error.log提示如下 原因分析 ngi ...
- centos7 yum 安装lnmp
centos7 yum 安装lnmp 安装7.2把7.1改成7.2就行 使用第三方扩展epel源安装php7.2 #移除旧版php [root@web02 ~]# yum remove php-m ...
- centos6服务器YUM安装LNMP(LINUX+NGINX+MYSQL+PHP)
之前都用的lamp,这次配置一个lnmp来看看,试试Nginx是不是好用 关闭SELINUXvi /etc/selinux/config#SELINUX=enforcing #注释掉#SELINUXT ...
- centos6.5下yum安装lnmp(适合刚入职的新手的方法)
新入职的员工,开始的时候都是让配环境,本地写代码用的wamp,在lnmp或lamp测试,除非有些土豪公司 用的是(果机). 另外安装时,把整个流程在脑子里先过一篇(记不全也没关系,一回生二回熟),重在 ...
- Centos7下使用yum安装lnmp zabbix3.2
1:配置epel-release mysql zabbix 源 配置epel源 wget http://mirrors.aliyun.com/epel/epel-release-latest-7.no ...
- yum安装lnmp
python其他知识目录 1.安装LNMP之前要安装EPEL,以便安装源以外的软件,如Nginx,phpMyAdmin等. yum install epel-release 提示:EPEL,即Extr ...
- Centos6.8 yum安装LNMP
1.Centos6系统库中默认是没有nginx的rpn包的,所以我们需要先更新下rpm依赖库 (1):使用yum安装nginx,安装nginx库 rpm -Uvh http://nginx.org/p ...
- Centos7 yum安装LNMP
1.Centos7系统库中默认是没有nginx的rpn包的,所以我们需要先更新下rpm依赖库 (1):使用yum安装nginx,安装nginx库 rpm -Uvh http://nginx.org/p ...
- yum安装 lnmp (linux+nginx+php7.1+mysql5.7)
1.第一步先更新yum update 2.yum安装nginx安装nginx最新源:yum localinstall http://nginx.org/packages/centos/7/noarch ...
随机推荐
- PHP 取网页变量
$_POST["test"]; $_GET["test"];isset(); if(isset($_GET["yyuid"]))
- CSS DIV 居中
左右居中 margin-left: auto; margin-right: auto; 上下居中
- vue中使用markdown富文本,并在html页面中展示
想给自己的后台增加一个markdown编辑器,下面记录下引用的步骤 引入组件mavon-editor 官网地址:https://github.com/hinesboy/mavonEditor // 插 ...
- fbx模型
[fbx模型] 1.FBX是Autodesk的一个用于跨平台的免费三维数据交换的格式(最早不是由Autodesk开发,但后来被其收购),目前被 众多的标准建模软件所支持,在游戏开发领域也常用来作为各种 ...
- Android中dp、dpi与px的关系
转自知乎用户的回答: 1. dpi是dot per inch,每英寸多少点,ppi是 Pixel per inch,每英寸像素数,针对显示器的设计时,dpi=ppi.ppi计算方法是长宽各自平方之和开 ...
- Centos里没有lsb_release
查看Centos操作系统版本,输入指令 lsb_release -a 报无此命令 解决办法,安装lsb_release 1.执行指令:yum install -y redhat-lsb 2.安装完毕后 ...
- ubunt 14.04 Could not find CMAKE_ROOT !!! CMake has most likely not been installed correctly. Modul
CMake Error: Could not find CMAKE_ROOT !!! CMake has most likely not been installed correctly. Modul ...
- Apache fcgistarter命令
一.简介 fcgistarter命令用于启动FastCGI程序. 二.语法 fcgistarter -c command -p port [ -i interface ] -N num 参考:http ...
- 一步到位带你入门Selenium
其实,关于这篇文章发布前还是有很多思考的,我是不想发布的,因为关于selenium的文章博客园里面有很多的介绍,写的详细的,也有写的不详细的,那么我的这篇文章的定位是基于selnium从开始到最后的框 ...
- javascript总结3:javaScript的 Math 对象
Math 对象 Math 对象用于执行数学任务. Math 对象并不像 Date 和 String 那样是对象的类,因此没有构造函数 Math(). Math 常用的方法 var n1=1234; v ...