Centos7.0版本下LAMP环境的简易安装
一, 安装MySQL (rpm安装)
1.rm -rf /etc/yum.repos.d/*
删除备份
2.编辑写入yum源
#vi /etc/yum.repos.d/centos.repo
[centos]
name=centos
baseurl=file:///opt/centos
gpgcheck=0
enabled=1
3. 挂载镜像
#mount -o loop CentOS-7-x86_64-DVD-1511.iso /mnt/
#mkdir /opt/centos
#cp -rvf /mnt/* /opt/centos/
#umount /mnt/
4.关闭防火墙并设置开机不自启
#systemctl stop firewalld
#systemctl disable firewalld
5.清除缓存,验证yum源
#yum clean all
#yum list
6.下载上传
mysql-5.7.21-1.el7.x86_64.rpm-bundle.tar
7.卸载自带mysql
yum -y remove mariadb-libs-5.5.44-2.el7.centos.x86_64
8…解压
tar -xvf mysql-5.7.21-1.el7.x86_64.rpm-bundle.tar
9.安装组件
rpm -ivh mysql-community-common-5.7.21-1.el7.x86_64.rpm rpm -ivh mysql-community-libs-5.7.21-1.el7.x86_64.rpm rpm -ivh mysql-community-client-5.7.21-1.el7.x86_64.rpm
yum install net-tools
rpm -ivh mysql-community-server-5.7.21-1.el7.x86_64.rpm
- 启动mysql
systemctl start mysqld systemctl enable mysqld.serivce
- 通过命令查看默认密码。
#grep “password” /var/log/mysqld.log
2018-03-22T03:34:26.125175Z 1 [Note] A temporary password is generated for root@localhost:XOfhfHqT3w,A
黄色部分为产生的默认随机密码。
2018-03-22T03:38:41.652605Z 2 [Note] Access denied for user ‘root’@‘localhost’ (using password: YES)
12.使用mysql -u root -p命令,并使用默认密码登录数据库。
#mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.21
13.使用
alter user ‘root’@‘localhost’ identified by ‘password’;
修改密码,其中password要符合密码规则。使用flush privileges刷新权限;
14.退出后重新登录验证密码。成功。
或者wget安装
注:用wget需要联网
1.从官网下载mysql的repo源
wget http://repo.mysql.com/mysql57-community-release-el7-9.noarch.rpm
如果提示wget命令无效,则安装wget组件:yum -y install wget
2.安装此rpm文件
rpm -ivh mysql57-community-release-el7-9.noarch.rpm
4.使用yum安装。
yum -y install mysql-server
安装了5.7.22
5.启动mysql服务。
[root@jack ~]# systemctl start mysqld
Failed to start mysqld.service: Unit not found.
设置 mysqld.service服务自动启动
[root@jack ~]# systemctl enable mysqld.service
[root@jack ~]# systemctl start mysqld
启动服务成功。
6.通过命令查看默认密码。
[root@jack ~]# grep "password" /var/log/mysqld.log
2018-03-22T03:34:26.125175Z 1 [Note] A temporary password is generated for root@localhost:XOfhfHqT3w,A
黄色部分为产生的默认随机密码。
2018-03-22T03:38:41.652605Z 2 [Note] Access denied for user ‘root’@‘localhost’ (using password: YES)
7.使用mysql -u root -p命令,并使用默认密码登录数据库。
[root@jack ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.21
8.使用
alter user ‘root’@‘localhost’ identified by ‘password’;
修改密码,其中password要符合密码规则。使用flush privileges刷新权限;
9.退出后重新登录验证密码。成功。
安装Apache
1、安装
yum -y install httpd
- 根据本机设置进行编辑
#vi /etc/httpd/conf/httpd.conf
<VirtualHost 172.49.2.170>
ServerAdmin y@centos7.com
DocumentRoot /home/user1/web1/
ServerName y.centos7.com
DirectoryIndex index.html
3.#apachectl configtest
//检测是否有配置的语法错误
4.可以检查:
#getenforce
应显示:disabled
或:permissive
如果不是修改
#cd /etc/selinux
#vi config
将 Enforcing改成:disabled 或:permissive
保存退出,重启电脑
5. #systemctl restart httpd.service
//重启http服务!
安装PHP
由于linux的yum源不存在php7.x,所以我们要更改yum源
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum search php7
yum -y install php71w php71w-cli php71w-common php71w-devel php71w-embedded php71w-fpm php71w-gd php71w-mbstring php71w-mysqlnd php71w-opcache php71w-pdo php71w-xml
修改Apache的配置文件*.conf
DirectoryIndex index.html index.php #添加index.php
找到:
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
添加如下内容
AddType application/x-httpd-php-source .phps
AddType application/x-httpd-php .php
添加LoadModule php7_module modules/libphp7.so
在、/var/www/html下创建一个index.php文件。内容:
<?php
phpinfo();
?>
通过浏览器访问主机名/index.php会看到php信息。
上传phpMyAdmin.zip到/www/web/,解压缩
unzip phpMyAdmin.zip
如果命令无效则需要安装unzip
修改解压出的文件夹名字为phpMyAdmin
使用地址/phpMyAdmin访问,输入MySql数据库的用户名密码即可管理MySQL数据库