一、安装apache
1.安装Apache,命令:sudo apt-get install apache2
2.1)配置文件:路径为/etc/apache2,配置文件是apache2.conf,而没有http.conf
2)默认网站根目录:/var/www/html
3.检验apache安装是否成功的标志是:
在浏览器中输入localhost+回车,浏览器中显示下图界面,表示apache安装成功
4.重启apache的指令:sudo /etc/init.d/apache2 restart
注:每次修改了apache的配置之后,重启才能生效
二、安装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 :apt-get install php5-curl
安装完之后重启apache
三、安装Mysql
1.安装Mysql,安装命令:sudoapt-get install mysql-server,安装过程中设置密码(用户名默认为root)
2.建立php和Mysql的链接指令:sudo apt-get install php5-mysql
3.检测php和Mysql的链接dpkg-reconfigure php5-mysql
4.重启mysql:sudo /etc/init.d/mysql restart
5.重启apache:sudo /etc/init.d/apache2 restart
四、测试apache+php+mysql是否能正常协同工作
vim hello.php
在文件中输入:
echo "hello world\n";
//此句显示正常表明配置好了apache
echo "now time:" . date("Y-m-d H:i:s");
//此句显示正常表明配置好了php
$link = mysql_connect("localhost","root","root");
//此句正常表明配置好了mysql,localhost是数据库地址,root是数据库账号,123是数据库密码
echo "\n";//换行
var_dump($link);//输出数据库的连接情况
?>
执行结果: