LAMP环境和软件版本
名称 | 版本号 | 查询命令 |
---|---|---|
linux系统 | CentOS release 6.8 (Final) | cat /etc/redhat-release |
Apache | httpd-2.2.15-69.el6.centos.x86_64 | rpm -qa | grep httpd |
mysql | mysql-server-5.1.73-8.el6_8.x86_64 | rpm -qa | grep mysql |
php | php-5.3.3-49.el6.x86_64 | rpm -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