|
我们通过yum安装
一.安装必备
1
2
3
| 1、yum update 检查一下系统更新
2、yum -y installgcc gcc gcc-c 安装编译环境
3、yum erasehttpd 卸载系统自带的httpd
|
二.安装 Apache
1
| [iyunv@localhost ~]# yum install httpd
|
配置系统让 Apache 随系统启动:
1
| [iyunv@localhost ~]# chkconfig --levels 235 httpd on
|
配置完毕,启动 Apache:
1
| [iyunv@localhost ~]# /etc/init.d/httpdstart
|
配置环境
1
| [iyunv@localhost ~]# vi /etc/httpd/conf/httpd.conf
|
找到#ServerNamewww.example.com:80然后在下面加入如下
1
| ServerName 127.0.0.1:80
|
然后重启apache
1
| /etc/init.d/httpd restart
|
此时apache已经安装好了,访问http://127.0.0.1/就可以看到如下界面(备注:在有图像界面的Linux系统里)
三.安装PHP
1
| [iyunv@localhost ~]# yum install php
|
需要重新启动 Apache 服务:
1
| [iyunv@localhost ~]# /etc/init.d/httpdrestart
|
但是为了测试是否安装成功,你可以新建一个 PHP 页面进行测试,使用 vim 编辑器新建:
1
| [iyunv@localhost ~]# vi/var/www/html/info.php
|
按 “i” 键进行编辑,输入:
1
2
3
| <?php
phpinfo();
?>
|
四.安装Mysql
1
| [iyunv@localhost ~]# yum install mysql mysql-server
|
让 MySQL 能够随系统自动启动:
1
2
| [iyunv@localhost ~]# chkconfig --levels 235 mysqld on
[iyunv@localhost ~]# /etc/init.d/mysqldstart
|
设置MySQL 数据 root 账户的密码:
1
2
3
4
5
6
7
8
9
10
11
12
13
| [iyunv@localhost ~]# mysql_secure_installation
当出现如下提示时候直接按回车:
Enter currentpassword for root
出现如下再次回车:
Set rootpassword? [Y/n]
出现如下提示输入你需要设置的密码,回车后在输入一次确认:
New password:
接下来还会有四个确认,分别是:
Remove anonymoususers? [Y/n]
Disallow rootlogin remotely? [Y/n]
Remove testdatabase and access to it? [Y/n]
Reload privilegetables now? [Y/n]
直接回车即可。
|
重启mysql
1
| /etc/init.d/mysqld restart #重启
|
测试mysql是否安装成功
使用 vim 编辑器新建: 1
| [iyunv@localhost ~]# vi/var/www/html/test.php
|
按 “i” 键进行编辑,输入: 1
2
3
4
5
6
| <?php
$connect=mysql_connect("127.0.0.1","root","你的密码");
if(!$connect) echo "Mysql Connect Error!";
else echo "ok";
mysql_close();
?>
|
然后在浏览器中访问http://127.0.0.1/test.php,我们发现链接失败,我们再次打开之前测试php的例子http://127.0.0.1/info.php
我们会发现,里面没有mysql,而只有’–without-mysql’因为我们是通过yum安装的,所以我们可以通过yum搜索查找
我们会发现php53-mysql.i386 : A module for PHP applications that use MySQLdatabases
而php53-mysql.i386就是我要找到东东。
使用yum安装
1
| #yum install php53-mysql.i386
|
然后重新访问http://127.0.0.1/test.php,链接成功
|
|