apache 默认情况下仅支持html页面,不支持php的页面,php会以模块的方式存在于apache中,安装此模快即可访问php页面。apache通过php调用mysql中的数据。

 

安装lamp:
[root@localhost ~]# mount /dev/cdrom /mnt
mount: block device /dev/cdrom is write-protected, mounting read-only
[root@localhost ~]# yum install httpd php php-mysql mysql mysql-server –y
 
启动http和mysql
[root@localhost ~]# /etc/init.d/httpd start
Starting httpd:                                             [ OK ]
[root@localhost ~]# /etc/init.d/mysqld start
添加数据库:
[root@localhost ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.77 Source distribution
 
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
 
mysql> show databases;
+--------------------+
| Database            |
+--------------------+
| information_schema |
| mysql               |
| test                |
+--------------------+
3 rows in set (0.00 sec)
 
mysql> use test
Database changed
mysql> create table wu (name char(10),tel char(20),address char(100));
Query OK, 0 rows affected (0.01 sec)
 
mysql> insert into wu values ('xiaobai','13800138000','bj');
Query OK, 1 row affected (0.00 sec)
 
mysql>
 
将mysql.php放到/var/www/html/中
[root@localhost ~]# cd /var/www/html/
 [root@localhost html]# ls
mysql.php
配置mysql.php
[root@localhost html]# vim mysql.php
 
 

 
重启http服务
[root@localhost html]# /etc/init.d/httpd restart
Stopping httpd:                                             [ OK ]
Starting httpd:                                             [ OK ]
[root@localhost html]#
 
在浏览器中进行测试:
http://192.168.18.167/mysql.php