Linux环境下搭建LAMP

安装Apache

  1. 安装Apache

    1
    yum install httpd -y
  2. 启动服务

    1
    service httpd restart
  3. Apache服务开机启动

    1
    chkconfig httpd on
  4. Apache的配置文件

    1
    /etc/httpd/conf/httpd.conf
  5. 网站根目录

    1
    /var/www/html/

安装mysql

  1. 安装mysql

    1
    2
    3
    wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
    rpm -ivh mysql-community-release-el7-5.noarch.rpm
    yum install mysql-server
  2. 启动mysql

    1
    service mysqld restart
  3. 首次登录mysql

    1
    mysql 
  4. 设置密码

    1
    2
    3
    4
    show databases;
    use mysql;
    select user,password from user;
    update user set password=password('root') where user='root';
  5. mysql刷新权限命令

    1
    flush privileges;
  6. 再次登录mysql

    1
    2
    mysql -u root(用户名) -p
    root(密码)

安装php

  1. 安装php和连接php、mysql工具

    1
    yum install php php-mysql
  2. 启动Apache和mysql

    1
    2
    service httpd restart
    service mysqld restart
  3. 测试php和mysql是否连接成功

    1
    2
    3
    4
    5
    6
    $link = mysql_connect('localhost','root','root');
    if($link){
    echo "successful";
    }else{
    echo "fail";
    }

常见问题

  1. 报错Cannot find a valid baseurl for repo: base/7/86-64

    解决方案:

    1
    2
    3
    cd /etc/sysconfig/network-scriptsls
    vim ifcfg-ens33
    ONBOOT=yes //修改,保存退出即可