Apache yum -y install httpd #根据提示,输入Y安装即可成功安装

systemctl start httpd.service #启动

apache systemctl stop httpd.service #停止

apache systemctl restart httpd.service #重启

apache systemctl enable httpd.service #设置apache开机启动

 

三、安装Apache

1.安装 yum -y install httpd

2.开启apache服务 systemctl start httpd.service

3.设置apache服务开机启动 systemctl enable httpd.service

4.验证apache服务是否安装成功 在本机浏览器中输入虚拟机的ip地址,CentOS7查看ip地址的方式为: ip addr (阿里云不需要用这种方式查看,外网ip已经在你主机列表那里给你写出来了的;) 这里是访问不成功的 (阿里云用外网访问,能成功,不需要做以下步骤) 查了资料,说法是,CentOS7用的是Firewall-cmd,CentOS7之前用的是iptables防火墙;要想让外网能访问到apache主目录,就需要做以下的操作:

firewall-cmd --permanent --zone=public --add-service=http firewall-cmd --permanent --zone=public --add-service=https firewall-cmd --reload

然后再访问外网ip,如果看到apache默认的页面--有Testing 123...字样,便是成功安装了apache服务了;

PHP 一、删除旧版本 如果已经安装过php就先删除之前的版本。检查方法如下:

yum list installed | grep php

然后将安装的包进行删除 比如

yum remove php.x86_64 php-cli.x86_64 php-common.x86_64 php-gd.x86_64 php-ldap.x86_64 php-mbstring.x86_64 php-mcrypt.x86_64 php-mysql.x86_64 php-pdo.x86_64 具体根据显示的安装列表的名称进行相应的删除

二、安装新版版

1. 更新yum安装包 CentOS 7.x rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm CentOS 6.x rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm CentOS 5.x rpm -Uvh http://mirror.webtatic.com/yum/el5/latest.rpm

2. 通过云进行php和其他组件的安装 yum install php71w.x86_64 php71w-cli.x86_64 php71w-common.x86_64 php71w-gd.x86_64 php71w-ldap.x86_64 php71w-mbstring.x86_64 php71w-mcrypt.x86_64 php71w-mysql.x86_64 php71w-pdo.x86_64 yum install php71w-fpm 其他需要的组件在自行安装。

 

三、其他版本php安装 如果想安装php5.5或者5.6版本,将上面的php70w替换为php55w或者php56w就可以了。

第一部分:CentOS 7安装MySQL 5.7 http://www.linuxidc.com/Linux/2016-08/134790.htm

1.下载YUM库 shell > wget http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm

2.安装YUM库 shell > yum localinstall -y mysql57-community-release-el7-7.noarch.rpm

3.安装数据库 shell > yum install -y mysql-community-server

4.启动MySQL服务 shell > systemctl start mysqld.service

5.默认空密码 shell > mysql -uroot -p

6.重置root密码后重启mysql服务 shell > update mysql.user set authentication_string=password("yourpassword") where user="root" and Host="localhost"; shell > flush privileges; shell > quit; shell > systemctl restart mysqld; 如果手贱或者不知道啥原因出现如下问题: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) 请修改my.cnf,添加skip-grant-tables和skip-networking: shell > vi /etc/my.cnf [mysqld] skip-grant-tables skip-networking 重启mysql,然后重复以上修改密码步骤即可,记得修改完后,去掉my.cnf添加的两行。

第二部分:

配置

1、添加远程登录用户(登入Mysql) use mysql; GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '你的密码' WITH GRANT OPTION; 注:'%'代表任意地址,也可以指定IP

2、检查用户表,刷新内存权限 select host, user from user; FLUSH PRIVILEGES;

3、设置防火墙(CentOS7 不推荐) vi /etc/sysconfig/iptables 在-A RH-Firewall-1-INPUT -j REJECT –reject-with icmp-host-prohibited之前,添加 -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT 重启防火墙 service iptables restart 注:centos7使用的是firewall防火墙   systemctl stop firewalld.service #停止   systemctl disable firewalld.service #禁用

4、设置字符编码集和区分大小写

4.1修改mysql配置文件(设置字符编码集) 默认位置:/etc/my.cnf 进入etc文件夹>>vim my.cnf [mysqld] character-set-server=utf8 collation-server=utf8_general_ci * systemctl restart mysql.service #重启MySQL * 查看当前mysql运行状态 mysql>status 参数说明: haracter_set_client:客户端请求数据的字符集。 character_set_connection:从客户端接收到数据,然后传输的字符集。 character_set_database:默认数据库的字符集,无论默认数据库如何改变,都是这个字符集;如果没有默认数据库,使character_set_server指定的字符集,此参数无需设置。 character_set_filesystem:把操作系统上文件名转化成此字符集,即把character_set_client转换character_set_filesystem,默认binary即可。 character_set_results:结果集的字符集。 character_set_server:数据库服务器的默认字符集。 character_set_system:这个值总是utf8,不需要设置,存储系统元数据的字符集。

4.2修改mysql配置文件(设置区分大小写) lower_case_table_names 参数详解: 0:区分大小写 1:不区分大小写 下面看下修改后的预览图: 如果想删除上面安装的包,重新安装 rpm -qa | grep webstatic rpm -e 上面搜索到的包即可 =========================================================5.6 安装apache: yum install httpd httpd-devel 启动apache: /etc/init.d/httpd start 此时输入服务器的IP地址,应该看到apache的服务页面,端口不用输,apache默认就是使用80端口 安装php yum install php php-devel 重启apache使php生效 /etc/init.d/httpd restart 此时可以在目录:/var/www/html/下建立一个PHP文件 代码:

