小言_互联网的博客

LNMP 基础搭建部署

270人阅读  评论(0)

一、yum安装nginx

yum install -y nginx

修改/etc/nginx/conf.d/default.conf配置server{}区域

server_name  oldboy.web.com;

测试配置文件&启动服务

nginx -t
systemctl start nginx
systemctl enable nginx

查看进程&端口是否启动

ps -ef|grep nginx
ss -antl|grep 80

测试浏览器访问oldboy.web.com

二、yum搭建部署mysql server(mariadb)

yum install mariadb-server -y

启动服务

systemctl start mariadb
systemctl enable mariadb

查看进程&端口是否启动

ps -ef|grep php
ss -antl|grep 3306

#设置DB密码

mysqladmin  -u root  password  '123456' 

三、yum搭建部署php

配置php yum源

[root@web01 ~]# cat  /etc/yum.repos.d/php.repo 
[webtatic-php]
name = php Repository
baseurl = http://us-east.repo.webtatic.com/yum/el7/x86_64/
gpgcheck = 0

安装php及模块

yum -y install php71w php71w-cli php71w-common php71w-devel php71w-embedded php71w-gd php71w-mcrypt php71w-mbstring php71w-pdo php71w-xml php71w-fpm php71w-mysqlnd php71w-opcache php71w-pecl-memcached php71w-pecl-redis php71w-pecl-mongodb

修改php进程启动用户为nginx,配置文件/etc/php-fpm.d/www.conf

[root@web01 ~]# sed -i  's/apache/nginx/g' /etc/php-fpm.d/www.conf
[root@web01 ~]# egrep '^user|^group' /etc/php-fpm.d/www.conf 
user = nginx
group = nginx

重启服务

systemctl start php-fpm
systemctl enable php-fpm

查看进程&端口是否启动

ps -ef|grep php
ss -antl|grep 9000

修改nginx配置文件,支持php文件解析

   location ~ \.php$ {
   
        fastcgi_pass    127.0.0.1:9000; #php服务监听端口
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #把用户RUI请求的路径丢给php
        include   fastcgi_params; #引用这个文件,将 Nginx 中的变量翻译成 PHP 中能够理解的变量
   }

重启加载nginx配置

nginx -t
systemctl reload nginx

测试php访问mysql,在网站根目录/usr/share/nginx/html新建a.php

<?php
$link = mysqli_connect('127.0.0.1:3306', 'root', '123456');
if (!$link) {
   
	die('Could not connect: ' . mysqli_error());
}
echo 'Mysql Connected successfully!,Hello PHP';
mysqli_close($link);
?>

测试:浏览器访问a.php

windows配置host文件
10.0.0.8 oldboy.web.com
http://oldboy.web.com/a.php

测试成功:


转载:https://blog.csdn.net/oyangyufu/article/details/116771754
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场