zoukankan      html  css  js  c++  java
  • LAMP开发之环境搭建(2014.12.7在ubuntu下)

    Ubuntu下搭建LAMP环境

    前言:学习PHP脚本编程语言之前,必须先搭建并熟悉开发环境,开发环境有很多种,例如LAMP、WAMP、MAMP等。这里我搭建的是LAMP环境,即Linux、Apache、MySQL、PHP环境。网上搭建方法也有很多,但都不是最新的,本搭建时间为2014.12.07.

    一、搭建环境
    Lenovo Y470
    VMWare9.0
    Ubuntu 14.04.1 LTS (Trusty Tahr):ubuntu-14.04.1-desktop-i386.iso
    二、安装软件
    1.安装apache2:

    sudo apt-get install apache2

    安装完成后,运行如下命令重启apache:sudo /etc/init.d/apache2 restart,在浏览器中输入
    http://localhost或者http://127.0.0.1,会看到"It works!"说明apache安装成功。

    2.安装php: 

    sudo apt-get install php5

    3.安装Mysql:

    sudo apt-get install mysql-server
    sudo apt-get install mysql-client

    安装过程中,会要求设置mysql服务器的密码,输入即可。

    4.安装phpmyadmin

    sudo apt-get install phpmyadmin

    安装过程中选择apache2,点击确定,下一步选择是要配置数据库,并输入密码。

    5 安装扩展模块

    sudo apt-get install libapache2-mod-php5 //最新版,自动已经安装
    sudo apt-get install libapache2-mod-auth-mysql
    sudo apt-get install php5-mysql
    sudo apt-get install php5-curl  (客户端 URL 库函数库)
    sudo apt-get install php5-gd (GD库图像函数库)

    6 添加测试模块

    sudo chmod 777 /var/www                            //修改权限
    sudo ln -s /usr/share/phpmyadmin /var/www  //建立软连接

    在浏览器中输入http://localhost/phpmyadmin,如果出现数据库管理软件,说明成功。

    三 测试网页

    1 启用mod_rewrite模块

    sudo a2enmod rewrite
    sudo /etc/init.d/apache2 restart //或sudo service apache2 restart 重启Apache服务器:

    2 设置Apache支持.htm .html .php

    sudo gedit /etc/apache2/apache2.conf
    AddType application/x-httpd-php .php .htm .html //添加

    3 测试php网页

    /*lamp.php*/
    <?php
    $link = mysql_connect("localhost", "root", "password");//注意修改自己的密码
    if(!$link)
    die('Could not connect: ' . mysql_error());
    else
    echo "Mysql 配置正确!";
    mysql_close($link);
    ?>

    将代码存放到/var/www/html/中,并访问 http://localhost/lamp.php 显示’Mysql 配置正确‘就代表配置正确。

    四 常见文件

    错误1:

    执行命令:sudo /etc/init.d/apache2 restart
    出现错误:apache2: Could not reliably determine the server's fully qualified domain name, using 
    127.0.1.1 for ServerName
    解决方法:
    打开:sudo gedit /etc/apache2/apache2.conf
    添加:
    #Server Name
    ServerName 127.0.0.1

    错误2:
    执行命令http://domain/phpmyadmin
    出现错误:The requested URL /phpmyadmin was not found on this server
    解决方法:
    打开:sudo gedit /etc/apache2/apache2.conf
    添加:Include /etc/phpmyadmin/apache.conf
    重启:sudo /etc/init.d/apache2 restart
    执行:http://domain/phpmyadmin

    错误3:
    执行命令:http://localhost/phpinfo.php
    出现错误:出现乱码
    解决方法:
    打开:sudo gedit /etc/apache2/apache2.conf
    添加:AddDefaultCharset UTF-8
    重启:sudo /etc/init.d/apache2 restart
    执行:http://localhost/phpinfo.php

    错误4:

    执行命令:http://localhost/test.php

    出现错误:The requested URL /phpinfo.php was not found on this server.

    解决方法:

    1 出现上述错误,查看日志(/var/log/apache2/error.log,发现系统查找的目的
    是/var/www/html
    2 把自定义的文件放到/var/www/html

    注:还可以可参考:/etc/apache2/sites-available/dafault.conf,建立自定义虚拟服务器,来解决此问题,下一节将重点介绍。

    五 参考链接

    Ubuntu搭建LAMP环境

    Ubuntu下搭建LAMP环境

  • 相关阅读:
    Asp.NET 4.0 ajax实例DataView 模板编程1
    ASP.NET 4.0 Ajax 实例DataView模板编程 DEMO 下载
    部分东北话、北京话
    .NET 培训课程解析(一)
    ASP.NET 4.0 Ajax 实例DataView模板编程2
    ASP.NET Web Game 架构设计1服务器基本结构
    ASP.NET Web Game 构架设计2数据库设计
    TFS2008 基本安装
    Linux上Oracle 11g安装步骤图解
    plsql developer远程连接oracle数据库
  • 原文地址:https://www.cnblogs.com/gjianw217/p/4149425.html
Copyright © 2011-2022 走看看