1.开始说明

下面很多可能参照网上其中以为前辈的,但有所改进吧。这些设置可能会有所不同,你需要根据不同情况进行修改。

安装apache2

2.切换管理员身份

在ubuntu中需要用root身份进行操作,所以用下面的命令确保以root身份登录:

sudo su

3.开始安装mysql5

apt-get install mysql-server mysql-client

你将被要求提供一个mysql的root用户的密码,我们需要在红色区域设置密码。

new password for the mysql root user: repeat password for the mysql root user:

4.安装apache2

apache2的是作为一个ubuntu的软件包,因此我们可以直接用下面命令安装它:

apt-get install apache2

现在,您的浏览器到http://localhost,你应该看到apache2的测试页:

如果顺利的话会出现:

It works!

然后下面是:

This is the default web page for this server.

The web server software is running but no content has been added, yet.


apache的默认文档根目录是在ubuntu上的/var/www目录 ,配置文件是/ etc/apache2/apache2.conf。配置存储在的子目录在/etc/apache2目录。

安装php5

5.安装php5

我们可以直接安装php5和apache的php5的模块,如下:

apt-get install php5 libapache2-mod-php5

安装完需要重启

/etc/init.d/apache2 restart

6.测试的php5并获取php5安装的详细信

默认网站的文件根目录是在/var/www下中。现在我们将在该目录中创建一个小型php文件(info.php的)在浏览器中调用它。该文件将显示很多关于我们的php安装,如安装的php版本和有用的一些细节。

vi /var/www/info.php

这里说明下,如果不会命令行操作的话(当然建议大家既然用linux应该习惯学会用会命令行)。可以手动建立,也就是在系统文件/var/www/下建立文件info.php,里面编写

<?php
phpinfo()
?>

这里说明下:也是我遇到的问题,我开始安装好ubuntu 12.04后,在这里发现我没权限操作,虽然已经获得root权限了,这里给大家讲下,
我们应该怎么设置文件及文件目录的可读写权限。
大家多知道,我们用虚拟主机都知道设置777什么的,其实这里也是一样的,有很多方法可以用,我就讲其中一种吧。
这里我们用到chmod ,比如我们要设置我们的www目录读写,就是chmod 777 /var/www/。具体大家可以参考百度百科这个命令的用法
http://baike.baidu.com/view/1229012.htm.
现在,我们可以用浏览器访问例如http://localhost/info.php

注意:在此处,可能出现了一个问题!用浏览器访问时,出现错误,The requested URL /info.php was not found on this server.解决办法是:将info.php放在/var/www/html/目录下,而不是/var/www/目录下。


正如你所看到的,php5正常工作,它通过apache 2.0的处理程序,在服务器api线。如果你继续向下滚动,你会看到所有在php5中已经启用的模块。mysql是没有列出,这意味着我们没有在php5支持mysql。

php5获得mysql的支持

7.php5获得mysql的支持

让php在mysql中获得支持,我们可以安装的php-mysql软件包。安装一些其他的php5模块,以及您可能需要的应用程序,这是一个好主意:

apt-cache search php5

还安装需要安装的

apt-get install php5-mysql php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl

现在重新启动apache2的:

/etc/init.d/apache2 restart   注意:此处可能会fail,需要在命令前面加上sudo

现在,重载http://localhost/info.php在您的浏览器,并再次向下滚动到模块部分。现在,你应该找到许多新的模块,包括mysql模块。


安装phpmyadmin

8.安装phpmyadmin

phpmyadmin是一个网络接口,通过它可以管理你的mysql数据库。

phpMyAdmin is a free software tool written in PHP intended to handle the administration of MySQL over the World Wide Web.

Open Terminall. And type the below code in terminal and hit enter.

sudo apt-get install phpmyadmin

Type your ubuntu password if needed.

Type y and hit enter to confirm phpMyadmin installation.

During the installation you will be prompted for a webserver configuration.
Select

apache2

(already selected)
press enter.

Now you will be promped for phpmyadmin configuration

Select

No

and press enter.

注意,如果上述两个选择选错,并且现在访问phpmyadmin,此处可能会出现问题。


Type below command in terminal

sudo cp /etc/phpmyadmin/apache.conf /etc/apache2/conf.d

restart your apache server using

sudo /etc/init.d/apache2 restart

Open your browser and type

http://localhost/phpmyadmin/

in the address bar and press enter.

Type your mysql root  username and password to login.


You’re now ready to start building your local website. just put all of your files into

/var/www


ubuntu 12.04下搭建web服务器(MySQL+PHP+Apache) 教程 _Linux

若#1045 无法登录 MySQL 服务器或者禁止空密码,则

我们需要修改/phpmyadmin/libraries/config.default.php 文件,找到下面的两行,

$cfg['Servers'][$i]['nopassword'] = false;
 $cfg['Servers'][$i]['AllowNoPassword'] = false;

将两个false改为true,同时设置,

$cfg['Servers'][$i]['password'] = '';

这样设置配置文件后phpmyadmin 就会允许以空密码方式登录mysql数据库了。