阿伦教你 Linux(Centos7)配置LAMP环境
1、1.安装Apache服务器
systemctl start httpd.service #启动apache
systemctl stop httpd.service #停止apache
systemctl restart httpd.service #重启apache
systemctl enable httpd.service #设置apache开机启动
在终端以root权限运行以下命令:
yum install httpd -y

2、启动Apache
systemctl start httpd设置开机启动systemctl enable http
测试Apache
浏览器访问 http://localhost/ 或者服务器的IP地址

3、Apache配置在httpd.conf(Apache主配置文件)中增加:
AddType application/x-httpd-php .php
在index.html 前面增加一个
index.php
AllowOverride None #修改为:AllowOverride All (允许.htaccess) vi /var/www/html/index.html
写入下面这些内容
<html><body>测试</body><html>再到浏览器中访问看看


4、2.安装PHP 解释器
在终端以root权限运行以下命令:
yum install php php-mysql php-gd php-pear -y
测试PHP:
在Apache文档根目录创建“index.php”
vi /var/www/html/index.php
<?php phpinfo();?>
重启 httpd 服务:
systemctl restart httpd浏览器访问 http://localhost/index.php 或者服务器的IP地址

5、3.安装MariaDB数据库服务器
CentOS 7.0中,已经使用MariaDB替代了MySQL数据库
systemctl start mariadb.service #启动MariaDB
systemctl stop mariadb.service #停止MariaDB
systemctl restart mariadb.service #重启MariaDB
systemctl enable mariadb.service #设置开机启动
在终端以root权限运行以下命令:
yum install mariadb-server mariadb -y
启动MariaDB
systemctl start mariadb
设置开机启动
systemctl enable mariadb
设置root密码
默认情况下,root密码为空。为防止未授权的访问,我们设置root密码
mysql_secure_installation 敲回车
回车之后,根据提示输入Y
输入2次密码,回车
根据提示一路输入Y
最后出现:Thanks for using MySQL!
MySql密码设置完成,重新启动 MySQL:
systemctl restart mariadb.service #重启MariaDB



6、4.安装PHPmyadmin
在终端以root权限运行以下命令:
添加 EPEL repository
yum install epel-release
安装 phpMyAdmin:yum install phpmyadmin -y
配置phpMyAdmin
默认,phpMyAdmin只能由本机访问。为了能够远程访问,编辑phpmyadmin.conf file:
vi /etc/httpd/conf.d/phpMyAdmin.conf查找/<Directory> ,注释掉或删除如下内容
<Directory /usr/share/phpMyAdmin/>
AddDefaultCharset UTF-8
<IfModule mod_authz_core.c>
# Apache 2.4
<RequireAny>
Require ip 127.0.0.1
Require ip ::1
</RequireAny>
</IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
Order Deny,Allow
Deny from All
Allow from 127.0.0.1
Allow from ::1
</IfModule>
</Directory>
<Directory /usr/share/phpMyAdmin/setup/>
<IfModule mod_authz_core.c>
# Apache 2.4
<RequireAny>
Require ip 127.0.0.1
Require ip ::1
</RequireAny>
</IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
Order Deny,Allow
Deny from All
Allow from 127.0.0.1
Allow from ::1
</IfModule>
</Directory>
添加
<Directory /usr/share/phpMyAdmin/>
Options none
AllowOverride Limit
Require all granted
</Directory>
编辑“config.inc.php” 改变phpMyAdmin的authentication,修改“cookie” 为 “http”vi /etc/phpMyAdmin/config.inc.php


7、重启the Apache service:
systemctl restart httpd
问 phpmyadmin 的控制台 http://192.168.16.101/phpmyadmin/
配置完成了
