lamp 环境搭建 php 7.0

一、安装Apache
1.安装
yum -y install httpd
2.开启apache服务
systemctl start httpd.service
3.设置apache服务开机启动
systemctl enable httpd.service

二、安装PHP 7.0
在centos7通过yum安装PHP7,首先在终端运行:
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
提示错误:
error: Failed dependencies:
epel-release >= 7 is needed by webtatic-release-7-3.noarch
需要先安装epel-release。

1.安装epel-release
通过命令:
yum -y install epel-release 
成功安装。
2.安装PHP7
执行下面的命令升级软件仓库
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

然后就可以直接yum安装php7.0了,可以安装的拓展如下:

yum install php70w-common php70w-fpmphp70w-opcache php70w-gd php70w-mysqlnd php70w-mbstring php70w-pecl-redisphp70w-pecl-memcached php70w-devel

 

yum -y install php70w php70w-mysqlphp70w-mbstring php70w-mcrypt php70w-gd php70w-imap php70w-ldap php70w-odbcphp70w-pear php70w-xml php70w-xmlrpc php70w-pdo

 

重启httpd

service httpd restart

查看最新的版本

php -v

现在应该是7.0了!

 

更多拓展:

http://blog.csdn.net/zhezhebie/article/details/73325663

三、安装MySQL

 

由于yum源上没有mysql-server。所以必须去官网下载,这里我们用wget命令,直接获取。    

# 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

   初入安装 root用户没有密码:    

[root@linuxidc-web linuxidc]# mysql -u root

 

#设置msyql密码为 123456

 

mysql> set password for'root'@'localhost' =password('123456');

 

#远程连接设置,所有以root账号连接的远程用户,设其密码为 123456

 

mysql> grant all privileges on *.* to root@'%'identified by '123456';

 

#更新权限

 

mysql>flush privileges; 

 

至此 lamp环境已经搭建成功

 

外网连接mysql还需配置防火墙和端口需配置阿里云安全组

 

以下解决办法

 

1、网络检测
   1)ping主机可以;
   2)telnet 主机3306端口不可以;
     telnet 主机22端口可以;
   说明与本机网络没有关系;


2、端口检测
   1)netstat -ntpl |grep 3306
    tcp        0      0 :::3306                    :::*                      LISTEN      - 
   2)netstat -ntpl |grep 22
    tcp        0      0 0.0.0.0:22                 0.0.0.0:*                  LISTEN     -   
   可以看出22端口监听所有地址,而3306只监听本机地址(绑定了到了本地),所以远程无法访问。修改my.cnf 中bind-address=0.0.0.0
   对于端口只允许本机访问,有两个地方启用,一个是防火墙启用3306,一个就是mysql配置绑定本机地址。


3、防火墙检测
   1)iptables --list查看;
   2)开启防火墙3306端口
     vi /etc/sysconfig/iptables
     -A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -jACCEPT(允许3306端口通过防火墙) 
     /etc/init.d/iptables restart(重启防火墙使配置生效)
   3)或者直接关闭防火墙;   参考:http://blog.csdn.net/fjssharpsword/article/details/50973283
   centos 7 以后是修改 firewall
  systemctl start firewalld # 启动,

  systemctl enable firewalld # 开机启动

  systemctl stop firewalld #关闭

  systemctl disable firewalld # 取消开机启动

4、mysql配置文件检查
   检查my.cnf的配置,bind-address=addr可以配置绑定ip地址。
   不配置或者IP配置为0.0.0.0,表示监听所有客户端连接。
   #ps -aux | grep mysql  查看进程ID是3340
   #ll /proc/3340 查看进程程序情况,找配置文件
   或者#which mysql 找程序路径

5、mysql用户访问权限
   进入mysql数据库
   $mysql -u root -p
   >use mysql;
   >select host,user from user;
    MySQL建用户的时候会指定一个host,默认是127.0.0.1/localhost只能本机访问;
    其它机器用这个用户帐号访问会提示没有权限,host改为%,表示允许所有机器访问。

 



猜你喜欢

转载自blog.csdn.net/qq_29099209/article/details/79206170