广告
返回顶部
首页 > 资讯 > 操作系统 >Linux下如何搭建LAMP
  • 809
分享到

Linux下如何搭建LAMP

2023-06-28 01:06:41 809人浏览 薄情痞子
摘要

这篇文章主要介绍了linux下如何搭建LAMP,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。LAMP(Linux-Apache-MySQL-PHP)网站架构是目前国际流行的W

这篇文章主要介绍了linux下如何搭建LAMP,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。

LAMP(Linux-Apache-MySQL-PHP)网站架构是目前国际流行的WEB框架,该框架包括:Linux操作系统,Apache网络服务器Mysql数据库,Perl、php或者python编程语言,所有组成产品均是开源软件,是国际上成熟的架构框架,很多流行的商业应用都是采取这个架构

Linux下如何搭建LAMP

准备工作

系统环境:Centos 6.8 x86_64

[root@localhost ~]# uname -aLinux localhost.localdomain 2.6.32-642.el6.x86_64 #1 SMP Tue May 10 17:27:01 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux[root@localhost ~]# cat /etc/redhat-releaseCentOS release 6.8 (Final)[root@localhost ~]#

LAMP相关包是否安装: 默认Httpd已经安装,在这里我们说明下:本次实验我们采用的是yum的方式来进行安装,httpd就是Apache软件在RPM中的软件包名

[root@localhost ~]# rpm -qa httpdhttpd-2.2.15-53.el6.centos.x86_64[root@localhost ~]# rpm -qa mysql*[root@localhost ~]# rpm -qa php*[root@localhost ~]#

L-A-M-P 安装

LAMP的安装其实非常简单,一条命令搞定。个人认为对于初学着没有必要搞那么多这个插件,那个插件;到了深入了解了LAMP后在根据自己实际的需求来进行模块的安装,由易道难,循序渐进的学习

yum仓库的检查

[root@localhost ~]# yum repolist                 \\查看yum仓库的情况Loaded plugins: fastestmirror, refresh-packagekit, securityLoading mirror speeds from cached hostfile* base: mirrors.cn99.com* extras: mirrors.cn99.com* updates: mirrors.aliyun.combase                                                               | 3.7 kB     00:00    extras                                                             | 3.4 kB     00:00    updates                                                            | 3.4 kB     00:00    repo id                             repo name                                 statusbase                                CentOS-6 - Base                           6,696extras                              CentOS-6 - Extras                         62updates                             CentOS-6 - Updates                        482repolist: 7,240

我们使用的是centos默认的网络yum仓库,当然如果默认yum仓库比较慢的话,可以使用epel的软件包。

yum安装LAMP

[root@localhost ~]# yum -y install httpd mysql mysql-server mysql-devel php*Loaded plugins: fastestmirror, refresh-packagekit, securitySetting up Install ProcessLoading mirror speeds from cached hostfile* base: mirrors.cn99.com* extras: mirrors.cn99.com* updates: mirrors.aliyun.comResolving Dependencies--> Running transaction check---> Package httpd.x86_64 0:2.2.15-53.el6.centos will be updated---> Package httpd.x86_64 0:2.2.15-54.el6.centos will be an update--> Processing Dependency: httpd-tools = 2.2.15-54.el6.centos for package: httpd-2.2.15-54.el6.centos.x86_64---> Package mysql.x86_64 0:5.1.73-7.el6 will be installed..........................Installed: mysql.x86_64 0:5.1.73-7.el6    mysql-devel.x86_64 0:5.1.73-7.el6    mysql-server.x86_64 0:5.1.73-7.el6     php.x86_64 0:5.3.3-48.el6_8    php-bcmath.x86_64 0:5.3.3-48.el6_8   php-cli.x86_64 0:5.3.3-48.el6_8        .........Updated: httpd.x86_64 0:2.2.15-54.el6.centos                                                                                  Dependency Updated: httpd-tools.x86_64 0:2.2.15-54.el6.centos  net-snmp-libs.x86_64 1:5.5-57.el6_8.1  openssl.x86_64 0:1.0.1e-48.el6_8.1Complete!

我们yum命令安装httpd ,安装mysql mysql-server 和mysql-devel开发包,在php的安装包上面我们选择了php* 的命令匹配搜有php相关的包。注意,注意的操作是为了让入门童鞋们先了解LAMP的方案,在深入了解后,还是要跟进实际的情况安装搜需要的包。

LAMP初始化

安装完成LAMP后,我们需要对LAMP进行初始化,其实也就是启动服务,开机自起和必要的配置。

Apache的初始化

