您的位置:首页 > 运维架构 > Nginx

centos7虚拟机中安装nginx+php+mysql

2017-03-12 12:27 459 查看
准备工作一、配置防火墙(iptables安装与配置)  1、禁用/停止自带的firewalld服务
#停止firewalld服务
systemctl stop firewalld
#禁用firewalld服务
systemctl mask firewalld
  2、安装iptable iptable-service  #先检查是否安装了iptablesservice iptables status#安装iptablesyum install -y iptables#升级iptables(安装的最新版本则不需要)yum update iptables #安装iptables-servicesyum install iptables-services
3、设置现有规则
   vim /etc/sysconfig/iptables    开启80端口、3306、22端口
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

:wq保存退出,重新启动防火墙
service iptables restart
二、配置selinux
vi /etc/selinux/config
设置SELINUX = disabled //如没有就添加
#重启系统
shutdown -r now
三、安装第三方yum源
  #安装下载工具yum install wget#下载wget http://www.atomicorp.com/installers/atomic #安装sh ./atomic#更新yum源yum check-update
开始安装

一. 安装nginx

  #删除系统自带的软件包yum remove httpd* php*#安装nginxyum install -y nginx#设置nginx开机启动chkconfig nginx on#启动nginxservice nginx start

二. 安装PHP

检查当前安装的PHP包
yum list installed | grep php
 如果有安装的PHP包,先删除他们, 如:
yum remove php.x86_64 php-cli.x86_64 php-common.x86_64
配置安装包源:
# CentOs 7.Xrpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm[/code]   如果想删除上面安装的包,重新安装
rpm -qa | grep webstaticrpm -e  [上面搜索到的包即可]
执行安装
yum -y install php56w.x86_64yum -y --enablerepo=webtatic install php56w-develyum -y install php56w-gd.x86_64 php56w-ldap.x86_64 php56w-mbstring.x86_64 php56w-mcrypt.x86_64 php56w-mysql.x86_64 php56w-pdo.x86_64 php56w-opcache.x86_64
安装PHP FPM
4000yum -y install php56w-fpm#设置php-fpm开机启动systemctl enable php-fpm#启动php-fpmsystemctl restart php-fpm
注:如果想更换到php5.5或5.4版本, 直接把上面的56w换成55w或者54w就可以了

三. 安装 MySQL

安装yum install mysql mysql-server(如果安装不成功,需要 下载mysql的repo源)    成功安装之后重启mysql服务(centos7以将mysql转为mariadb的安装了)    systemctl restart mariadb.service  2.为root账户设置密码    mysql_secure_installation

四. 配置nginx,php

1.配置nginx vi /etc/nginx/nginx.conf
    server {listen       80;server_name example.com;location / {root   /usr/share/nginx/html/test/;try_files $uri $uri/ /index.php?$query_string;index index.php  index.html index.htm;}error_page  404              /404.html;location = /404.html {root   /usr/share/nginx/html/test/;}error_page   500 502 503 504  /50x.html;location = /50x.html {root   /usr/share/nginx/html/test/;}location ~ \.php$ {root           /usr/share/nginx/html/test/;fastcgi_pass   127.0.0.1:9000;fastcgi_index  index.php;fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;include        fastcgi_params;}}
重启nginx
systemctl restart nginx.service
2.配置php-fpm
vi /etc/php-fpm.d/www.conf
修改user和group[/code]
   user = nginx`group = nginx
重启php-fpm服务
systemctl restart php-fpm.service
测试是否成功
vi /usr/share/nginx/html/test/index.php
<?php
phpinfo();
?>
curl 127.0.0.1  (查看是否配置成功)

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: