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