然后访问这个文件,就能看到PHP的一些信息,php.ini配置文件的路径可以在这个页面上看到 安装php的扩展 yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc 安装完扩展之后需要再次重启apache /etc/init.d/httpd restart 测试mysql是否链接成功的php代码

"; } mysql_close($con); ?> 可以把上面的代码传入目录/var/www/html/ 就可以看到执行情况 2.安装MySQL yum install mysql-community-server 1 3.启动MySQL systemctl start mysqld ======================================== rpm -qa|grep -i mysql查看mysql是否安装 AddType application/x-httpd-php.htm.html AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps mysql: 、下载mysql的repo源 $ wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm 1 2、安装mysql-community-release-el7-5.noarch.rpm包 $ sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm 1 安装这个包后,会获得两个mysql的yum repo源: /etc/yum.repos.d/mysql-community.repo和 /etc/yum.repos.d/mysql-community-source.repo。 3、安装mysql $ sudo yum install mysql-server 1 这个过程中就会看到有mysql的软件包存在: [root@VM_47_56_centos ~]# sudo yum install mysql-server 已加载插件:fastestmirror, langpacks | 2.5 kB 00:00:00 mysql-tools-community | 2.5 kB 00:00:00 mysql56-community | 2.5 kB 00:00:00 (1/3): mysql-connectors-community/x86_64/primary_db | 8.6 kB 00:00:00 (2/3): mysql-tools-community/x86_64/primary_db | 22 kB 00:00:00 (3/3): mysql56-community/x86_64/primary_db | 109 kB 00:00:01 Loading mirror speeds from cached hostfile * base: mirrors.sina.cn * extras: mirrors.sina.cn * updates: mirrors.sina.cn 正在解决依赖关系 --> 正在检查事务 省略内容。。。 依赖关系解决 ================================================================================================================= Package 架构 版本 源 大小 ================================================================================================================= 正在安装: mysql-community-libs x86_64 5.6.27-2.el7 mysql56-community 2.0 M 替换 mariadb-libs.x86_64 1:5.5.44-1.el7_1 mysql-community-server x86_64 5.6.27-2.el7 mysql56-community 58 M 为依赖而安装: mysql-community-client x86_64 5.6.27-2.el7 mysql56-community 19 M mysql-community-common x86_64 5.6.27-2.el7 mysql56-community 256 k numactl-libs x86_64 2.0.9-5.el7_1 事务概要 ================================================================================================================= 安装 2 软件包 (+9 依赖软件包) 总下载量:80 M Is this ok [y/d/N]: y 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 下边的安装和其他安装一样, 根据步骤安装就可以了,不过安装完成后,没有密码,需要重置密码。 4、重置密码 重置密码前,首先要登录 $ mysql -u root 1 登录时有可能报这样的错:ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2),原因是/var/lib/mysql的访问权限问题。下面的命令把/var/lib/mysql的拥有者改为当前用户: $ sudo chown -R mysql:mysql /var/lib/mysql #这里的mysql是用户名(需要设置用户组合用户) 1 然后,重启服务: $ service mysqld restart 1 接下来登录重置密码: $ mysql -u root mysql > use mysql; mysql > update user set password=password('xu827928') where user='root'; mysql > exit; 1 2 3 4 5、开放3306端口(可以不用设置) $ sudo vim /etc/sysconfig/iptables 1 添加以下内容: -A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT 1 保存后重启防火墙: $ sudo service iptables restart 1 这样从其它客户机也可以连接上mysql服务了。 6、修改权限可以使其他机器登录: ?mysql>mysql -h localhost -u root //这样应该可以进入MySQL服务器 mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION //赋予任何主机访问数据的权限 mysql>FLUSH PRIVILEGES //修改生效 mysql>EXIT //退出MySQL服务器 1 2 3 4 使用时遇到的问题 (1)java.sql.SQLException: Access denied for user ‘root’@’localhost’ (using password:YES) java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:946) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2870) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:812) at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3269) at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1182) 1 2 3 4 5 6 问题的场景是:在命令行模式下用户名和密码都是正确的但是就是出现登陆不了授权失败的问题。 解决方法: 进入MySQL命令台:mysql> select user,password,host from mysql.user; 这里写图片描述 可以看出该表显示的倒数第二行为: +--------+-------------------------------------------+--------------------+ | user | password | host | +--------+-------------------------------------------+--------------------+ | root | | % | 1 2 3 4 可以看出在root用户下的任何主机是没有password的,因此可以采取两种方式,在远端使用的时候没有密码,显然是不安全的,然后就是为其在远端访问的时候设置密码。步骤如下: mysql> grant all privileges on *.* to root@"%" identified by "your password"; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) 1 2 3 4 5 这相当于是给IP-xxx.xxx.xxx.xxx赋予了所有的权限,包括远程访问权限。 这样就可以为其设置密码,然后就可以使用密码进行登录。

posted on 2017-10-27 11:01  不要重复发明轮子  阅读(182)  评论(0编辑  收藏  举报