CentOS7下的LAMP环境搭建

CentOS7下的LAMP环境搭建,刚接触的时候在MySQL和PHP关联碰到一点问题
作为新手,希望把自己学习碰到的问题发布出来,一方面可以给其他人一点启发,另一方面自己以后也可以看看,事先准备:
虚拟机:
VMware
镜像:
CentOS-7.0-1406-x86_64-DVD.iso
网络适配器:
桥接模式(为了能够让外部网络访问,NAT模式只能本机访问)

下面开始我们搭建LAMP的步骤吧
一、安装虚拟机(最好选用桥接模式,看自己的需要吧)

二、安装CentOS7(在root权限下开始下面的安装)

三、安装Apache
a).安装httpd
yum -y install httpd
b).启动httpd服务
systemctl start httpd.service
c).设置开机启动
systemctl enable httpd.service
d).验证 httpd是否安装成功
使用 ip addr 查看虚拟机的ip地址
然后去本机的浏览器上访问自己的ip
发现访问是不成功的, 不用担心,我们把防火墙配置一下就可以了
要让外网能都访问到apache的主目录,执行以下命令:
firewall-cmd --zone=public --add-service=http --permanent
firewall-cmd --zone=public --add-service=https --permanent
firewall-cmd --reload

   这里permanent参数是为了永久开放http这个service,不添加的话

   下次重启虚拟机服务就会失效,reload参数是更新防火墙规则
   然后现在在去访问ip ,就会出现apache默认的页面 Testing 123...
   那我们就apache就安装成功了

四、安装PHP
a).安装
yum -y install php
b).重启apache服务
systemctl restart httpd.service

  c).然后我们写一个简单的php文件在浏览器中访问一下   

     touch /var/www/html/php1.php
     vi /var/www/html/php1.php
    按 a或i进入插入模式
    <?php phpinfo(); ?>
    按Esc键退出编辑模式
    :wq (保存退出) 
  然后在自己的浏览器中   输入10.203.87.100/php1.php(自己的ip)
  如果出现PHP版本这样的一些信息,那说明安装成功了

五、安装MariaDB

    MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可 MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。
    a).安装
        yum install mariadb-server mariadb
        Is this ok [y/d/N]: y
    mariadb数据库的相关命令是:
           systemctl start mariadb  #启动MariaDB
           systemctl stop mariadb  #停止MariaDB
           systemctl restart mariadb  #重启MariaDB
           systemctl enable mariadb  #设置开机启动
   b).启动数据裤
      systemctl start mariadb
   c).设置开机启动
      systemctl enable mariadb
   d).进入数据库
  (因为还没设置数据库密码,所以输入要求密码时直接回车就可以了)
     mysql -u root -p
   e).设置数据库密码

     set password for 'root'@'localhost'=password('password');

     ‘password’是你以后登录数据库的密码
     show databases;
   f).退出数据库
     exit;

六、将PHP和MySQL关联起来

   yum search php
   yum -y install php-mysql

七、安装常用的PHP模块
a).安装
yum -y install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel
b).重启apache服务
systemctl restart httpd.service
再次访问 yourip/php1.php会看到安装的模板信息
到此,我们的LAMP环境就搭好了

转自:https://blog.csdn.net/dFireJJ/article/details/78311781

猜你喜欢

转载自blog.csdn.net/qq_39629343/article/details/80119299