栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

LAMP部署

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

LAMP部署

文章目录
      • LAMP简介
      • web服务器
        • web服务器的资源分为两种,静态资源和动态资源
        • 工作流程
          • http响应报文
      • httpd与php结合的方式
        • httpd与php结合的方式有以下三种:
      • lamp平台构建
          • 环境说明:
          • lamp平台软件安装次序:
        • 配置yum源
        • 安装httpd
        • 安装mysql
        • 安装php
        • 配置php
        • 配置apache
      • 报错
        • httpd报错
        • php报错

LAMP简介

lamp是由Linux+Apache+Mysql/MariaDB+Php/Perl/Python的一组动态网站或者服务器的开源软件,除Linux外其它各部件本身都是各自独立的程序,但是因为经常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的Web应用程序平台。

LAMP指的是Linux(操作系统)、Apache(HTTP服务器)、MySQL(也指MariaDB,数据库软件)和PHP(有时也是指Perl或Python)的第一个字母,一般用来建立web应用平台。

web服务器 web服务器的资源分为两种,静态资源和动态资源
  • 静态资源就是指静态内容,客户端从服务器获得的资源的表现形式与原文件相同。可以简单的理解为就是直接存储于文件系统中的资源
  • 动态资源则通常是程序文件,需要在服务器执行之后,将执行的结果返回给客户端
工作流程

通过下面的图说明一下web的工作流程︰

  • 客户端通过http协议请求web服务器资源
  • web服务器收到请求后判断客户端请求的资源是静态资源或是动态资源
    • 若是静态资源则直接从本地文件系统取之返回给客户端。
    • 否则若为动态资源则通过FastCGI协议与php服务器联系,通过CGI程序的master进程调度worker进程来执行程序以获得客户端请求的动态资源,并将执行的结果通过FastCGI协议返回给httpd服务器,httpd服务器收到php的执行结果后将其封装为http响应报文响应给客户端。在执行程序获取动态资源时若需要获得数据库中的资源时,由Php服务器通过mysql协议与MySQL/MariaDB服务器交互,取之而后返回给httpd,httpd 将从php服务器收到的执行结果封装成http响应报文响应给客户端。
http响应报文
  • 1xx:100-101,纯信息提示
  • 2XX:200-206,“成功”类的信息
  • 3XX:300-305,“重定向”类的信息
  • 4XX:400-415,“客户端错误”类的信息
  • 5XX:500-505,“服务端错误”类的信息
httpd与php结合的方式 httpd与php结合的方式有以下三种:

modules: php将以httpd的扩展模块形式存在,需要加载动态资源时,httpd可以直接通过php模块来加工资源并返回给客户端
httpd prefork: libphp5.so(多进程楔型的php)
httpd event or worker: libphp5-zts.so(线程模型的php)
CGI(通用网关接口): httpd需要加载动态资源时,通过CGI与php解释器联系,获得php执行的结果,此的nlipa贝责与php连接的建立和断开等
FastCGI(CGI的改良版):利用php-fpm机制,启动为服务进程,php自行运行为一个服务,https通过socket与php通信

较于CGI方式,FastCGl更为常用,很少有人使用CGI方式来加载动态资源

lamp平台构建 环境说明:
系统平台IP需要安装的服务
redhat8192.168.201.138httpd-2.4 mysql-5.7 php php-mysql
lamp平台软件安装次序:

https --> mysql --> php

配置yum源
//配置centos源
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# rm -rf *
[root@localhost yum.repos.d]# ls
[root@localhost ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@localhost ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

//配置epel源
[root@localhost ~]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm                             
[root@localhost ~]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@localhost ~]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
安装httpd
//配置环境
[root@localhost ~]# yum groups mark install "Development Tools"
[root@localhost ~]# useradd -r -M -s /sbin/nologin apache
[root@localhost ~]# grep apache /etc/group
apache:x:973:

//安装依赖包
[root@localhost ~]# yum -y install bzip2 make openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make-devel

//安装源码包
[root@localhost ~]# wget https://downloads.apache.org/apr/apr-1.7.0.tar.gz
[root@localhost ~]# wget https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz
[root@localhost ~]# wget https://downloads.apache.org/httpd/httpd-2.4.53.tar.gz
[root@localhost ~]# ls
公共  视频  文档  音乐  anaconda-ks.cfg   apr-util-1.6.1.tar.gz  initial-setup-ks.cfg
模板  图片  下载  桌面  apr-1.7.0.tar.gz  httpd-2.4.53.tar.gz

//安装apr
[root@localhost ~]# tar xf apr-1.7.0.tar.gz
[root@localhost ~]# cd apr-1.7.0/
[root@localhost apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.7.0]# dnf -y install make
[root@localhost apr-1.7.0]# make
[root@localhost apr-1.7.0]# make install

