CentOS 搭建 LAMP 环境

查看系统环境

CentOS版本为 7.5

一、下载 Apache 

  执行下面命令进行安装

yum install httpd httpd-devel

启动 Apache 服务

systemctl start httpd

在浏览器中输入 localhost,看到如下界面说明 Apache 安装成功

后续操作

1. 查看服务的运行状态

systemctl status httpd

2. 防火墙设置开启80端口

[root@loaclhost-7 ~]# firewall-cmd --permanent --zone=public  --add-service=http
success
[root@loaclhost-7 ~]# firewall-cmd --permanent --zone=public  --add-service=https
success
[root@loaclhost-7 ~]# firewall-cmd --reload
success

3. 确认端口状态为监听

netstat -tulp

4.  查服务器IP

ip addr

 

在浏览器中输入该地址,正常访问

二、安装 Mysql/mariadb

因为现在 Mysql 被 oracle 收购,随时都有可能面临收费的可能性,所以 Mysql 的的创始人Michael Widenius 开发了一款 Mariadb 用来代替 Mysql,Mariadb 完全兼容 Mysql。

因此在这里我们安装 mariadb

yum install mariadb mariadb-server mariadb-libs mariadb-devel

判断是否安装成功

rpm -qa |grep maria

出现图中 的4个,证明 mariadb 数据库安装成功

启动 mariadb

systemctl start mariadb

设置 mariadb 开机启动

systemctl enable mariadb

查看 mariadb 的运行状态

systemctl status mariadb

查看端口状态

netstat -tulp

数据库安全设置

mysql_secure_installation

登陆 mysql 测试

mysql -u root -p

输入刚刚设置的密码

三、安装 PHP

yum -y install php

查看是否安装成功

rpm -ql php

将 mysql 与 php 关联起来

yum install php-mysql

查看是否安装成功

rpm -ql php-mysql

安装常用的 php 插件

yum install -y php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel php-bcmath

测试 php

[root@nmserver-7 ~]# cd  /var/www/html/
[root@nmserver-7 html]# ls
[root@nmserver-7 html]# pwd
/var/www/html
[root@nmserver-7 html]# vi info.php

<?php
        phpinfo();
?>
~                                                                                        
~                                                                                        
~                                                                                        
~                                                                                        
~                                                                                        
~                                                                                        
~                                                                                        
~                                                                            
:wq

重启服务器进行测试

systemctl restart httpd

 看到如下界面证明 LAMP 环境搭建成功

发布了39 篇原创文章 · 获赞 20 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/cong____cong/article/details/87300774