LAMP搭建示例
lamp介绍
其实就是由Linux+Apache+Mysql/MariaDB+Php/Perl/Python的一组动态网站或者服务器的开源软件,除Linux外其它各部件本身都是各自独立的程序,但是因为经常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的Web应用程序平台。
- Apache,网页服务器
web服务器工作流程
web服务器的资源分为两种,静态资源和动态资源
静态资源就是指静态内容,客户端从服务器获得的资源的表现形式与原文件相同。可以简单的理解为就是直接存储于文件系统中的资源
动态资源则通常是程序文件,需要在服务器执行之后,将执行的结果返回给客户端
工作过程:当客户端请求是静态资源时,web服务器会直接把静态资源返回个客户端。
:动态资源则通过FastCGI协议与php服务器联系,通过CGI程序的master进程调度worker进程来执行程序以获得客户端请求的动态资源,并将执行的结果通过FastCGI协议返回给httpd服务器,httpd服务器收到php的执行结果后将其封装为http响应报文响应给客户端。在执行程序获取动态资源时若需要获得数据库中的资源时,由Php服务器通过mysql协议与MySQL/MariaDB服务器交互,取之而后返回给httpd,httpd将从php服务器收到的执行结果封装成http响应报文响应给客户端。
cgi与fastcgi
CGI(Common Gateway Interface,通用网关接口),CGI是外部应用程序(CGI程序)与WEB服务器之间的接口标准,是在CGI程序和Web服务器之间传递信息的过程。CGI规范允许Web服务器执行外部程序,并将它们的输出发送给Web浏览器,CGI将web的一组简单的静态超媒体文档变成一个完整的新的交互式媒体。
FastCGI(Fast Common Gateway Interface)是CGI的改良版,CGI是通过启用一个解释器进程来处理每个请求,耗时且耗资源,而FastCGI则是通过master-worker形式来处理每个请求,即启动一个master主进程,然后根据配置启动几个worker进程,当请求进来时,master会从worker进程中选择一个去处理请求,这样就避免了重复的生成和杀死进程带来的频繁cpu上下文切换而导致耗时
lamp平台搭建
环境说明:
系统平台 | IP | 需要安装的服务 |
centos8 redhat8 |
192.168.248.131 | httpd-2.4 mysql-5.7 php php-mysql |
lamp平台软件安装次序: httpd --> mysql --> php
yum源:
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo #epel
yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
sed -i 's|^#baseurl=https://download.fedoraproject.org/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
安装httpd
#安装开发工具包
[root@localhost ~]# yum groups mark install 'Development Tools' #创建apache用户和组
[root@localhost ~]# useradd -r -M -s /sbin/nologin apache #安装依赖包
[root@localhost ~]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make #下载和安装apache,apr和apr-util
[root@localhost ~]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/httpd-2.4.46.tar.gz [root@localhost ~]# wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.7.0.tar.gz [root@localhost ~]# wget http://mirrors.hust.edu.cn/apache//apr/apr-util-1.6.1.tar.gz [root@localhost ~]# tar -xf apr-1.7.0.tar.gz
[root@localhost ~]# tar -xf httpd-2.4.46.tar.gz
[root@localhost ~]# tar -xf apr-util-1.6.1.tar.gz
[root@localhost ~]# ls
apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz httpd-2.4.46.tar.gz
apr-1.7.0 apr-util-1.6.1 httpd-2.4.46 [root@localhost ~]# cd apr-1.7.0
[root@localhost apr-1.7.0]# vim configure
cfgfile="${ofile}T"
trap "$RM \"$cfgfile\"; exit 1" 1 2 15
# $RM "$cfgfile" //将此行加上注释,或者删除此行 [root@localhost apr-1.7.0]# ./configure --prefix=/usr/local/apr
....................................................配置过程
[root@localhost apr-1.7.0]# make && make install
...................................编译安装过程 [root@localhost apr-1.7.0]# cd /root/apr-util-1.6.1
[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
....................................配置过程
[root@localhost apr-util-1.6.1]# make && make install
.........................................编译安装过程 #apache安装
[root@localhost apr-util-1.6.1]# cd /root/httpd-2.4.46
[root@localhost httpd-2.4.46]# ./configure --prefix=/usr/local/apache \
> --sysconfdir=/etc/httpd24 \
> --enable-so \
> --enable-ssl \
> --enable-cgi \
> --enable-rewrite \
> --with-zlib \
> --with-pcre \
> --with-apr=/usr/local/apr \
> --with-apr-util=/usr/local/apr-util/ \
> --enable-modules=most \
> --enable-mpms-shared=all \
> --with-mpm=prefork
....................................配置过程
[root@localhost httpd-2.4.46]# make && make install
............................编译安装过程
#安装后配置
[root@localhost ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@localhost ~]# source /etc/profile.d/httpd.sh
[root@localhost ~]# ln -s /usr/local/apache/include/ /usr/include/httpd
[root@localhost ~]# vim /etc/man_db.conf
MANDATORY_MANPATH /usr/man
MANDATORY_MANPATH /usr/share/man
MANDATORY_MANPATH /usr/local/share/man
MANDATORY_MANPATH /usr/local/apache/man //添加此行
[root@localhost ~]# vim /etc/httpd24/httpd.conf
#
#ServerName www.example.com:80 //取消前面的注释 #启动apache
[root@localhost ~]# apachectl start
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
安装MySQL
#安装依赖包
[root@localhost ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel ncurses-compat-libs #创建用户和组
[root@localhost ~]# useradd -r -M -s /sbin/nologin mysql #下载二进制格式mysql软件包
[root@localhost ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz #解压软件
[root@localhost ~]# tar -xf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ [root@localhost ~]# ln -sv /usr/local/mysql-5.7.31-linux-glibc2.12-x86_64/ /usr/local/mysql
'/usr/local/mysql' -> '/usr/local/mysql-5.7.31-linux-glibc2.12-x86_64/' [root@localhost local]# chown -R mysql.mysql mysql* #添加环境变量
[root@localhost local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/myslq.sh
[root@localhost local]# source /etc/profile.d/myslq.sh
[root@localhost local]# echo $PATH
/usr/local/mysql/bin:/usr/local/apache/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@localhost ~]# ln -s /usr/local/mysql/include/ /usr/include/mysql
[root@localhost ~]# vim /etc/man_db.conf
MANDATORY_MANPATH /usr/local/apache/man
MANDATORY_MANPATH /usr/local/mysql/man #添加man文件
[root@localhost ~]# vim /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
[root@localhost ~]# ldconfig
#创建数据存放目录
[root@localhost local]# mkdir /mydata
[root@localhost local]# chown -R mysql.mysql /mydata/ #初始化数据库
[root@localhost local]# mysqld --initialize --user=mysql --datadir=/mydata
2021-01-01T07:38:58.366227Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-01-01T07:38:58.551752Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-01-01T07:38:58.582971Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-01-01T07:38:58.593654Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 68c0296b-4c04-11eb-a48e-000c2928a994.
2021-01-01T07:38:58.594268Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-01-01T07:38:59.115003Z 0 [Warning] CA certificate ca.pem is self signed.
2021-01-01T07:38:59.228479Z 1 [Note] A temporary password is generated for root@localhost: Jcselu.3md<w #修改my.cnf配置文件
[root@localhost ~]# vim /etc/my.cnf
#添加以下内容
[mysqld]
basedir = /usr/local/mysql
datadir = /mydata
socket = /tmp/mysql.sock
port = 3306
pid-file = /mydata/mysql.pid
user = mysql
skip-name-resolve [client-server] #配置服务启动脚本
[root@localhost ~]# cd /usr/local/mysql/support-files/
[root@localhost support-files]# ls
magic mysqld_multi.server mysql-log-rotate mysql.server
[root@localhost support-files]# cp mysql.server /etc/init.d/mysqld
[root@localhost support-files]# vim /etc/init.d/mysqd
# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files. basedir=/usr/local/mysql
datadir=/mydata #启动mysql
[root@localhost ~]# service mysqld start
Starting MySQL. SUCCESS!
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:* #使用临时密码登录修改密码
[root@localhost ~]# mysql -uroot -p'Jcselu.3md<w'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.31 Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> set password = password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
yum安装PHP
#安装依赖包
[root@localhost ~]# yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg libjpeg-devel libpng libpng-devel openldap-devel pcre-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel php-mysqlnd [root@localhost ~]# yum -y install php-*
[root@localhost ~]# php -v
PHP 7.2.24 (cli) (built: Oct 22 2019 08:28:36) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.24, Copyright (c) 1999-2018, by Zend Technologies
[root@localhost ~]# vim /etc/php-fpm.d/www.conf
;listen = /run/php-fpm/www.sock #注释此行
listen = 127.0.0.1:9000 #添加监听端口
[root@localhost ~]# systemctl start php-fp
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 127.0.0.1:9000 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22
配置apache
启用代理模块
[root@localhost ~]# vim /etc/httpd24/httpd.conf
#LoadModule remoteip_module modules/mod_remoteip.so
LoadModule proxy_module modules/mod_proxy.so //取消注释
#LoadModule proxy_connect_module modules/mod_proxy_connect.so
#LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
#LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so //取消注释
#LoadModule proxy_scgi_module modules/mod_proxy_scgi.so
创建虚拟主机目录并生成php测试页面
[root@localhost ~]# mkdir /usr/local/apache/htdocs/test
[root@localhost ~]# vim /usr/local/apache/htdocs/test/index.php
<?php
phpinfo();
?> [root@localhost ~]# chown -R apache.apache /usr/local/apache/htdocs/ [root@localhost ~]# vim /etc/httpd24/httpd.conf
#在配置文件的最后加入以下内容
<VirtualHost *:80>
DocumentRoot "/usr/local/apache/htdocs/test"
ServerName www.testhhhh.com
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/test/$1
<Directory "/usr/local/apache/htdocs/test">
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
[root@localhost ~]# vim /etc/httpd24/httpd.conf
# If the AddEncoding directives above are commented-out, then you
# probably should define those extensions to indicate media types:
#
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php #添加此行
AddType application/x-httpd-php-source .phps #添加此行
.......................................................
# is requested.
#
<IfModule dir_module>
DirectoryIndex index.php index.html #添加index.php [root@localhost ~]# apachectl restart
验证
LAMP搭建示例的更多相关文章
- 搭建LAMP环境示例
html { font-family: sans-serif } body { margin: 0 } article,aside,details,figcaption,figure,footer,h ...
- (原创)LAMP搭建之二:apache配置文件详解(中英文对照版)
LAMP搭建之二:apache配置文件详解(中英文对照版) # This is the main Apache server configuration file. It contains the # ...
- 买错的电影票,含着泪也得看-LAMP搭建&Linux基础
hi 没说过,上周五室友过生请客,在龙湖里吃嗨了喝爽了,回去的路上侃侃而谈.说好的这周一起去看年内最后的大片,火星救援的,谁知道老子眼神不好,买错了电影的时间...把周六的约定提前到了今儿个下午,ma ...
- (原创)LAMP搭建之一:图解如何安装并检查LAMP
LAMP搭建之一:图解如何安装并检查LAMP 第一步:安装Linux(RedHat5) 第二步:rpm -qa httpd(查看apache是否安装) rpm -qa php(查看php是否安装) r ...
- LAMP 搭建wordpress部署教程贴.
LAMP 搭建wordpress部署教程贴.这是一篇主要将LAMP,并且通过wordpress来进行验证,演示.如何去部署PHP CMS很多新手看到LAMP就很很头大,觉得很难搞,编译安装,搞了好几天 ...
- Ubuntu 14.04 LAMP搭建(Apache 2.47+MySQL 5.5+PHP5.5)
原文:Ubuntu LAMP搭建 为了数据库课程设计,只好自己搭一个数据库系统,采用LAMP方式. 一.安装 1.安装Apache sudo apt-get install apache2 Apach ...
- LVS之-LAMP搭建wordpress
author:JevonWei 版权声明:原创作品 LVS搭建wordpress,涉及的知识点有DNS,LAMP,NFS及LVS 网络拓扑图 网络环境 NFS 192.168.198.130 mysq ...
- LAMP 搭建
p { margin-bottom: 0.25cm; line-height: 120% } LAMP 搭建 承 Ubuntu 17.10.1安装, 定制. 参考 电子工业出版社, Ubuntu完美应 ...
- Linux:LAMP搭建DISCU!论坛
LAMP搭建DISCU!论坛 试验机为centos6.8 i686 应用的包 mysql-5.1.73-linux-i686-glibc23.tar.gz httpd-2.2.24.tar.bz2 p ...
随机推荐
- 第15.23节 PyQt(Python+Qt)入门学习:Model/View架构中QListView视图配套Model的开发使用
老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 一.概述 QListView理论上可以和所有QAbstractItemModel派生的类如QStri ...
- flask注册蓝图报错
记录下这个我找了两天的坑... take no arguments() 这两天一直学习flask的时候,我把注册的蓝图,写成注册的form表单的 举个栗子 class TetsView(view.Me ...
- 读github,deepfm,pytorch源码 记录
代码:https://github.com/chenxijun1029/DeepFM_with_PyTorch 2020/12/2首先是数据预处理文件:dataPreprocess.py1. 源数据集 ...
- 团队作业4-Day2
团队作业4-Day2 项目git地址 1. 站立式会议 2. 项目燃尽图 3. 适当的项目截图(部分) 4. 代码/文档签入记录(部分) 5. 每人每日总结 吴梓华:今日进行了小程序与网页代码编写的区 ...
- CF484B Maximum Value
这个东西他一开始也是草稿 题解 我们考虑在值域上做,设值域为 \(m\) . 我们可以考虑数论分块,对于一对 \(a_i\) 和 \(a_j\) ,$\left \lfloor \frac{a_i}{ ...
- Android开发系列全套课程
学习地址 https://pan.baidu.com/s/12Ljy-TDL5-P0AsYdTxGw5w#list/path=%2F
- 项目中对获取的数据进行下载成Excel表格
//moment是操作日期的插件 //引入lodash是为了方便操作数据 //xlsx是获取表格的必须插件 import moment from 'moment'; import _ from ...
- Windows版 charles安装证书抓包网页HTTPS
1.在Charles官网https://www.charlesproxy.com/download/下载,我这边下载的是免费体验版的. 2.安装好以后打开,配置Charles证书:选择 help--S ...
- AWT02-ContainerAPI
1.体系 Object -Component -Container Window:窗口容器 Frame:创建窗口 Dialog:创建对话框 Panel:内嵌容器 Applet ScrollPane:含 ...
- abp.zero 9.0框架的前端Angular使用说明
abp.zero 9.0框架的前端Angular使用说明 目录 abp.zero 9.0框架的前端Angular使用说明 摘要 1 部署及启动 1.1 依赖包安装 1.2 使用yarn安装依赖包 1. ...