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 /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已经存在,可以使用!奥利给!!!!!!!!!!!!!!!!