首页 » 编程开发 » Linux » 正文

Linux下CentOS-7-64bit 安装配置Apache + MySQL + PHP 教程

1、环境准备

一、配置防火墙,开启80端口、3306端口

CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙。

1、关闭firewall并安装iptables防火墙:

#停止firewall服务

systemctl stop firewalld.service

#禁止firewall开机启动

systemctl disable firewalld.service

#安装iptables防火墙

yum install iptables-services

#编辑防火墙配置文件

*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-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
-A INPUT -j REJECT –reject-with icmp-host-prohibited
-A FORWARD -j REJECT –reject-with icmp-host-prohibited
COMMIT

#最后重启防火墙使配置生效

systemctl restart iptables.service

#设置防火墙开机启动

systemctl enable iptables.service

2、安装apache

执行安装命令

yum install httpd

安装完成之后,打开浏览器,直接在浏览器访问服务器IP地址,如果网页能打开,说明已经安装成功了。
下面这些命令是apache服务器管理几个重要命令:

systemctl start httpd.service #启动apache
systemctl stop httpd.service #停止apache
systemctl restart httpd.service #重启apache
systemctl enable httpd.service #设置apache开机启动

3、安装mysql

CentOS 7的yum源中貌似没有正常安装mysql时的mysql-sever文件,需要去官网上下载

输入如下命令开始下载

# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm

输入下面命令开始解压

# rpm -ivh mysql-community-release-el7-5.noarch.rpm

输入下面的命令开始安装

# yum install mysql-community-server

成功安装之后重启mysql服务
# service mysqld restart
初次安装mysql是root账户是没有密码的 设置密码的方法是输入如下命令:
首先登录mysql

# mysql -urootmysql

输入命令设置密码,“mypasswd”请替换成您需要设置的新密码

set password for ‘root’@‘localhost’ = password(‘mypasswd’);

至此,mysql的安装已经完成。

4、安装php

执行以下命令进行php的安装

yum install php

安装完成之后,执行以下命令开始安装php常用的组件如mysql等等

yum install php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash

最后,重新服务器使刚安装的组件生效,下面的命令重启mysql和apache

systemctl restart mysqld.service
systemctl restart httpd.service

发表评论