Linux安装LAMP(Linux+Apache+MySQL+PHP)(centos6)

LAMP环境和软件版本

名称版本号查询命令
linux系统CentOS release 6.8 (Final)cat /etc/redhat-release
Apachehttpd-2.2.15-69.el6.centos.x86_64rpm -qa | grep httpd
mysqlmysql-server-5.1.73-8.el6_8.x86_64rpm -qa | grep mysql
phpphp-5.3.3-49.el6.x86_64rpm -qa | grep php

一、安装Apache

1、查看是否安装过Apache。

rpm -qa | grep httpd

2、有就卸载httpd。

yum remove -y "httpd*"

3、重新安装httpd。

yum install -y httpd

4、查看启动状态。

service httpd	 status

5、启动httpd。

service httpd	 start

6、添加开机启动,设置启动级别,查看启动级别。

chkconfig --add httpd
chkconfig httpd on
chkconfig --list httpd

7、临时关闭防火墙seLinux和临时清除iptables防火墙规则。

setenforce 0	
iptables -F

8、永久关闭selinux 需编辑配置文件/etc/selinux/config,设置SELINUX=disabled,重启系统后生效。

9、设置iptables防火墙开放httpd 监听网络端口,并保存配置。

iptables -I INPUT -p tcp --dport	  80 -j ACCEPT
service iptables save

10、使用浏览器访问http://192.168.1.110/,显示如下界面,说明安装的Apache HTTP服务正常运行。
在这里插入图片描述
11、默认主页index.html位于默认目录/var/www/html/中。若要发布自己的网站内容,替换index.html主页内容即可。例:主页内写入内容 “This is a apache test.” 。使用浏览器访问http://192.168.1.110,则显示如下界面内容。

touch    /var/www/html/index.html
echo     "This is a apache test."     >     /var/www/html/index.html

在这里插入图片描述

二、安装mysql数据库

1、查看是否安装过mysql。

rpm -qa | grep mysql

2、有就卸载mysql。

yum remove -y "mysql*"

3、重新安装mysql-server。

yum install -y mysql-server

4、查看启动状态。

service mysqld status

5、启动mysql。

service mysqld start

6、添加开机启动,设置启动级别,查看启动级别。

chkconfig --add mysqld
chkconfig mysqld on
chkconfig --list mysqld

7、设置mysql数据库root账号密码。

mysqladmin -uroot password ‘yourpassword’

8、root账号登陆mysql。

mysql -uroot -p

9、登陆mysql后设置数据库密码命令。

mysql> SET PASSWORD = PASSWORD('123456')

10、查看数据库。

mysql> show databases

11、退出mysql数据库。

mysql> quit; 

mysql> exit

12、如需远程连接mysql,请设置iptables防火墙开放mysqld监听网络端口,并保存配置。

iptables -I INPUT -p udp --dport	  3306 -j ACCEPT
service iptables save

三、安装PHP

1、查看是否安装过php。

rpm -qa | grep php

2、有就卸载php。

yum remove -y "php*"

3、重新安装php。

yum install -y php

4、创建文件/var/www/html/index.php,写入内容 “This is a php test.” 。使用浏览器访问http://192.168.1.110/index.php,如果输出写入内容,则说明php安装成功,如下图。

touch    /var/www/html/index.php
echo     "This is a php test."     >     /var/www/html/index.php

在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值