Ubuntu+Apache+PHP+Mysql环境搭建

Ubuntu+Apache+PHP+Mysql环境搭建

Ubuntu+Apache+PHP+Mysql环境搭建


  1. Apache

    1、安装Apache,安装命令:sudo apt-get install apache2
    2、环境配置:
    1)配置文件:路径为/etc/apache2,配置文件是apache2.conf,而没有http.conf。
    2)默认网站根目录:/var/www/html,使用浏览器访问http://localhost 即可打开;
    3)修改网站根目录:
    A、“sudo vim /etc/apache2/apache2.conf”→找到””的位置→更改”/var/www/“为新的根目录“/home/www”即可
    B、”sudo vi/etc/apache2/sites-available/000-default.conf”→找到”DocumentRoot /var/www/html”的位置→更改”/var/www/html”为新的根目录“/home/www”即可。
    4)重启Apache服务器: sudo /etc/init.d/apache2 restart

  2. php

    1、更新源列表,否则安装php会失败:
    命令行输入: vim /etc/apt/source.list
    在最前面添加以下内容:
    deb http://mirrors.aliyun.com/ubuntu/ precise main restricteduniverse multiverse
    deb http://mirrors.aliyun.com/ubuntu/ precise-security mainrestricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ precise-updates mainrestricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ precise-proposed mainrestricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ precise-backports mainrestricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ precise mainrestricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ precise-securitymain restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ precise-updatesmain restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ precise-proposedmain restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ precise-backportsmain restricted universe multiverse
    apt-get update //更新一下列表
    2、安装PHP,安装命令:sudoapt-get install php5
    3、让Apache支持php,安装命令:sudo apt-get install libapache2-mod-php5
    4、安装php5-gd模块,安装命令:sudoapt-get install php5-gd
    5、让PHP支持curl
    1)首先查看php5-curl是否已安装:dpkg -l | grep ‘php5-curl’
    2)如果没有安装,则:apt-get install php5-curl
    3)确保 extension_dir存在,并且包含curl.so,
    查找extension_dir:php -i | grep extension_dir
    4)确保 /etc/php5/mods-available/curl.ini存在,文件内容如下:
    ; configuration for php CURL module
    ; priority=20
    extension=curl.so

  3. Mysql

    1、安装Mysql,安装命令:sudoapt-get install mysql-server,安装过程中设置密码
    2、允许root远程登录:mysql -u root -p
    1)从所有主机:grant all privileges on . username@”%” identified by “password” with grant option;
    2)刷新权限 flush privileges;
    3)can’t connect to mysql server解决方法:修改配置文件,路径为/etc/mysql/my.cnf或mysql.conf.d,注释掉bind-address = 127.0.0.0
    即:#bind-address = 127.0.0.1

发表评论

邮箱地址不会被公开。 必填项已用*标注