centOS7下配置lnmp+mongodb

1.安装epel源
yum install epel-release

2.关闭SELinux严格模式
严格模式关闭:/etc/selinux/config
SELINUX=disabled
修改完后重启服务
终端输入:setenforce 0

3.安装nginx、mysql、php、fast-cgi(作用是使nginx可以管理支持php文件)
yum install nginx mariadb-server mariadb php php-fpm php-mysql

4.启动nginx、mysql、php-fpm
[root@localhost /]# systemctl start nginx
[root@localhost /]# systemctl start mariadb
[root@localhost /]# systemctl start php-fpm
设置开机启动
[root@localhost /]# systemctl enable nginx
[root@localhost /]# systemctl enable mariadb
[root@localhost /]# systemctl enable php-fpm
查看当前连接状态
[root@localhost /]# systemctl status nginx
[root@localhost /]# systemctl status mariadb
[root@localhost /]# systemctl status php-fpm
查看启动的端口
netstat -tunlp

5.配置nginx
vim /etc/nginx/conf.d/test.com.conf
粘贴进去
server{
listen 80;
server_name www.test.com;
charset utf-8;
index index.php;
location ~ .php${
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME d o c u m e n t r o o t document_root documentrootfastcgi_script_name;
include fastcgi_params;
}
root /var/www/www.test.com/;
}

6.创建测试文件
mkdir /var/www/www.test.com
touch /var/www/www.test.com/index.php
vim进入这个文件
vim /var/www/www.test.com/index.php
随意输入index.php内容,我这里输入了这些

<?php phpinfo(); ?>

可以直接终端执行,查看打印
php /var/www/www.test.com/index.php
之后修改目录权限,让此目录属主为nginx,终端执行
chown -R nginx:nginx /var/www/www.test.com

8.让nginx重新加载配置
systemctl restart nginx
systemctl reload nginx 用这个如果报错,请运行nginx -t查看,检查无误后
如果服务被关闭请运行systemctl start nginx开启

9.运行ifconfig -a查看虚拟机本机ip

10.修改hosts文件
sudo vim /etc/hosts
在末尾添加(下方192.168.62.158需更换为自己刚刚查询到的ip)
192.168.62.158 www.test.com

11.访问www.test.com查看

12mongodb安装
官网下载centOS7版本的,扔虚拟机里解压安装

13.php访问mongoDB
(1)进入https://pecl.php.net/package/mongo
(2)点击第一个stable版本的。我这里是1.6.16,在后面mongo-1.6.16.tgz位置右键复制链接
(3)回到linux下的文件夹中,我这里是/usr/local/src/
(4)在这里输入wget https://pecl.php.net/get/mongo-1.6.16.tgz
(5)下载完毕后解压tar zxvf mongo-1.6.16.tgz
(6)执行/usr/bin/phpize(如果找不到请打whereis phpize查找然后运行),之后可能会有报错是提示没有php-devel的,
直接运行安装yum install php-devel,之后再次/usr/bin/phpize
(7)如果正确会提示类似如下打印:
Configuring for:
PHP Api Version: 20100412
Zend Module Api No: 20100525
Zend Extension Api No: 220100525
(8)运行(找不到还是运行whereis xxx查看)
./configure --with-php-config=/usr/bin/php-config
(9)如果此处最后一行提示“Cannot find OpenSSL’s <evp.h>”
直接安装sudo yum install openssl openssl-devel之后再次运行./configure --with-php-config=/usr/bin/php-config
最终提示
Build complete.
Don’t forget to run ‘make test’.

Installing shared extensions: /usr/lib64/php/modules/
(10)进入php.ini中添加
extension=/usr/lib64/php/modules/mongo.so
(11)重启php
pkill-9 php
systemctl start php-fpm
运行之前的www.test.com查看
mongo已经存在,可以使用!奥利给!!!!!!!!!!!!!!!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值