CentOS 7 一步一步搭建LAMP
admin
2023-05-18 21:22:47
0

一、准备环境

1、系统版本

[root@Webserver01 ~]# cat /proc/version

Linux version 3.10.0-514.16.1.el7.x86_64

2、关防火墙

[root@Webserver01 ~]# systemctl disable firewalld

3、准备yum源

[root@Webserver01 ~]# rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm

[root@Webserver01 ~]# rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm

4、安装基础工具

[root@Webserver01 ~]# yum install -y net-tools vim lrzsz tree screen lsof tcpdump nc nmap

5、关掉SELINUX

[root@Webserver01 ~]# vim /etc/sysconfig/selinux 
SELINUX=disabled

6、更新并重启

[root@Webserver01 ~]# yum update -y && reboot

二、开始安装LAMP组建


LAMP至少需要以下组建:

  • httpd (提供 Apache 主程序)

  • mysql (MySQL 客戶端程序)

  • mysql-server (MySQL 服务器程序)

  • php (PHP 主程序含给 apache 使用的模块)

  • php-devel (PHP 的开发工具,这个与PHP 外挂的加速软件有关)

  • php-mysql (提供给PHP 程序读取 MySQL 资料库的模块)

可以用以下命令一次安装;

[root@Webserver01 ~]# yum install httpd mysql mysql-server php php-mysql

为了看的更详细,我们一个一个安装

1、利用yum命令安装Apache

[root@Webserver01 ~]# yum -y install httpd

启动httpd并且设置为开机启动

[root@Webserver01 ~]# systemctl start httpd.service
[root@Webserver01 ~]# systemctl enable httpd.service

输入网址,查看测试页


CentOS 7 一步一步搭建LAMP


2、安装Mariadb

利用yum命令进行安装,并且配置开机启动同样还是利用yum命令进行安装,并且配置开机启动

[root@Webserver01 ~]# yum -y install mariadb-server mariadb
[root@Webserver01 ~]# systemctl start mariadb.service
[root@Webserver01 ~]# systemctl enable mariadb.service

配置root密码

[root@Webserver01 ~]# mysql_secure_installation
安装过程中会有几个选项,大家根据自己的需要进行配置就好了
Enter current password for root (enter for none):(输入原始root密码,若无enter)
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation. 
Set root password? [Y/n] (是否设置root密码)
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!
Remove anonymous users? [Y/n] (是否移除匿名用户)
 ... Success!
Disallow root login remotely? [Y/n] (是否禁止远程root登陆)
 ... skipping.
Remove test database and access to it? [Y/n] (是否删除测试数据库)
Reload privilege tables now? [Y/n] (重新载入)
 ... Success!
Cleaning up...
All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!

登录数据库测试一下

[root@Webserver01 ~]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 5.5.52-MariaDB MariaDB Server
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
MariaDB [(none)]> exit
Bye

3、安装PHP

[root@Webserver01 ~]# yum -y install php

安装所需组件

[root@Webserver01 ~]# yum -y install php-mysql php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel

启动服务并设置开机自动启动

[root@Webserver01 ~]# systemctl start httpd.service
[root@Webserver01 ~]# systemctl enable httpd.service

查看80端口和3306端口是否处于监听状态:

[root@Webserver01 ~]# netstat -ntlp


测试php是否正常工作

编辑/etc/httpd/conf/httpd.conf文件,在DirectoryIndex后面填写index.php,定义默认主页为index.php

[root@Webserver01 ~]# vim /etc/httpd/conf/httpd.conf

CentOS 7 一步一步搭建LAMP

重载httpd配置文件

[root@Webserver01 ~]# systemctl reload httpd.service
[root@Webserver01 ~]# vim /var/www/html/index.php

制作默认主页/var/www/html/index.php,编写如下内容

This is new Web !

       

重启httpd服务    

[root@Webserver01 ~]# systemctl restart httpd.service

好了,该验证最后是否成功了

打开网址 http://x.x.x.x/info.php 进行查看

CentOS 7 一步一步搭建LAMP



看到这个页面,我们就可以收工了,LAMP环境搭建结束!



相关内容

热门资讯

AI赋能中医,市七医院“中医药... 当AI开始“望闻问切”,当中医迈入智能新时代。2026年5月16日,在2026结合医学·上海论坛上,...
北大教授乔晓春:AI时代知识不... 5月17日,2026搜狐科技年度论坛在京盛大开幕。来自科学界、学术界和产业界的近三十位嘉宾共襄盛会,...
中国新提3项旅游国际标准,将开... 国际标准化组织旅游及相关服务技术委员会2026年年会日前在浙江杭州举行,这是该组织年会首次落地中国。...
让精准营养“有数可依”,数据驱... 5月14日,由人民日报健康客户端主办、如新(中国)公益支持的“主动健康·创新路径——数据驱动精准营养...
后车司机突发疾病车辆失控,前车... 5月14日下午江苏泰州靖江街头一幕齐心协力的紧急救援看得人惊心动魄在东进路与兴业路红绿灯路口一名司机...
2000万粉丝博主发声:撑不住... 5月14日、15日两天,辽宁本地知名搞笑博主“大连老湿王博文”,分别在微信公众号和小红书上发表长文,...
零食包装也变黑白,死亡氛围在日... 作者 | 荣智慧 编辑 | 向现5月12日,日本“国民零食”巨头卡乐比宣布,因“石脑油”供应短缺,旗...
欧洲首个可复用航天器整装待发,... (来源:科普中国) 转自:科普中国 据阿根廷布宜诺斯艾利斯经济新闻网 5 月 10 日报道,欧洲即将...
奥立电子取得密封型线束专利,降... 国家知识产权局信息显示,东莞奥立电子有限公司取得一项名为“密封型线束”的专利,授权公告号CN2242...
嘉陵江重庆段发生划桨板人员落水... 记者从重庆市相关部门了解到,16日晚,嘉陵江重庆中心城区段发生一起划桨板人员落水事件,有7人落水。事...