http://www.linuxidc.com/Linux/2014-07/104563.htm
CentOS 6.5使用yum快速搭建LAMP环境
1、安装Apache
[root@localhost ~]# yum -y install httpd
# 开机自启动
[root@localhost ~]# chkconfig httpd on
# 启动httpd 服务
[root@localhost ~]# service httpd start
### 安装apache 一些扩展
root@localhost ~]# yum -y install httpd-manual mod_ssl mod_perl mod_auth_mysql
现在直接在浏览器键入http://localhost 或 http://本机IP ,应该会看到Apache的测试页面
这里需要注意iptables的设置哦。
2、安装配置MySQL
# 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 start
# 开机启动
[root@localhost ~]# chkconfig mysqld on
初次安装mysql,root账户没有密码。
[root@yl-web yl]# mysql -u root
Welcome to the MySQL monitor. Commands end with ;or \g.
Your MySQL connection id is 3
Server version: 5.6.26 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporationand/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.01 sec)
在mysql安装过程中如下内容:
Installed:
mysql-community-client.x86_64 0:5.6.26-2.el7 mysql-community-devel.x86_64 0:5.6.26-2.el7
mysql-community-libs.x86_64 0:5.6.26-2.el7 mysql-community-server.x86_64 0:5.6.26-2.el7
Dependency Installed:
mysql-community-common.x86_64 0:5.6.26-2.el7
Replaced:
mariadb.x86_64 1:5.5.41-2.el7_0 mariadb-devel.x86_64 1:5.5.41-2.el7_0 mariadb-libs.x86_64 1:5.5.41-2.el7_0
mariadb-server.x86_64 1:5.5.41-2.el7_0
所以安装完以后mariadb自动就被替换了,将不再生效。
[root@yl-web yl]# rpm -qa |grep mariadb
[root@yl-web yl]#
# 进行一些安全性配置
[root@localhost ~]# /usr/bin/mysql_secure_installation
[root@localhost ~]# netstat -tulpn | grep -i mysql
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 1723/mysqld
OK, 我们看到mysqld已经启动,监听在3306端口上。
3、安装php
安装相关模块:为了让PHP支持MySQL,我们可以安装php-mysql软件包;也可使用以下命令搜索可用的php模块
[root@localhost ~]# yum -y install php php-mysql
# 安装php常用扩展
[root@localhost ~]# yum search php
[root@localhost ~]# yum -y install gd php-gd gd-devel php-xml php-common php-mbstring php-ldap php-pear php-xmlrpc php-imap
### 重启httpd服务,这一步很重要
[root@localhost ~]# service httpd restart
然后,我们提供php页面,测试
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# vi index.php
<?php
phpinfo();
?>
然后,我们再次在浏览器键入http://localhost 或 http://本机IP ,应该会看到如下页面
4、安装配置phpMyAdmin
安装好MySQL,Apache及PHP后,为了可视化的管理MySQL数据库,我们可以安装phpMyAdmin。到其官网下载最新版本:http://www.phpmyadmin.net/home_page/
在Windows下,其实Navicat也是一个非常好用的MySQL可视化工具,推荐使用。
[root@localhost ~]# unzip phpMyAdmin-4.2.6-all-languages.zip
[root@localhost ~]# mv phpMyAdmin-4.2.6-all-languages /var/www/html/phpmyadmin
[root@localhost ~]# cd /var/www/html/phpmyadmin
[root@localhost ~]# cp libraries/config.default.php config.inc.php
[root@localhost ~]# vi cnfig.inc.php
$cfg['PmaAbsoluteUri'] = '';这里填写 phpMyAdmin 的访问网址。
$cfg['Servers'][$i]['host'] = 'localhost'; // MySQL hostname or IP address
$cfg['Servers'][$i]['port'] = ''; // MySQL port - leave blank for default port
$cfg['Servers'][$i]['user'] = 'root'; // 填写 MySQL 访问 phpMyAdmin 使用的 MySQL 用户名,默认为 root。
fg['Servers'][$i]['password'] = ''; // 填写对应上述 MySQL 用户名的密码。
# 然后重启,httpd服务
[root@localhost ~]# service httpd restart
在浏览器键入http://localhost/phpmyadmin 即可访问。
如果遇到访问权限的问题,请检查SElinux。