[root@localhost ~]# service httpd start           \\启动httpd服务;注意httpd和apache的关系Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName                                                          [  OK  ][root@localhost ~]# chkconfig httpd on             \\设置httpd开启自器

mysql的初始化

[root@localhost ~]# service mysqld start           \\开启mysql服务,会提示需要初始化,很详细Initializing MySQL database:  Installing MySQL system tables...OKFilling help tables...OKTo start mysqld at boot time you have to copysupport-files/mysql.server to the right place for your systemPLEASE REMEMBER TO SET A PASSWord FOR THE MySQL root USER !To do so, start the server, then issue the following commands:/usr/bin/mysqladmin -u root password 'new-password'/usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'Alternatively you can run:/usr/bin/mysql_secure_installationwhich will also give you the option of removing the testdatabases and anonymous user created by default.  This isstrongly recommended for production servers.See the manual for more instructions.You can start the MySQL daemon with:cd /usr ; /usr/bin/mysqld_safe &You can test the MySQL daemon with mysql-test-run.plcd /usr/mysql-test ; perl mysql-test-run.plPlease report any problems with the /usr/bin/mysqlbug script!                                                          [  OK  ]Starting mysqld:                                           [  OK  ][root@localhost ~]# chkconfig mysqld on                \\设置mysql开机自启动[root@localhost ~]# mysqladmin -u root password linuxprobe.com                           \\初始化mysql,在这里需要设置mysql的root的密码;命令:mysqladmin -u 用户 password 密码[root@localhost ~]# mysql -u root -p                    \\登录mysql查看是否能够登录        Enter password:Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 3Server version: 5.1.73 Source distributionCopyright (c) 2000, 2013, oracle and/or its affiliates. All rights reserved.Oracle is a reGIStered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>                                             \\ok登录成功

注意:在yum安装lamp的时候,其实php只是apache的一个集成的组件,不需要添加模块的应用,只要在配置文件中启用就可以了。

环境简单的测试

查看经常mysql和httpd是否运行:

[root@localhost ~]# ps -aux |grep httpd               \\查看httpd的进程Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQroot      2930  0.0  2.9 487660 14664 ?        Ss   10:46   0:00 /usr/sbin/httpdapache    2933  0.0  1.9 487660  9400 ?        S    10:46   0:00 /usr/sbin/httpdapache    2934  0.0  1.8 487660  9112 ?        S    10:46   0:00 /usr/sbin/httpdapache    2935  0.0  1.9 487660  9400 ?        S    10:46   0:00 /usr/sbin/httpdapache    2936  0.0  1.9 487660  9392 ?        S    10:46   0:00 /usr/sbin/httpdapache    2937  0.0  1.8 487660  9116 ?        S    10:46   0:00 /usr/sbin/httpdapache    2938  0.0  1.8 487660  9136 ?        S    10:46   0:00 /usr/sbin/httpdapache    2939  0.0  1.8 487660  9112 ?        S    10:46   0:00 /usr/sbin/httpdapache    2940  0.0  2.3 487844 11840 ?        S    10:46   0:00 /usr/sbin/httpdroot     10163  0.0  0.1 103316   868 pts/3    S+   12:23   0:00 grep httpd[root@localhost ~]# ps -aux |grep mysql               \\查看mysql的相关进程Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQroot      3035  0.0  0.2 108216  1452 pts/1    S    10:47   0:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --Socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysqlmysql     3137  0.0  4.3 367512 21444 pts/1    Sl   10:47   0:02 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sockroot     10165  0.0  0.1 103316   868 pts/3    S+   12:23   0:00 grep mysql[root@localhost ~]# netstat -tanulp |grep 80      \\查看httpd 的端口对外监听tcp        0      0 192.168.1.108:50878         63.80.4.177:80              ESTABLISHED 2629/clock-applet  tcp        0      0 :::80                       :::*                        LISTEN      2930/httpd          [root@localhost ~]# netstat -tanulp |grep 3306     \\查看mysql的端口对外监听tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      3137/mysqld

防火墙的相关设置

[root@localhost ~]# iptables -L                   \\查看iptables的规则Chain INPUT (policy ACCEPT)target     prot opt source               destination        ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHEDACCEPT     icmp --  anywhere             anywhere            ACCEPT     all  --  anywhere             anywhere            ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:sshREJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibitedChain FORWARD (policy ACCEPT)target     prot opt source               destination        REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibitedChain OUTPUT (policy ACCEPT)target     prot opt source               destination    [root@localhost ~]# iptables -I INPUT 1 -p tcp --dport 80 -j ACCEPT                                        \\添加iptables INPUT的链的第一条规则允许tcp协议的80端口                                 \\关于iptables 的更多设置,请参考《linux就该这样学》相关内容[root@localhost ~]# service iptables save        \\将我们的添加的规则保存在配置文件iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ][root@localhost ~]# iptables -L                         \\查看保存情况Chain INPUT (policy ACCEPT)target     prot opt source               destination        ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:httpACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHEDACCEPT     icmp --  anywhere             anywhere            ACCEPT     all  --  anywhere             anywhere            ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:sshREJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibitedChain FORWARD (policy ACCEPT)target     prot opt source               destination        REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibitedChain OUTPUT (policy ACCEPT)target     prot opt source               destination

