centos7安装nginx+mariadb+php-fpm(yum版)
用CentOS-7-x86_64-Minimal-1611.iso最小化安装一个centos7,安装选项:英文、时区为上海、启用网络(如果不在安装时设置,需要安装完成后修改/etc/sysconfig/network-scripts/ifcfg-enp12s0文件中的ONBOOT选项为yes)。安装完成后,先升级一下整个系统:
yum update
重启:reboot
列出内核,如:
# rpm -qa|grep kernel
kernel-3.10.0-514.10.2.el7.x86_64
kernel-tools-libs-3.10.0-514.16.1.el7.x86_64
kernel-3.10.0-514.16.1.el7.x86_64
kernel-tools-3.10.0-514.16.1.el7.x86_64
kernel-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 mariadb
mysqladmin -u root password "密码"
4、创建php的session目录及设置权限mkdir /var/lib/php/session
chmod 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):
7、启动lnmp环境及设置开机启动firewall-cmd --permanent --zone=public --add-service=http firewall-cmd --reload
systemctl start nginx
systemctl start php-fpm
systemctl enable nginx
systemctl enable php-fpm
systemctl enable mariadb
完成!写个phpinfo测试一下就可以了。