CentOS下LAMP环境搭建

背景:半年多没有碰代码了,现在又因为工作的原因重新拾起程序,今天先搭建了下LAMP环境,顺便也做了下记录

第一步:配置防火墙

CentOS7.0默认是使用的是Firewall作为防火墙
1,关闭firewall
systemctl stop firewalld.service  #关闭防火墙#
systemctl disable firewalld.service #禁止防火墙开机启动#

2,关闭SELINUX

vim /etc/selinux/config

#SELINUX=enforcing#注释掉

SELINUX=disabled  在该行前增加“#”注释掉
:wq!  #保存退出
setenforce 0 #使配置立即生效

(至于为什么要关闭Firewall,关闭SELINUX,只要是为了降低LINUX的安全等级,更方便操作而已,有兴趣的小伙伴可以自己查阅相关资料)!

第二步:安装Apache
yum install httpd  #根据系统提示信息,输入Y安装即可
systemctl start httpd.service #启动Apache
systemctl stop httpd.service #停止Apache
systemctl restart httpd.service #重启APache
systemctl enable httpd.service #设置Apace开机自启动

第三步:安装mariadb(Mysql)
yum install mariadb mariadb-server   #询问是否要自动安装,输入Y即可自动安装,知道安装完成为止
systemctl start mariadb.service #启动mariadb
systemctl stop mariadb.service #关闭mariadb
systemctl restart mariadb.service #重启mariadb
systemctl enable mariadb.service #设置mariadb开机自启动

第四步:开启MySQL
mysql -u root -p#回车确定(默认没有密码)
设置mysql密码
set password for 'root'@‘localhost’=password('root');
授权mysql远程连接
grant all on *.* to root identified by 'root';

第五步:安装php及其相关组件,使PHP支持MySQL
yum install php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash;
#选择以上安装包进行安装,根据提示输入Y回车#
systemctl restart mariadb.service
systemctl restart httpd.service

第六步:测试php是否启动
cd /var/www/html
vim indexphp
输入以下内容:

  <?php

phpinfo();

?> :wq!#保存并退出在客户端浏览器输入服务器的IP,如果看到如下图信息,测环境搭建成功


猜你喜欢

转载自blog.csdn.net/hi_pengbo/article/details/70312685