测试httpd的静态文件

添加一个测试的静态index.html页面,或者使用默认的页面进行测试。关于添加网站页面的更多问题,请参考《linux就该这样学》的相关内容

[root@localhost ~]# echo "hello word" > /var/www/html/index.html

测试用ie浏览器测试静态页面:

Linux下如何搭建LAMP
新手必看,老鸟绕道–LAMP简易安装新手必看,老鸟绕道–LAMP简易安装

ok,测试成功。

配置文件

[root@localhost ~]# ls /etc/httpd/              \\配置文件目录,相关配置模块conf/    conf.d/  logs/    modules/ run/    [root@localhost ~]# vi /etc/httpd/conf/httpd.conf  magic      [root@localhost ~]# vi /etc/httpd/conf/httpd.conf     \\主配文件[root@localhost ~]# wc -l /etc/httpd/conf/httpd.conf    1009 /etc/httpd/conf/httpd.conf                             \\ 主配文件共有1009行,其中有好多都是注释的.养成好习惯,备份默认配置文件[root@localhost ~]# tail /etc/httpd/conf/httpd.conf      \\更多配置建议参考《linux就该这样学》相关内容# The first VirtualHost section is used for requests without a known# server name.##                                          \\配置文件中添加虚拟主机的语句#    ServerAdmin webmaster@dummy-host.example.com#    DocumentRoot /www/docs/dummy-host.example.com#    ServerName dummy-host.example.com#    ErrorLog logs/dummy-host.example.com-error_log#    CustomLog logs/dummy-host.example.com-access_log common#

高级环境的测试

LAMP是一个稳定的动态的网站架构方案,在这里我们需要添加php的支持,测试动态网站。

启用对php的支持

[root@localhost ~]# vi /etc/httpd/conf/httpd.conf[root@localhost ~]# cat /etc/httpd/conf/httpd.conf |grep  DirectoryIndex                                                     \\在配置文件402行添加对php页面的支持# DirectoryIndex: sets the file that Apache will serve if a directory

添加php测试页面,测试

[root@localhost ~]# vi /var/www/html/index.php    [root@localhost ~]# cat /var/www/html/index.php    \\添加php信息的测试页面[root@localhost ~]# vi /var/www/html/test.php[root@localhost ~]# cat /var/www/html/test.php      \\添加php页面测试testthis php test

测试: Linux下如何搭建LAMP

Linux下如何搭建LAMP
新手必看,老鸟绕道–LAMP简易安装新手必看,老鸟绕道–LAMP简易安装

注意: 动态网页搭建动族论坛 过程略,大家自己测试 Apache:httpd(服务名) 80 (端口) Mysql: mysqld(服务名) 3306(端口,默认只对本地监听) php:在apache 中集成,只需添加启用php默认文档即可 lamp的日志等功能,建议查看相关文档 建议安装lamp为了让入门童鞋更加容易了解lamp,生产环境要根据实际情况安装不通的组件。

LAMP,so easy!!!

感谢你能够认真阅读完这篇文章,希望小编分享的“Linux下如何搭建LAMP”这篇文章对大家有帮助,同时也希望大家多多支持编程网,关注编程网操作系统频道,更多相关知识等着你来学习!

--结束END--

本文标题: Linux下如何搭建LAMP

