$ sudo apt-get install apache2
$ sudo apt-get install mysql-server-5.5 (root密码随意,如:123456)
$ sudo apt-get install php5
$ sudo apt-get install libapache2-mod-php5 (解决apache识别php页面)
$ sudo apt-get install php5-mysql (解决php连接mysql)
$ sudo ls /etc/php5/conf.d/ (确保该目录下有mysqli.ini、mysql.ini、pdo.ini、pdo_mysql.ini文件,如果在其它路径下拷到该目录下即可)
$ sudo service apache2 restart
验证:
$ sudo vi /var/www/test.php
<?php
phpinfo();
?>
:wq
$ sudo vi /var/www/mysql.php
<?php
$db = mysql_connect("localhost","root","123456") or die("fail");
echo "connect ok!<br>"
?>
:wq
访问http://localhost/test.php http://localhost/mysql.php
时间: 2024-11-06 23:09:13