1、Apache
apache在linux中的名字是httpd
,检查是否已安装 rpm -qa |grep httpd
,如没有则进行下一步的安装yum install httpd
开启 | 停止 | 重启apache服务:service httpd start | stop | restart
查询服务状态:service httpd status
配置自启动:
chkconfig 命令 chkconfig httpd on
或 systemctl 命令 systemctl enable httpd.service
systemctl
新命令是系统服务管理器指令,它实际上将 service
和 chkconfig
这两个命令组合到一起。
任务 | 旧指令 | 新指令 |
---|---|---|
使某服务自动启动 | chkconfig httpd on | systemctl enable httpd.service |
使某服务不自动启动 | chkconfig httpd off | systemctl disable httpd.service |
检查服务状态 | service httpd status | systemctl status httpd.service |
显示所有已启动的服务 | chkconfig --list | systemctl list-units --type=service |
启动某服务 | service httpd start | systemctl start httpd.service |
停止某服务 | service httpd stop | systemctl stop httpd.service |
重启某服务 | service httpd restart | systemctl restart httpd.service |
查询安装apache后生产的文件列表:rpm -ql httpd
在浏览器输入localhost或者ip地址,测试是否出现一个Apache test page (测试页面)
如局域网或外网不能访问,则检查80端口是否打开。
CentOS7用的是Firewall-cmd,CentOS7之前用的是iptables防火墙,
2、mysql
yum安装mysql的官方说明
https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/
下载mysql的yum源
在官网 https://dev.mysql.com/downloads/repo/yum/
el7 表示centOS7.*版本,el6 表示centOS6.*版本,大致是这么个意思
wget https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
安装源
rpm -ivh mysql80-community-release-el7-1.noarch.rpm
或
yum localinstall mysql80-community-release-el7-1.noarch.rpm
yum 命令的 localinstall参数:安装本地的rpm软件包
/etc/yum.repos.d
目录下,就多了Yum仓库的两个配置文件(.repo文件)
mysql-community.repo
mysql-community-source.repo
选择mysql版本
默认是安装最新版的mysql,可通过手动编辑/etc/yum.repos.d/mysql-community.repo
文件来选择需要的版本。
如要选择5.7版本,则把[mysql80-community]规则的enabled改为0,
把[mysql57-community] 规则的enabled改为1。
# Enable to use MySQL 5.7
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
通过命令 yum repolist enabled | grep mysql
查看是否使用了正确的库
安装:
yum install mysql-community-server
开启服务:
systemctl start mysqld
查看MySQL的启动状态
systemctl status mysqld
开机启动
systemctl enable mysqld
mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码
获取密码
grep 'temporary password' /var/log/mysqld.log
得到这行A temporary password is generated for root@localhost:******
冒号后面的就是密码
登入修改密码
mysql -uroot -p*******
set password = password('123456');
下次登入:
mysql -uroot -p123456
注意:mysql5.7默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则报错。
开放远程访问权限
use mysql;
update user set host = '%' where user = 'root';
百分号相当于*号,意为全部放行,也可改为IP地址则只允许此IP连接,也可以设置为192.168.%.%或者192.168.0.1/9代表允许一个ip段进行连接,也可以多加几条数据设置不同ip允许连接。
3、php
(一)安装默认版本(5.3)
yum install php php-mysql
(二)使用其他yum资源安装php
安装remi源
CentOS 6 :
wget https://rpms.remirepo.net/enterprise/remi-release-6.rpm
rpm -Uvh remi-release-6.rpm
CentOS 7 :
wget https://rpms.remirepo.net/enterprise/remi-release-7.rpm
rpm -Uvh remi-release-7.rpm
安装后remi 源后,已默认启用 remi-safe 仓库
yum repolist all
查看所有的仓库,如下图,可选择安装不同版本的PHP,
yum install --enablerepo=remi --enablerepo=remi-php56 php php-mysql
其中--enablerepo=remi
、 --enablerepo=remi-php56
是使用remi仓库和remi-php56仓库的意思。
如想安装PHP7.0,则可运行
yum install --enablerepo=remi --enablerepo=remi-php70 php php-mysql
(三)源码编译安装php
…略