- 安装 wget
yum -y install wget
- 更改yum源与更新系统 (可选)
[1] 首先备份/etc/yum.repos.d/CentOS-Base.repo
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
[2] 进入yum源配置文件所在文件夹
[root@localhost yum.repos.d]# cd /etc/yum.repos.d/
[3] 下载163的yum源配置文件,放入/etc/yum.repos.d/(操作前请做好相应备份)
[root@localhost yum.repos.d]# wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
[4] 运行yum makecache生成缓存
[root@localhost yum.repos.d]# yum makecache
[5] 更新系统
[root@localhost yum.repos.d]# yum -y update
- 关闭防火墙
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
-
安装Apache yum -y install httpd
systemctl start httpd.service #启动apache
systemctl stop httpd.service #停止apache
systemctl restart httpd.service #重启apache
systemctl enable httpd.service #设置apache开机启动
在客户端浏览器中打开服务器IP地址,会出现下面的界面,说明apache安装成功 -
安装MariaDB(就是mysql)
yum -y install mariadb mariadb-server #询问是否要安装,输入Y即可自动安装,直到安装完成
systemctl start mariadb.service #启动MariaDB
systemctl stop mariadb.service #停止MariaDB
systemctl restart mariadb.service #重启MariaDB
systemctl enable mariadb.service #设置开机启动
cp /usr/share/mysql/my-huge.cnf /etc/my.cnf #拷贝覆盖配置文件 为root账户设置密码 mysql_secure_installation回车,根据提示输入Y
输入2次密码,回车
根据提示一路输入Y
最后出现:Thanks for using MySQL!
MySql密码设置完成 给root 远程访问授权 mysql -uroot -proot GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION; systemctl restart mariadb.service #重启MariaDB 用mysql客户端连接测试
-
安装PHP
1. 配置yum源
事先确认yum源的链接是不是有效的。
# rpm -Uvh http://ftp.iij.ad.jp/pub/linux/fedora/epel/7/x86_64/e/epel-release-7-5.noarch.rpm # rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
2. 确认安装的php版本
# yum list --enablerepo=remi --enablerepo=remi-php56 | grep php
3. 安装php5.6
# yum -y install --enablerepo=remi --enablerepo=remi-php56 php php-opcache php-pecl-apcu php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pdo php-pear php-fpm php-cli php-xml php-bcmath php-process php-gd php-common
php-opcache及php-pecl-apcu会有效的提高php执行速度。
4. 确认php版本
# php -v PHP 5.6.6 (cli) (built: Feb 19 2015 10:19:37) Copyright (c) 1997-2015 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2015, by Zend Technologies with Xdebug v2.3.1, Copyright (c) 2002-2015, by Derick Rethans
systemctl restart mariadb.service #重启MariaDB
systemctl restart httpd.service #重启apache
-
测试篇
cd /var/www/html
vi index.php #输入下面内容
<?php
phpinfo();
?>
:wq! #保存退出
在客户端浏览器输入服务器IP地址,可以看到如下图所示相关的配置信息!