//安装apr-util
[root@localhost ~]# tar xf apr-util-1.6.1.tar.gz 
[root@localhost ~]# cd 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
[root@localhost apr-util-1.6.1]# make install

//安装http
[root@localhost ~]# tar xf httpd-2.4.53.tar.gz 
[root@localhost ~]# cd httpd-2.4.53/
[root@localhost httpd-2.4.53]# ./configure --prefix=/usr/local/apache 
> --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


//配置httpd
[root@localhost ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/apache.sh
[root@localhost ~]# source /etc/profile.d/apache.sh
[root@localhost ~]# which httpd
/usr/local/apache/bin/httpd
[root@localhost ~]# which apachectl
/usr/local/apache/bin/apachectl
[root@localhost ~]# ln -s /usr/local/apache/include/ /usr/include/apache
[root@localhost ~]# vim /etc/man_db.conf
MANDATORY_MANPATH                       /usr/local/share/apache

//启动apache
[root@localhost ~]# systemctl disable --now firewalld.service
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# setenforce 0
[root@localhost ~]# apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
[root@localhost ~]# ss -antl
State           Recv-Q          Send-Q                     Local Address:Port                     Peer Address:Port          
LISTEN          0               32                         192.168.122.1:53                            0.0.0.0:*             
LISTEN          0               128                              0.0.0.0:22                            0.0.0.0:*             
LISTEN          0               5                              127.0.0.1:631                           0.0.0.0:*             
LISTEN          0               128                                 [::]:111                              [::]:*             
LISTEN          0               128                                    *:80                                  *:*     


//使用systemctl命令设置httpd
[root@localhost conf]# apachectl status
/usr/local/apache/bin/apachectl:行95: lynx: 未找到命令
[root@localhost conf]# cd 
[root@localhost ~]# systemctl status httpd
[root@localhost ~]# cd /usr/lib/systemd/system
[root@localhost system]# ls sshd.service 
sshd.service
[root@localhost system]# cp sshd.service httpd.service
[root@localhost system]# vi httpd.service
[root@localhost system]# cat httpd.service
[Unit]
Description=httpd server daemon
After=network.target sshd-keygen.target

[Service]
Type=forking
ExecStart=/usr/local/apache/bin/apachectl start
ExecStop=/usr/local/apache/bin/apachectl stop
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target

[root@localhost system]# systemctl daemon-reload 
[root@localhost system]# systemctl status httpd
● httpd.service - httpd server daemon
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset:>
   Active: inactive (dead)
[root@localhost system]# systemctl start httpd
[root@localhost system]# systemctl enable --now httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@localhost system]# systemctl status httpd
● httpd.service - httpd server daemon
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: >
   Active: active (running) since Sun 2022-04-17 22:56:53 CST; 6s ago
  Process: 425418 ExecStart=/usr/local/apache/bin/apachectl start (code=exited, st>
 Main PID: 425426 (httpd)
    Tasks: 6 (limit: 11159)
   Memory: 4.8M
   CGroup: /system.slice/httpd.service
           ├─425426 /usr/local/apache/bin/httpd -k start
           ├─425428 /usr/local/apache/bin/httpd -k start
           ├─425429 /usr/local/apache/bin/httpd -k start
           ├─425430 /usr/local/apache/bin/httpd -k start
           ├─425431 /usr/local/apache/bin/httpd -k start
           └─425432 /usr/local/apache/bin/httpd -k start

4月 17 22:56:53 localhost.localdomain systemd[1]: Starting httpd server daemon...
4月 17 22:56:53 localhost.localdomain apachectl[425418]: AH00558: httpd: Could not>
4月 17 22:56:53 localhost.localdomain systemd[1]: Started httpd server daemon.
[root@localhost system]# ss -antl
State     Recv-Q    Send-Q         Local Address:Port         Peer Address:Port    
LISTEN    0         128                  0.0.0.0:111               0.0.0.0:*       
LISTEN    0         32             192.168.122.1:53                0.0.0.0:*       
LISTEN    0         128                  0.0.0.0:22                0.0.0.0:*       
LISTEN    0         5                  127.0.0.1:631               0.0.0.0:*       
LISTEN    0         128                     [::]:111                  [::]:*       
LISTEN    0         128                        *:80                      *:*       
LISTEN    0         128                     [::]:22                   [::]:*       
LISTEN    0         5                      [::1]:631                  [::]:*       

安装mysql
[root@localhost ~]# which wget
/usr/bin/wget
[root@localhost ~]# wget http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
[root@localhost ~]# rpm -ivh mysql57-community-release-el7-10.noarch.rpm
[root@localhost ~]# yum clean all
[root@localhost ~]# yum makecache


//下载mysql的软件包并安装
[root@localhost ~]# wget http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-client-5.7.37-1.el7.x86_64.rpm
[root@localhost ~]# wget http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-common-5.7.37-1.el7.x86_64.rpm
[root@localhost ~]# wget http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-devel-5.7.37-1.el7.x86_64.rpm
[root@localhost ~]# wget http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-libs-5.7.37-1.el7.x86_64.rpm
[root@localhost ~]# wget http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-server-5.7.37-1.el7.x86_64.rpm
[root@localhost ~]# ls
公共  anaconda-ks.cfg
模板  initial-setup-ks.cfg
视频  mysql57-community-release-el7-10.noarch.rpm
图片  mysql-community-client-5.7.37-1.el7.x86_64.rpm
文档  mysql-community-common-5.7.37-1.el7.x86_64.rpm
下载  mysql-community-devel-5.7.37-1.el7.x86_64.rpm
音乐  mysql-community-libs-5.7.37-1.el7.x86_64.rpm
桌面  mysql-community-server-5.7.37-1.el7.x86_64.rpm
[root@localhost ~]# dnf -y install *.rpm


//
[root@localhost ~]# grep "password" /var/log/mysqld.log
2022-04-18T11:03:10.946413Z 1 [Note] A temporary password is generated for root@localhost: 2+fipbIa9yll
[root@localhost ~]# mysql -uroot -p2+fipbIa9yll
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 3
Server version: 5.7.37

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

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>



mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)

mysql> set password = password('090.Com');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> quit
Bye

[root@localhost ~]# mysql -uroot -p090.Com
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 4
Server version: 5.7.37 MySQL Community Server (GPL)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

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> 

安装php
//下载php
[root@localhost ~]# wget https://www.php.net/distributions/php-7.4.29.tar.xz
[root@localhost ~]# tar xf php-7.4.29.tar.xz


//安装依赖包
[root@localhost ~]# cd php-7.4.29/
[root@localhost php-7.4.29]# 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
[root@localhost php-7.4.29]# dnf list all|grep mysql|grep php
php-mysqlnd.x86_64                                                7.2.24-1.module_el8.2.0+313+b04d0a66                   AppStream                
[root@localhost php-7.4.29]# dnf -y install php-mysqlnd
[root@localhost php-7.4.29]# yum -y install sqlite-devel libzip-devel
[root@localhost ~]#yum -y install https://repo.almalinux.org/almalinux/8/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm
[root@localhost php-7.4.29]# ./configure --prefix=/usr/local/php7  
> --with-config-file-path=/etc 
> --enable-fpm 
> --enable-inline-optimization 
> --disable-debug 
> --disable-rpath 
> --enable-shared 
> --enable-soap 
> --with-openssl 
> --enable-bcmath 
> --with-iconv 
> --with-bz2 
> --enable-calendar 
> --with-curl 
> --enable-exif  
> --enable-ftp 
> --enable-gd 
> --with-jpeg 
> --with-zlib-dir 
> --with-freetype 
> --with-gettext 
> --enable-json 
> --enable-mbstring 
> --enable-pdo 
> --with-mysqli=mysqlnd 
> --with-pdo-mysql=mysqlnd 
> --with-readline 
> --enable-shmop 
> --enable-simplexml 
> --enable-sockets 
> --with-zip 
> --enable-mysqlnd-compression-support 
> --with-pear 
> --enable-pcntl 
> --enable-posix

[root@localhost php-7.4.29]# make
[root@localhost php-7.4.29]# make install
配置php
//创建环境变量
[root@localhost ~]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh
[root@localhost ~]# source /etc/profile.d/php7.sh
[root@localhost ~]# which php
/usr/local/php7/bin/php

//配置php-fpm
[root@localhost ~]# cd php-7.4.29/
[root@localhost php-7.4.29]# cp php.ini-production /etc/php.ini
cp:是否覆盖'/etc/php.ini'? yes
[root@localhost php-7.4.29]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-7.4.29]# chmod +x /etc/rc.d/init.d/php-fpm
[root@localhost php-7.4.29]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
[root@localhost php-7.4.29]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf


