栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > PHP

centos7安装nginx+mariadb+php-fpm

PHP 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

centos7安装nginx+mariadb+php-fpm

由 dp7f1f9f 创建,最后一次修改 2017-05-22

用CentOS-7-x86_64-Minimal-1611.iso最小化安装一个centos7,安装选项:英文、时区为上海、启用网络(如果不在安装时设置,需要安装完成后修改/etc/sysconfig/network-scripts/ifcfg-enp12s0文件中的ONBOOT选项为yes)。安装完成后,先升级一下整个系统:

yum update

重启:


reboot

列出内核,如:


# rpm -qa|grep kernelkernel-3.10.0-514.10.2.el7.x86_64kernel-tools-libs-3.10.0-514.16.1.el7.x86_64kernel-3.10.0-514.16.1.el7.x86_64kernel-tools-3.10.0-514.16.1.el7.x86_64kernel-headers-3.10.0-514.16.1.el7.x86_64

删除旧内核:



yum remove kernel-3.10.0-514.10.2.el7.x86_64

安装一些基本工具(不建议安装net-tools来使用ifconfig命令,试试ip命令!):


yum install wget unzip unrar -y

做完以上工作后,下面是用yum安装nginx+mariadb+php-fpm的具体过程:


1、添加nginx官方源:

rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

2、安装lnmp基本环境(如需要其他php组件,另行安装):


yum install nginx php-fpm php-gd php-mysql mariadb-server -y

3、设置mariadb的root密码:


systemctl start mariadbmysqladmin -u root password "密码"

4、创建php的session目录及设置权限


mkdir /var/lib/php/sessionchmod 777 /var/lib/php/session -R

5、修改nginx配置添加php默认文件:


vi /etc/nginx/nginx.conf
location / {  root /usr/share/nginx/html;  index index.php index.html index.htm;}

修改以下代码,添加php支持:

# location ~ .php$ {#   root html;#   fastcgi_pass 127.0.0.1:9000;#   fastcgi_index index.php;#   fastcgi_param script_FILENAME /usr/share/nginx/html$fastcgi_script_name;#   include fastcgi_params;# }

删除上面所有的#和蓝色字体部分。

6、防火墙中打开http服务

由于centos7默认使用的是firewalld防火墙,不再是iptables,许多人不习惯,把默认的卸载,重新安装了iptables,不建议这样做,firewalld功能更强大,使用也简单。防火墙中把http服务放行设置如下(配置文件:/etc/firewalld/zones/public.xml):

firewall-cmd --permanent --zone=public --add-service=httpfirewall-cmd --reload

7、启动lnmp环境及设置开机启动

systemctl start nginxsystemctl start php-fpmsystemctl enable nginxsystemctl enable php-fpmsystemctl enable mariadb

完成!写个phpinfo测试一下就可以了。


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/228228.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号