首页 后端开发 php教程 LAMP环境如何搭建?LAMP环境搭建的详细过程

LAMP环境如何搭建?LAMP环境搭建的详细过程

Aug 07, 2018 am 09:45 AM
apache centos linux mysql php

这篇文章给大家介绍的内容是关于LAMP环境搭建的详细过程,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

最开始最小化安装好CentOS 7之后,直接输入 ifconfig 命令,提示 "ifconfig command not found" ,说明最小化安装没有安装相关软件,我们可以用 ip addr 代替 ifconfig 来查看网卡详情,或者我们可以通过 yum install net-tools 来安装回 ifconfig 命令,在安装过程中输入两次y,即可完成安装。

一、Apache

yum install httpd //安装Apache

Total download size: 3.0 M
Installed size: 10 M
Is this ok [y/d/N]:  //输入y,确认安装
登录后复制
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
 Userid     : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
 Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 Package    : centos-release-7-5.1804.el7.centos.x86_64 (@anaconda)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Is this ok [y/N]:  //验证GPG密钥是否正确,输入y
登录后复制
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : apr-1.4.8-3.el7_4.1.x86_64                                                            1/5 
  Installing : apr-util-1.5.2-6.el7.x86_64                                                           2/5 
  Installing : httpd-tools-2.4.6-80.el7.centos.1.x86_64                                              3/5 
  Installing : mailcap-2.1.41-2.el7.noarch                                                           4/5 
  Installing : httpd-2.4.6-80.el7.centos.1.x86_64                                                    5/5 
  Verifying  : mailcap-2.1.41-2.el7.noarch                                                           1/5 
  Verifying  : httpd-tools-2.4.6-80.el7.centos.1.x86_64                                              2/5 
  Verifying  : apr-util-1.5.2-6.el7.x86_64                                                           3/5 
  Verifying  : apr-1.4.8-3.el7_4.1.x86_64                                                            4/5 
  Verifying  : httpd-2.4.6-80.el7.centos.1.x86_64                                                    5/5 

Installed:
  httpd.x86_64 0:2.4.6-80.el7.centos.1                                                                   

Dependency Installed:
  apr.x86_64 0:1.4.8-3.el7_4.1  apr-util.x86_64 0:1.5.2-6.el7 httpd-tools.x86_64 0:2.4.6-80.el7.centos.1
  mailcap.noarch 0:2.1.41-2.el7

Complete!
登录后复制

开启Apache服务,并设置系统启动时服务自动启动:
systemctl start httpd.service
systemctl enable httpd.service  

为了能够从外部访问Web服务器,必须在防火墙中打开HTTP(80)和HTTPS(443)端口。CentOS上的默认防火墙是firewalld,可以使用firewalld-cmd命令进行配置。
firewall-cmd --permanent --zone = public --add-service = http
firewall-cmd --permanent --zone = public --add-service = https
firewall-cmd --reload  //重启firewalld

检测Apache服务是否打开:
systemctl status httpd.service

● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Mon 2018-08-06 20:14:21 CST; 9s ago
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 1498 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
   CGroup: /system.slice/httpd.service
           ├─1498 /usr/sbin/httpd -DFOREGROUND
           ├─1499 /usr/sbin/httpd -DFOREGROUND
           ├─1500 /usr/sbin/httpd -DFOREGROUND
           ├─1501 /usr/sbin/httpd -DFOREGROUND
           ├─1502 /usr/sbin/httpd -DFOREGROUND
           └─1503 /usr/sbin/httpd -DFOREGROUND

Aug 06 20:14:21 localhost systemd[1]: Starting The Apache HTTP Server...
Aug 06 20:14:21 localhost httpd[1498]: AH00558: httpd: Could not reliably determine the server's f...sage
Aug 06 20:14:21 localhost systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
登录后复制

再用浏览器输入服务器的IP地址:

2779468906-5b683cd43f4a9_articlex.png

看到如图所示界面表示安装成功。

二、MySQL/MariaDB

MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可。

开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜在风险,因此社区采用分支的方式来避开这个风险。

MariaDB的目的是完全兼容MySQL,包括API和命令行,是目前最受关注的MySQL数据库衍生版,也被视为开源数据库MySQL的替代品。

这里我们用MariaDB代替MySQL,MySQL安装及操作方法大体类似。
安装时,把mariadb换成mysql;
启动、停止服务、查看状态,把mariadb.service换成mysql.service。

