网站首页 > 技术教程 正文
欢迎访问:江城决的小站
一:安装nginx
[root@localhost /]# yum list | grep nginx
[root@localhost /]# yum install nginx.x86_64 -y
查看nginx的配置文件
[root@localhost /]# cat /etc/nginx/nginx.conf 查看nginx的配置文件(具体每项表示可参考nginx安装的文档))
在root对应目录下加入index.php文件:
location / {
root /opt/nginx/tg-t2;
index index.php index.htm index.html;
[root@localhost /]# systemctl start nginx
浏览器中输入10.0.0.170或是10.0.0.170/index.html (注意需要关闭防火墙等安全配置)
二:安装mariadb数据库(centos7系统默认由mysql更换为mariadb数据库)
[root@localhost /]# yum list |grep mariadb
[root@localhost /]# yum install mariadb-server.x86_64 mariadb.x86_64 -y
[root@localhost /]# systemctl start mariadb
[root@localhost /]# cp /etc/my.cnf /etc/my.cnf.bkg 备份数据库配置文件
[root@localhost /]# vim /etc/my.cnf 编辑数据库文件增加如下两项配置
skip_name_resolve = ON 禁止主机名解析
innodb_file_per_table = ON 启用innodb存储引擎
[root@localhost /]# systemctl restart mariadb 重启数据库
开机自启动#systemctl enable mariadb.service
安装启动数据库后先初始化数据库#mysql_secure_installation
[root@localhost /]# mysql_secure_installation
[root@localhost /]# mysql -uroot -p123456
MariaDB [(none)]> show databases; 查看数据库
MariaDB [(none)]> CREATE DATABASE nginx_php CHARSET ‘utf8’; 创建一个数据库
MariaDB [(none)]> GRANT ALL ON nginx_php.* TO ‘root’@’localhost’ IDENTIFIED BY ‘123456’; 授权本地用户访问该数据库的权限。
MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO ‘root’@’%’ IDENTIFIED BY ‘123456’;授权能远程连接的用户
flush privileges; 刷新数据库权限
三:安装php以及php连接数据库的驱动等程序
[root@localhost /]# yum install php php-mysql php-fpm -y
[root@localhost /]# vim etc/nginx/nginx.conf 增加如下配置信息
location ~ .php$ {
root /usr/share/nginx/html; #将/usr/share/nginx/html替换为您的网站根目录,本文使用/usr/share/nginx/html作为网站根目录。
fastcgi_pass 127.0.0.1:9000; #Nginx通过本机的9000端口将PHP请求转发给PHP-FPM进行处理。
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params; #Nginx调用fastcgi接口处理PHP请求。
}
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;
}
注:如在实际环境中需要更改存放网站的默认路径,如果更改root参数无法生效,可以加上一项location配置参数,如下:
location / { root /data/www;
index index.html index.php; }
[root@localhost /]# systemctl restart nginx 重启nginx服务
[root@localhost /]# systemctl enable nginx 开机启动nginx服务
[root@localhost /]# systemctl restart php-fpm 重启php-fpm
[root@localhost /]# ss -tnl 查看phpde 9000端口是否处于监听状态
[root@localhost /]# cd /usr/share/nginx/html 进入网站为/usr/share/nginx/html的跟目录
[root@localhost html]# vim phpinfo.php 编辑测试页面内 内如如下
<html>
<title>测试</title>
<?php
phpinfo();
?>
</html>
浏览器输入访问页面 10.0.0.170/phpinfo.php
数据库mariadb(mysql)也已开启
还可以使用编辑脚本再次测试mariadb数据库的连接是否正常
[root@localhost /]# vim /usr/share/nginx/html/php_mariadb.php
<?php
$conn = mysql_connect(‘10.0.0.170′,’root’,’123456′);
if ($conn)
echo “OK”;
else
echo “Failure”;
?>
猜你喜欢
- 2024-10-14 Linux在搭建开发环境时的注意事项
- 2024-10-02 nginx和php-fpm通信,使用unix socket还是TCP
你 发表评论:
欢迎- 最近发表
-
- Linux入门-普通用户赋予sudo权限(linux基础用户及权限管理的思维导图)
- Linux系统更改系统用户与密码,RK3568工控主板演示
- 在Windows服务器上安装Linux系统5种主要方法!
- Linux系统非root用户执行Docker命令
- 2、linux命令-用户管理(linux用户和用户组管理)
- Linux下安装常用软件都有哪些?做了一个汇总列表,你看还缺啥?
- Linux中wheel组的使用(centos wheel组和sudo)
- 信息安全实战案例:Linux系统用户权限管理
- Linux 组的管理:groupmod命令 + 练习 + 思维导图
- Linux中的用户管理(linux用户管理的命令)
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)
本文暂时没有评论,来添加一个吧(●'◡'●)