一、配置防火墙,开启80端口、3306端口
CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙。
1、关闭firewall:
#停止firewall服务
1. systemctl stop firewalld.service
#禁止firewall开机启动
1. systemctl disable firewalld.service
2、安装iptables防火墙
#安装
1. yum install iptables-services
#编辑防火墙配置文件
1. vi /etc/sysconfig/iptables
# Firewall configuration written bysystem-config-firewall
# Manual customization of this file is not recommended.
*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 -jACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -jACCEPT
-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
:wq! #保存退出
#最后重启防火墙使配置生效
1. systemctl restart iptables.service
#设置防火墙开机启动
1. systemctl enable iptables.service
二、关闭SELINUX(http://os.51cto.com/art/201105/265956.htm)
#修改配置文件
1. vi /etc/selinux/config
#SELINUX=enforcing #注释掉
#SELINUXTYPE=targeted #注释掉
SELINUX=disabled #增加
:wq! #保存退出
#使配置立即生效
1. setenforce 0
安装apache
三.安装apache
1. yum install httpd
可能会用到的:
systemctl start httpd.service #启动apache
systemctl stop httpd.service #停止apache
systemctl restart httpd.service #重启apache
systemctl enable httpd.service #设置apache开机启动
restart一下
安装nginx
配置第三方yum源(CentOS默认的标准源里没有nginx软件包)
[root@CentOS~]#wgethttp://www.atomicorp.com/installers/atomic
//下载atomicyum源
[root@CentOS~]# sh ./atomic
安装nginx
yum install nginx #安装nginx,根据提示,输入Y安装即可成功安装
service nginx start #启动
chkconfig nginx on #设为开机启动
/etc/init.d/nginx restart #重启
rm -rf /usr/share/nginx/html/* #删除ngin默认测试页
安装mysql
官网下载安装mysql-server
# wgethttp://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
# rpm -ivhmysql-community-release-el7-5.noarch.rpm
# yum installmysql-community-server
安装成功后重启mysql服务。
# service mysqldrestart
初次安装mysql,root账户没有密码。
[root@yl-web yl]# mysql -u root
Welcome to theMySQL monitor. Commands end with ; or \g.
Your MySQLconnection id is 3
Server version:5.6.26 MySQL Community Server (GPL)
Copyright (c) 2000,2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Othernames may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> showdatabases;
+--------------------+
| Database |
+--------------------+
|information_schema |
| mysql |
|performance_schema |
| test |
+--------------------+
4 rows in set (0.01 sec)
mysql>
设置密码
mysql> setpassword for 'root'@'localhost' =password('password');
Query OK, 0 rowsaffected (0.00 sec)
mysql>
.配置mysql
1)编码
mysql配置文件为/etc/my.cnf
最后加上编码配置
[mysql]
default-character-set=utf8
这里的字符编码必须和/usr/share/mysql/charsets/Index.xml中一致。
2)远程连接设置
把在所有数据库的所有表的所有权限赋值给位于所有IP地址的root用户。
mysql> grant all privileges on *.* to root@'%'identified by 'password';
如果是新用户而不是root,则要先新建用户
mysql>create user 'username'@'%' identified by 'password';
此时就可以进行远程连接了。
chkconfig mysqld on #设为开机启动
安装php 5.6
1. 执行下面的命令升级软件仓库
rpm -Uvhhttps://mirror.webtatic.com/yum/el7/epel-release.rpm
rpm -Uvhhttps://mirror.webtatic.com/yum/el7/webtatic-release.rpm
2 安装php5.6
yum install -y php56w php56w-opcache php56w-xml php56w-mcrypt php56w-gd php56w-devel php56w-mysql php56w-intl php56w-mbstring php56w-fpm php56w-cli php56w-process git gcc php56w-pear libevent-devel 这个把workerman所需要的依赖都安装上了
yum install php-cli php-process git gcc php-devel php-pear libevent-devel -y
如果 是安装apache
重启apache
Service httpd restart
-------------------------------------------------------
如果是 nginx
service mysqld restart #重启MySql
service nginx restart #重启nginx
service php-fpm start #启动php-fpm
chkconfig php-fpm on #设置开机启动
vi /etc/php.ini #编辑
date.timezone = PRC #在946行 把前面的分号去掉,改为date.timezone = PRC
vi /etc/nginx/nginx.conf #编辑
user nginx nginx; #修改nginx运行账号为:nginx组的nginx用户
:wq! #保存退出
或者用ftp把文件下载下来修改
vi/etc/nginx/conf.d/default.conf #编辑 有的找不到 可以直接修改nginx.conf
在原先
location / {
}
nginx config
location / {
root /www;
index index.html index.htm index.php;
}
location ~ \.php$ {
root /www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /www$fastcgi_script_name;
include fastcgi_params;
}
修改php fpm
vi /etc/php-fpm.d/www.conf #编辑
user = nginx #修改用户为nginx
group = nginx #修改组为nginx
service mysqld restart #重启MySql
service nginx restart #重启nginx
service php-fpm restart #重启php-fpm
至此大功告成
在根目录 放index.php 里面写上phpinfo()
看看是不是有信息出来
阿里云CentOS7配置PHP环境:Apache+MySQL+PHP
本文介绍了如何在阿里云CentOS7系统中,通过yum命令搭建PHP环境,包括配置iptables防火墙,关闭SELINUX,安装Apache、MySQL和PHP,并进行相关配置,确保PHP环境正常运行。
627

被折叠的 条评论
为什么被折叠?