//开启服务检查端口
[root@localhost ~]# service php-fpm start
Starting php-fpm  done
[root@localhost ~]# ss -antl
State           Recv-Q          Send-Q                     Local Address:Port                     Peer Address:Port          
LISTEN          0               128                              0.0.0.0:111                           0.0.0.0:*             
LISTEN          0               32                         192.168.122.1:53                            0.0.0.0:*             
LISTEN          0               128                              0.0.0.0:22                            0.0.0.0:*             
LISTEN          0               5                              127.0.0.1:631                           0.0.0.0:*             
LISTEN          0               128                            127.0.0.1:9000                          0.0.0.0:*             
LISTEN          0               80                                     *:3306                                *:*             
LISTEN          0               128                                 [::]:111                              [::]:*             
LISTEN          0               128                                    *:80                                  *:*             
LISTEN          0               128                                 [::]:22                               [::]:*             
LISTEN          0               5                                  [::1]:631                              [::]:*             
[root@localhost ~]# ps -ef |grep php
root      622547       1  0 23:01 ?        00:00:00 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)
nobody    622548  622547  0 23:01 ?        00:00:00 php-fpm: pool www
nobody    622549  622547  0 23:01 ?        00:00:00 php-fpm: pool www
root      623150  336616  0 23:01 pts/0    00:00:00 grep --color=auto php
配置apache
//创建虚拟主机目录并生成php测试页面
[root@localhost ~]# cd /usr/local/apache/htdocs/
[root@localhost htdocs]# mkdir test.com
[root@localhost htdocs]# ls
index.html  test.com
[root@localhost htdocs]# chown -R apache.apache /usr/local/apache/
[root@localhost htdocs]# cd test.com/
[root@localhost test.com]# vim index.php
[root@localhost test.com]# cat index.php

