Linux安装Apache,mysql和php,(LAMP环境的搭建与部署)
yum list installed | grep php或者 rpm -qa |grep httpd为空发现并没有。
Apachea安装
1.首先检查是否已经安装了apache
yum list installed | grep php 或者 rpm -qa |grep httpd
为空发现并没有
2.yum安装apache
yum -y install httpd
发现报错
解决办法
- 检查网络连接
:确保你的系统可以连接到互联网,尝试ping一个外部网站,如:
ping google.com
- 检查DNS配置
:确保你的系统有正确的DNS服务器配置。你可以编辑/etc/resolv.conf文件,添加或修改DNS服务器,例如使用Google的公共DNS服务器:
sudo nano /etc/resolv.conf
添加以下内容:
nameserver 8.8.8.8
nameserver 8.8.4.4
3.打开并编辑/etc/yum.repos.d/CentOS-Base.repo文件:
文本替换成下面的
[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
baseurl=http://vault.centos.org/7.9.2009/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
baseurl=http://vault.centos.org/7.9.2009/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
baseurl=http://vault.centos.org/7.9.2009/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7[centosplus]
name=CentOS-$releasever - Plus
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
baseurl=http://vault.centos.org/7.9.2009/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
这样就可以成功开始安装了
一直选择y即可
4.设置apache为开机自启动
systemctl enable httpd
[root@localhost zheng]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
启动apache服务器并且查看apache状态
systemctl start httpd
systemctl status httpd
防火墙设置开放访问端口(80端口)
开启http访问端口
firewall-cmd --permanent --zone=public --add-service=http
开启https访问端口
firewall-cmd --permanent --zone=public --add-service=https
防火墙进行重新加载
firewall-cmd --reload
查看端口的信息
netstat -tulp
通过浏览器来访问apache服务器(ip地址)
成功了
安装数据库
yum install mariadb mariadb-server mariadb-libs mariadb-devel
一直yes
启动数据库的服务
systemctl start mariadb
设置数据库服务开机自启动
systemctl enable mariadb
查看mariadb数据库的状态
systemctl status mariadb
修改一下数据库登录密码
mysql_secure_installation
输入后全部yes 就好了中间有一个输入密码
验证数据库是否安装成功,并能进行登录
mysql -u用户名(默认为root) -p
如何输入刚刚修改的密码
成功登入
安装php
安装php
yum -y install php
安装PHP与MySQL数据库环境交互的组件
yum -y install php-mysql
安装PHP相关的组件,以便适配不同的WEB项目应用程序
yum -y install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel php-bcmath
验证PHP环境
进入程序源文件的存放地(/var/www/html)
cd /var/www/html
编写一个php页面
vi info.php
内容:
<?php
phpinfo();
?>
通过浏览器来进行访问,一开始没办法打开出来,通过重启服务器就可以了
systemctl restart httpd

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐
所有评论(0)