这里是在Centos7系统里采用纯yum的方式安装,纯手工一步一步的配置。
1、首先关闭防火墙和selinux
分别执行两个命令和修改selinux配置文件
# systemctl stop firewalld.service
# systemctl disable firewalld.service
# vim /etc/selinux/config 修改完后重启生效
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled #把这个变量改成disabled就紧止了selinux了
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
2、yum分布安装nginx、mariadb、mariadb-server、php、php-mysql、php-fpm
# yum install -y nginx
# yum install -y mariadb mariadb-server
# yum install -y php
# yum install -y php-mysql
# yum install -y php-fpm
查看一下nginx的配置文件,修改vim /etc/nginx/conf.d/default.conf
# rpm -qc nginx
/etc/logrotate.d/nginx
/etc/nginx/conf.d/default.conf
/etc/nginx/fastcgi_params
/etc/nginx/koi-utf
/etc/nginx/koi-win
/etc/nginx/mime.types
/etc/nginx/nginx.conf
/etc/nginx/scgi_params
/etc/nginx/uwsgi_params
/etc/nginx/win-utf
/etc/sysconfig/nginx
/etc/sysconfig/nginx-debug
# vim /etc/nginx/conf.d/default.conf
server {
listen 80; #nginx服务所需的端口
server_name localhost; #本机的IP地址
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / { #网站的根
root /usr/share/nginx/html; #存放网站代码目录
index index.html index.htm index.php; #指定首页类型越是靠左越优先 (手工添加一个index.php)
}
#error_page 404 /404.html; #错误页这里默认被注释了
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html; #这个错误页没有被注释是有效的
location = /50x.html {
root /usr/share/nginx/html; #错误页的目录位置
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ { #这个模块默认是注释的要取消注释才能支持php
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; #把/scripts换/usr/share/nginx/html(网站目录)
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
开启数据库并开机自启动
# systemctl start mariadb.service
# systemctl enable mariadb.service
配置php关联上nginx:开启工具php-fpm
# systemctl start php-fpm
# systemctl enable php-fpm
完毕!
测试下php有没有关联上nginx写一个index.php代码放到网站根目录后访问试试
# systemctl restart nginx #必须重启ngixn否则效果出不来