[root@localhost test.com]# cd ..
[root@localhost htdocs]# ls
index.html  test.com
[root@localhost htdocs]# ll
总用量 4
-rw-r--r--. 1 apache apache 45 6月  12 2007 index.html
drwxr-xr-x. 2 apache apache 23 4月  21 23:11 test.com

//配置虚拟主机
[root@localhost htdocs]# cd /usr/local/apache/conf/
[root@localhost conf]# vim httpd.conf
//在配置文件的最后加入以下内容

    DocumentRoot "/usr/local/apache/htdocs/test.com"
    ServerName www.test.com
    ProxyRequests Off
    ProxyPassMatch ^/(.*.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/test.com/$1
    
        Options none
        AllowOverride none
        Require all granted
    


[root@localhost conf]# vim httpd.conf
//将这两行注释取消 启动这两个模块
LoadModule proxy_module modules/mod_proxy.so   
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

[root@localhost conf]# vim httpd.conf
//搜索AddType,添加以下内容
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php        #添加此行
AddType application/x-httpd-php-source .phps        #添加此行

[root@localhost conf]# apachectl stop
[root@localhost conf]# apachectl start

报错 httpd报错
make: *** [/root/apr-util-1.6.1/build/rules.mk:206:xml/apr_xml.lo] 错误 1

//解决方案
[root@localhost apr-util-1.6.1]#yum -y install expat-devel
checking for C compiler ... not found ./configure: error: C compiler cc is not found 

//解决方案
[root@localhost ~]# yum -y install gcc gcc-c++ make
rm: cannot remove 'libtoolT': No such file or directory
config.status: executing default commands

//解决方案
[root@localhost apr-1.7.0]# dnf -y install libtool
[root@localhost apr-1.7.0]# dnf -y install libtool-ltdl-devel libtool-ltdl
configure: error: in `/root/apr-1.7.0':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details

//解决方案
[root@localhost apr-1.7.0]# dnf -y install gcc gcc-c++
make:***没有规则可制作目标“build”,由“default” 需求   停止

//解决方案
[root@localhost ~]# yum -y install gcc openssl openssl-devel pcre-devel zlib zlib-devel 
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-
http_gzip_module option, or install the zlib library into the
system, or build the zlib library statically from the source with
nginx by using --with-zlib= option. 

//解决方案:
[root@localhost ~]# yum -y install zlib-devel
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL 
library into the system, or build the OpenSSL library statically
from the source with nginx by using --with-openssl= option.

//解决方案
[root@localhost ~]# yum -y install openssl-devel
configure: error: pcre(2)-config for libpcre not found. PCRE is required and available from http://pcre.org/

//解决方案
[root@localhost ~]# yum -y install pcre-devel
php报错
configure: error: Package requirements (sqlite3 > 3.7.4) were not met:
Package 'sqlite3', required by 'virtual:world', not found

//解决方案
[root@localhost php-7.4.29]# rpm -qa|grep sqlite3
[root@localhost php-7.4.29]# dnf list all|grep sqlite
[root@localhost php-7.4.29]# yum -y install  sqlite-devel
configure: error: Package requirements (oniguruma) were not met:
Package 'oniguruma', required by 'virtual:world', not found

//解决方案
[root@localhost ~]#yum -y install https://repo.almalinux.org/almalinux/8/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm
configure: error: Package requirements (libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0) were not met:
Package 'libzip', required by 'virtual:world', not found

//解决方案
[root@localhost php-7.4.29]# yum install -y libzip-devel
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/830667.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号