Centeros 6 安装 php7 apache mysql

不会的跟我一起操作

1.安装 libmcrypt

cd /usr/local/src/
wget http://mirrors.hust.edu.cn/epel//6/x86_64/epel-release-6-8.noarch.rpm
rpm -ivh epel-release-6-8.noarch.rpm
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
yum install libmcrypt-devel

2.安装apache

yum install httpd
service httpd start 
chkconfig --levels 235 httpd on

3.安装php7

rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm  
yum -y install php70w php70w-mysql php70w-mbstring php70w-mcrypt php70w-gd php70w-imap php70w-ldap php70w-odbc php70w-pear php70w-xml php70w-xmlrpc php70w-pdo

4.安装mysql,设置初始密码

yum install mysql mysql-server mysql-devel -y
service mysqld start
mysqladmin -u root password '123456'

设置对外帐号
 mysql -uroot -p
123456

GRANT ALL PRIVILEGES ON *.* TO someone@"%" IDENTIFIED BY "123456" WITH GRANT OPTION;
flush privileges;

默认安装的是mysql5.1,如果要新版本5.7,这样

wget https://dev.mysql.com/get/mysql57-community-release-el6-9.noarch.rpm
rpm -ivh mysql57-community-release-el6-9.noarch.rpm
yum install mysql-community-server
service mysqld start

mysql 5.7修改密码

1.关闭mysqld
service mysqld stop
2.关闭安全
mysqld_safe --skip-grant-tables &
3.连接
mysql -p
4.改密码
update mysql.user set authentication_string=password('123456') where user='root' and Host = 'localhost';
5.刷新
flush privileges;
quit;

如果php的pdo连接mysql5.7报错[Can't initialize character set utf8mb4],试试下面这2句(根据自己php版本修改)

yum erase php70w-mysql
yum install php70w-mysqlnd

5.配置apache

vim /etc/httpd/conf/httpd.conf

6.配置防火墙

iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 8080 -j ACCEPT
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
service iptables save
cat /etc/sysconfig/iptables

修改顺序

[root@localhost ~]# cat /etc/sysconfig/iptables
# Generated by iptables-save v1.4.7 on Sun Jun 11 15:51:06 2017
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [34:5240]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8080 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

改完之后,策略并没有直接生效,需要关闭重开一下

service iptables stop
service iptables start

你可能感兴趣的:(Centeros 6 安装 php7 apache mysql)