Linux环境下搭建LAMP
安装Apache
安装Apache
1
yum install httpd -y
启动服务
1
service httpd restart
Apache服务开机启动
1
chkconfig httpd on
Apache的配置文件
1
/etc/httpd/conf/httpd.conf
网站根目录
1
/var/www/html/
安装mysql
安装mysql
1
2
3wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum install mysql-server启动mysql
1
service mysqld restart
首次登录mysql
1
mysql
设置密码
1
2
3
4show databases;
use mysql;
select user,password from user;
update user set password=password('root') where user='root';mysql刷新权限命令
1
flush privileges;
再次登录mysql
1
2mysql -u root(用户名) -p
root(密码)
安装php
安装php和连接php、mysql工具
1
yum install php php-mysql
启动Apache和mysql
1
2service httpd restart
service mysqld restart测试php和mysql是否连接成功
1
2
3
4
5
6$link = mysql_connect('localhost','root','root');
if($link){
echo "successful";
}else{
echo "fail";
}
常见问题
报错Cannot find a valid baseurl for repo: base/7/86-64
解决方案:
1
2
3cd /etc/sysconfig/network-scriptsls
vim ifcfg-ens33
ONBOOT=yes //修改,保存退出即可