手动折腾LNMP

11 篇文章 0 订阅
5 篇文章 0 订阅

懒人专用: https://lnmp.org

自己手动折腾实现,至于为什么呢?

学习,积累,折腾自己。

本人的电脑是win7系统,

1、安装一个vmware,里面装一个centos 7

2、安装nginx

3、安装PHP

4、安装MySQL

5、结合起来

nginx配置虚拟主机,支持php-fpm, php连接数据库。

mkdir /usr/local/nginx/conf/vhost

vim /usr/local/nginx/conf/nginx.conf

在http配置中加入虚拟主机配置:

http{
 #其他的忽略没写,主要是加入下面这句  
   include vhost/*.conf;
}

vim /usr/local/nginx/conf/vhost/test.com.conf

server{
   listen       80;
   server_name  test.com;
   root         /data/www/test.com;
   index        index.html index.htm index.php;

   location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            include        fastcgi.conf;
    }
}

mkdir -p /data/www/test.com

cd /data/www/test.com

vim index.php

<?php
header('Content-Type:text/html;charset=utf-8');

$db = new PDO('mysql:host=127.0.0.1;dbname=test;charset=utf8','root','123456');

$sql="SELECT * FROM test";
$sth = $db->prepare($sql);
$sth->execute();
$list = $sth->fetchAll();

echo "<pre>";
print_r($list);

连接数据库,创建表和测试数据

CREATE TABLE `test`.`test` (
`id`  int UNSIGNED NOT NULL AUTO_INCREMENT ,
`title`  varchar(255) NOT NULL ,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

INSERT INTO `test`.`test` (`id`, `title`) VALUES ('1', '测试');
INSERT INTO `test`.`test` (`id`, `title`) VALUES ('2', '测试21');

重新加载配置:

nginx -s reload

6、在win7系统上的host上,配置一个域名解析到虚拟机的centos上,

文件路径: C:\Windows\System32\drivers\etc\hosts

192.168.50.21  test.com

7、打开浏览器访问 test.com 


 完毕!


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值