yum -y install mariadb-server mariadb  //安装MariaDB

Installed:
  mariadb.x86_64 1:5.5.56-2.el7                   mariadb-server.x86_64 1:5.5.56-2.el7                  

Dependency Installed:
  perl.x86_64 4:5.16.3-292.el7                        perl-Carp.noarch 0:1.26-244.el7                   
  perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7        perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7       
  perl-DBD-MySQL.x86_64 0:4.023-6.el7                 perl-DBI.x86_64 0:1.627-4.el7                     
  perl-Data-Dumper.x86_64 0:2.145-3.el7               perl-Encode.x86_64 0:2.51-7.el7                   
  perl-Exporter.noarch 0:5.68-3.el7                   perl-File-Path.noarch 0:2.09-2.el7                
  perl-File-Temp.noarch 0:0.23.01-3.el7               perl-Filter.x86_64 0:1.49-3.el7                   
  perl-Getopt-Long.noarch 0:2.40-3.el7                perl-HTTP-Tiny.noarch 0:0.033-3.el7               
  perl-IO-Compress.noarch 0:2.061-2.el7               perl-Net-Daemon.noarch 0:0.48-5.el7               
  perl-PathTools.x86_64 0:3.40-5.el7                  perl-PlRPC.noarch 0:0.2020-14.el7                 
  perl-Pod-Escapes.noarch 1:1.04-292.el7              perl-Pod-Perldoc.noarch 0:3.20-4.el7              
  perl-Pod-Simple.noarch 1:3.28-4.el7                 perl-Pod-Usage.noarch 0:1.63-3.el7                
  perl-Scalar-List-Utils.x86_64 0:1.27-248.el7        perl-Socket.x86_64 0:2.010-4.el7                  
  perl-Storable.x86_64 0:2.45-3.el7                   perl-Text-ParseWords.noarch 0:3.29-4.el7          
  perl-Time-HiRes.x86_64 4:1.9725-3.el7               perl-Time-Local.noarch 0:1.2300-2.el7             
  perl-constant.noarch 0:1.27-2.el7                   perl-libs.x86_64 4:5.16.3-292.el7                 
  perl-macros.x86_64 4:5.16.3-292.el7                 perl-parent.noarch 1:0.225-244.el7                
  perl-podlators.noarch 0:2.5.1-3.el7                 perl-threads.x86_64 0:1.87-4.el7                  
  perl-threads-shared.x86_64 0:1.43-6.el7            

Complete!
登录后复制

开启MariaDB服务,并设置系统启动时服务自动启动:
systemctl start mariadb.service
systemctl enable mariadb.service

设置MySQL root帐户的密码:
mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):  //输入当前root用户密码,直接回车

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] 
New password:   //输入密码
Re-enter new password:   //确认密码
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n]   //删除匿名用户,回车
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n]   //不允许root用户远程登录,回车
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n]   //删除测试数据库并访问它,回车
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

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!
登录后复制

三、PHP

yum install php  //安装php

Total download size: 4.7 M
Installed size: 17 M
Is this ok [y/d/N]:   //允许安装,输入y
Downloading packages:
(1/4): libzip-0.10.1-8.el7.x86_64.rpm                                             |  48 kB  00:00:00     
(2/4): php-5.4.16-45.el7.x86_64.rpm                                               | 1.4 MB  00:00:01     
(3/4): php-common-5.4.16-45.el7.x86_64.rpm                                        | 565 kB  00:00:01     
(4/4): php-cli-5.4.16-45.el7.x86_64.rpm                                           | 2.7 MB  00:00:02     
---------------------------------------------------------------------------------------------------------
Total                                                                    2.1 MB/s | 4.7 MB  00:00:02     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : libzip-0.10.1-8.el7.x86_64                                                            1/4 
  Installing : php-common-5.4.16-45.el7.x86_64                                                       2/4 
  Installing : php-cli-5.4.16-45.el7.x86_64                                                          3/4 
  Installing : php-5.4.16-45.el7.x86_64                                                              4/4 
  Verifying  : php-5.4.16-45.el7.x86_64                                                              1/4 
  Verifying  : php-cli-5.4.16-45.el7.x86_64                                                          2/4 
  Verifying  : libzip-0.10.1-8.el7.x86_64                                                            3/4 
  Verifying  : php-common-5.4.16-45.el7.x86_64                                                       4/4 

