一步步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 ...
随机推荐
- Hive split 分割函数
hive字符串分割函数 split(str, regex) - Splits str around occurances that match regexTime taken: 0.769 secon ...
- 动态绑定事件-on
动态绑定事件 $(document).on("各种事件(如click.mousemove...)","事件对象(比如我点击class为.close的div,那么这里就是. ...
- 安装 Windows Service
1.打开 VS 命令行窗口 2. installutil /u service文件路径 (卸载原有服务) 3, installutil /i service 文件路径 (安装服务)
- EF中的批量操作
阅读目录 插入 更新 删除 在使用EF的过程中,我们经常会遇到需要批量操作数据的场景,批量操作有的时候不仅能提高性能,比如使用SqlBulkCopy进入批量插入的时候,而且比较方便操作,提高效率.那么 ...
- BOOL运算符号(从C#入门经典第五版中摘录)
只总结自己觉得难的哈: (1) var1=!var2; //(非) (2) var1=var2&var3; //(与) (3)var1=var2|var3; //(或) (4 ...
- Luogu 4844 LJJ爱数数
LOJ 6482 设$d = gcd(a, b)$,$xd = a$,$yd = b$,因为$\frac{1}{a} + \frac{1}{b} = \frac{a + b}{ab} = \frac{ ...
- cakephp中sql查询in
$list = $this->Capital->find('all', array('conditions'=>array('remark in '=>array('银联支付' ...
- 写一段php代码,确保报个进程同时写入同一个文件
- Shiro——认证概述
认证流程 身份认证流程 首先调用 Subject.login(token) 进行登录,其会自动委托给SecurityManager SecurityManager 负责真正的身份验证逻辑:它会委托给A ...
- 转:Linux awk 命令 说明
一. AWK 说明 awk是一种编程语言,用于在linux/unix下对文本和数据进行处理.数据可以来自标准输入.一个或多个文件,或其它命令的输出.它支持用户自定义函数和动态正则表达式等先进功能,是 ...