本文链接: https://www.lsjlt.com/news/315539.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Linux下如何搭建LAMP
    这篇文章主要介绍了Linux下如何搭建LAMP,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。LAMP(Linux-Apache-MySQL-PHP)网站架构是目前国际流行的W...
    99+
    2023-06-28
  • Linux下如何搭建LAMP PHP开发环境
    本篇内容主要讲解“Linux下如何搭建LAMP PHP开发环境”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Linux下如何搭建LAMP PHP开发环境”吧!我的OS是ubuntu 9.10,得...
    99+
    2023-06-13
  • LAMP下如何搭建WordPress博客
    这篇文章主要介绍LAMP下如何搭建WordPress博客,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!WordPress是一种使用PHP语言开发的博客平台,用户可以在支持PHP和MySQL 数据库的服务器上架设自己的...
    99+
    2023-06-28
  • centos下安装搭建LAMP+WordPress
    目录 1.安装Apache服务器 2. 安装Mysql(MariaDB)数据库 3.安装PHP 7.4 4.安装WordPress 命令安装Apache yum install httpd -y 启动Apache systemctl e...
    99+
    2023-09-03
    apache mysql linux centos php
  • linux单机LAMP环境搭建
    LAMP单机环境搭建一.系统环境准备。1.系统环境:CentOS_6.5,32位[root@localhost ~]# cat /etc/redhat-release      ...
    99+
    2022-10-18
  • Centos7.2 / Linux的下搭建LAMP环境的搭建和配置虚拟主机
    LAMP环境:LINUX + Apahce的+ MYSQL + PHP的网络服务器环境。(一)。准备工作1.下载并安装CentOS7.2,配置好网络环境,确保centos能上网,可以获取到yum源(阿里云服...
    99+
    2022-10-18
  • Fedora中如何搭建Fedora LAMP
    小编给大家分享一下Fedora中如何搭建Fedora LAMP,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!Fedora LAMP搭建中的LAMP是Linux+A...
    99+
    2023-06-16
  • Linux下如何搭建OpenNebula
    小编给大家分享一下Linux下如何搭建OpenNebula,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!OpenNebula提供一个丰富的功能集,企业可以用来创造...
    99+
    2023-06-27
  • Linux下如何搭建Redis
    这篇文章主要介绍了Linux下如何搭建Redis,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。Redis 是一个高性能的key-value数据库。 redis的出现,很大程度...
    99+
    2023-06-28
  • Linux下如何搭建VPS
    这篇文章主要为大家展示了“Linux下如何搭建VPS”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“Linux下如何搭建VPS”这篇文章吧。VPS技术,指将一台服务器分割成多个虚拟专享服务器的优质...
    99+
    2023-06-28
  • Ubuntu9.10下搭建LAMP服务器详细教程
    这篇文章主要讲解了“Ubuntu9.10下搭建LAMP服务器详细教程”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Ubuntu9.10下搭建LAMP服务器详细教程”吧!undefined  ...
    99+
    2023-06-13
  • Docker下多容器搭建 lamp (httpd+mysql+php+redis)
    Docker下多容器搭建lamp环境 说明搭建拉取所需镜像mysqlmysql创建mysql测试 redisredis创建redis测试 phpphp创建php安装扩展php测...
    99+
    2023-09-29
    docker 容器
  • LAMP 搭建zabbix监控Oracle 数据库 for Linux
    准备环境介绍文档简介想要实现的功能为在zabbix服务器端再增加orabbix插件以此访问oracle数据库进行监控操作。环境介绍CentOS 7 zabbix 2.4.2 。yum介绍因公司电脑无法访问外...
    99+
    2022-10-18
  • LAMP平台下搭建论坛和博客系统
    CentOS6.5系统中构建LAMP平台在LAMP平台下搭建论坛页面使用模板进行发布论坛以及博客系统相对来说方便快捷,部署简单使用discuz发布论坛一,配置数据库1.为论坛页面配置数据库2.配置论坛连接数...
    99+
    2022-10-18
  • Linux下如何搭建FTP服务
    本篇内容介绍了“Linux下如何搭建FTP服务”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!对于用户来说,如何搭建自己的FTP服务是一个基本...
    99+
    2023-06-16
  • linux下jenkins项目如何搭建
    这篇文章给大家分享的是有关linux下jenkins项目如何搭建的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。Jenkins是由java编写的一个开放源码的持续集成(CI)工具,其主要目的就是持续、自动的构建/测...
    99+
    2023-06-28
  • linux 下如何搭建php环境
    这篇文章主要介绍了linux 下如何搭建php环境,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。linux下搭建php环境的方法:1、通过“sudo apt-get inst...
    99+
    2023-06-22
  • Lamp环境中如何搭建Mysql与PHP环境的搭建
    今天就跟大家聊聊有关  Lamp环境中如何搭建Mysql与PHP环境的搭建,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。 Lam...
    99+
    2022-10-18
  • Ubuntu中如何搭建LAMP开发环境
    本篇内容介绍了“Ubuntu中如何搭建LAMP开发环境”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!1.更新sudo apt-get upd...
    99+
    2023-07-04
  • Linux下如何搭建Git服务器
    这篇文章将为大家详细讲解有关Linux下如何搭建Git服务器,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。Git是一款免费、开源的分布式版本控制系统。众所周知的Github便是基于Git的开源代码库以及版...
    99+
    2023-06-28
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作