Installed:
  php.x86_64 0:5.4.16-45.el7                                                                             

Dependency Installed:
  libzip.x86_64 0:0.10.1-8.el7    php-cli.x86_64 0:5.4.16-45.el7    php-common.x86_64 0:5.4.16-45.el7   

Complete!
登录后复制

为了使数据库和php关联,我们还需要安装php-mysql:
yum install php-mysql  //安装过程输入y,即可安装完成

systemctl restart httpd.service  //安装好php后,要重启Apache服务

测试php有没有安装好:
vi /var/www/html/index.php  //新建一个php文件,填入下面的内容

<?php
phpinfo();
?>
登录后复制

在之前URL后加上/info.php,看到以下界面,就说明安装成功了。

4124821225-5b68475931513_articlex.png

相关文章推荐:

Nginx配置文件nginx.conf的操作步骤

Linux系统下修改phpstudy集成环境中的MySQL端口号的步骤

以上是LAMP环境如何搭建?LAMP环境搭建的详细过程的详细内容。更多信息请关注PHP中文网其他相关文章!

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

热门话题

Java教程
1659
14
CakePHP 教程
1415
52
Laravel 教程
1310
25
PHP教程
1258
29
C# 教程
1232
24
在MySQL中解释外键的目的。 在MySQL中解释外键的目的。 Apr 25, 2025 am 12:17 AM

在MySQL中,外键的作用是建立表与表之间的关系,确保数据的一致性和完整性。外键通过引用完整性检查和级联操作维护数据的有效性,使用时需注意性能优化和避免常见错误。

比较和对比Mysql和Mariadb。 比较和对比Mysql和Mariadb。 Apr 26, 2025 am 12:08 AM

MySQL和MariaDB的主要区别在于性能、功能和许可证:1.MySQL由Oracle开发,MariaDB是其分支。2.MariaDB在高负载环境中性能可能更好。3.MariaDB提供了更多的存储引擎和功能。4.MySQL采用双重许可证,MariaDB完全开源。选择时应考虑现有基础设施、性能需求、功能需求和许可证成本。

SQL与MySQL:澄清两者之间的关系 SQL与MySQL:澄清两者之间的关系 Apr 24, 2025 am 12:02 AM

SQL是一种用于管理关系数据库的标准语言,而MySQL是一个使用SQL的数据库管理系统。SQL定义了与数据库交互的方式,包括CRUD操作,而MySQL实现了SQL标准并提供了额外的功能,如存储过程和触发器。

nginx和apache:了解关键差异 nginx和apache:了解关键差异 Apr 26, 2025 am 12:01 AM

NGINX和Apache各有优劣,选择应基于具体需求。1.NGINX适合高并发场景,因其异步非阻塞架构。2.Apache适用于需要复杂配置的低并发场景,因其模块化设计。

使用Apache:构建和托管网站 使用Apache:构建和托管网站 Apr 25, 2025 am 12:07 AM

Apache是一种开源Web服务器软件,广泛用于网站托管。安装步骤:1.在Ubuntu上使用命令行安装;2.配置文件位于/etc/apache2/apache2.conf或/etc/httpd/conf/httpd.conf。通过模块扩展,Apache支持静态和动态内容托管,优化性能和安全性。

MacOS与Linux:探索差异和相似之处 MacOS与Linux:探索差异和相似之处 Apr 25, 2025 am 12:03 AM

Macosandlinuxbothofferuniquerenths:Macosprovidesa-frignlylexperienceWithExcelenthardArdWareIntegration,而Lilinuxexcelsinflexibilitionallibility andCommunitysupport.macos,evartednebyBybyBybyBybyByapple,issone bybyapple,seknoybyapple

说明如何使用会话进行用户身份验证。 说明如何使用会话进行用户身份验证。 Apr 26, 2025 am 12:04 AM

会话通过服务器端的状态管理机制实现用户认证。1)会话创建并生成唯一ID,2)ID通过cookies传递,3)服务器存储并通过ID访问会话数据,4)实现用户认证和状态管理,提升应用安全性和用户体验。

如果session_start()被多次调用会发生什么? 如果session_start()被多次调用会发生什么? Apr 25, 2025 am 12:06 AM

多次调用session_start()会导致警告信息和可能的数据覆盖。1)PHP会发出警告,提示session已启动。2)可能导致session数据意外覆盖。3)使用session_status()检查session状态,避免重复调用。

See all articles