LAMP服务架构

LAMP服务架构,第1张

LAMP服务架构

文章目录
  • LAMP服务架构
    • 1. LAMP简介
    • 2. LAMP工作原理
    • 3. 部署LAMP
      • 3.1 源码安装http服务
      • 3.2 源码安装mysql数据库
      • 3.3 源码安装php
      • 3.2 apache和php配置

1. LAMP简介

LAMP是指一组通常一起使用来运行动态网站或者服务器的自由软件名称首字母缩写

  • L代表服务器 *** 作系统使用Linux
  • A代表网站服务使用的是Apache软件基金会中的httpd软件
  • M代表网站后台使用的数据库是MySQL数据库
  • P代表网站是使用PHP/Perl/Python等语言开发
2. LAMP工作原理

当客户端请求的是静态资源时,web服务(httpd程序),会直接返回静态资源给客户端

当客户端请求的是动态资源时,apache(httpd程序)会调用libphpX.so模块进行相应的解析
如果解析处理需要用到后台数据库相关数据,此时php程序也会连接后台数据库
最终php程序将解析后的结果返回给apache(httpd程序),让apache返回给客户端

静态网页

  • 静态网页指使用HTML(超文本标记语言)编写,一般后缀为.htm,.html等;网页文件中没有程序代码。
  • 静态页面,用户双击打开,看到的效果与web服务器是相同的,因为网页的内容在用户访问之前就已经确定。

动态网页

  • 动态网页指网站使用特定的编程语言编写,网页文件中除了HTML标记以外,还包括一些实现特定功能的程序代码。
  • 服务端可以根据客户端的不同请求动态产生网页内容。
  • 动态网页后缀一般为.php .asp .aspx .cgi .perl .jsp等
  • 常见的留言板,论坛,注册,发帖都是用动态网页实现的


3. 部署LAMP 3.1 源码安装http服务
# 下载解压包后解压
[root@localhost ~]# ls
anaconda-ks.cfg  apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz  httpd-2.4.53.tar.gz
[root@localhost ~]# tar -xf apr-1.7.0.tar.gz
[root@localhost ~]# tar -xf apr-util-1.6.1.tar.gz
[root@localhost ~]# tar -xf httpd-2.4.53.tar.gz
# 安装环境
[root@localhost ~]# dnf -y group mark install "Development Tools"
[root@localhost ~]# dnf -y install gcc gcc-c++ openssl-devel pcre-devel expat-devel
# 创建用户
[root@localhost ~]# useradd -r -M -s /sbin/nologin apache
# 编译安装
[root@localhost ~]# cd apr-1.7.0
[root@localhost apr-1.7.0]# vim configure
    $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
[root@localhost apr-util-1.6.1]# cd /root/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
[root@localhost httpd-2.4.53]# make && make install
# 安装后配置
[root@localhost httpd-2.4.53]# cd /usr/local/apache/
[root@localhost apache]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/apache.sh
[root@localhost apache]# source /etc/profile.d/apache.sh 
[root@localhost apache]# cd /usr/lib/systemd/system
[root@localhost system]# cp sshd.service httpd.service
[root@localhost system]# vim 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 enable --now httpd
[root@localhost ~]# ss -antl
State       Recv-Q      Send-Q            Local Address:Port             Peer Address:Port      Process      
LISTEN      0           128                     0.0.0.0:22                    0.0.0.0:*                      
LISTEN      0           128                           *:80                          *:*                      
LISTEN      0           128                        [::]:22                       [::]:*                      



3.2 源码安装mysql数据库
# 安装5.7yum源和所需的依赖包
[root@localhost ~]# wget https://dev.mysql.com/get/mysql80-community-release-el7-5.noarch.rpm
[root@localhost ~]# rpm -ivh mysql80-community-release-el7-5.noarch.rpm
[root@localhost ~]# vim /etc/yum.repos.d/mysql-community.repo 
[root@localhost ~]# wget http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-server-5.7.35-1.el7.x86_64.rpm \
> http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-client-5.7.35-1.el7.x86_64.rpm \
> http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-common-5.7.35-1.el7.x86_64.rpm \
> http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-devel-5.7.35-1.el7.x86_64.rpm \
> http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-libs-5.7.35-1.el7.x86_64.rpm
# 启动服务
[root@localhost ~]# systemctl enable --now mysqld
[root@localhost ~]# ss -antl
State       Recv-Q      Send-Q            Local Address:Port             Peer Address:Port      Process      
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 ~]# grep 'password' /var/log/mysqld.log 
2022-04-21T16:26:14.702813Z 1 [Note] A temporary password is generated for root@localhost: _3(biehY-h!J
[root@localhost ~]# mysql -uroot -p'_3(biehY-h!J'

3.3 源码安装php

所需软件包网址:https://pkgs.org/

# 下载oniguruma-devel工具包
[root@localhost ~]# dnf -y install http://mirror.centos.org/centos/8-stream/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm

php官网:php.net

链接:https://www.php.net/distributions/php-7.4.29.tar.xz

# 配置安装环境进行编译安装
[root@localhost ~]# dnf -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 sqlite-devel libzip-devel
[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]# ./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 && make install

3.2 apache和php配置
# 配置php
[root@localhost php-7.4.29]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh
[root@localhost php-7.4.29]# source /etc/profile.d/php7.sh 
[root@localhost php-7.4.29]# \cp php.ini-production /etc/php.ini
[root@localhost php-7.4.29]# cp sapi/fpm/init.d.php-fpm /etc/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 php-7.4.29]# service php-fpm start
Starting php-fpm  done
[root@localhost php-7.4.29]# ss -antl
State       Recv-Q      Send-Q            Local Address:Port             Peer Address:Port      Process      
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 ~]# mkdir /usr/local/apache/htdocs/test.com
[root@localhost test.com]# cat > /usr/local/apache/htdocs/test.com/index.php <
<?php
    phpinfo();
?>
EOF

[root@localhost ~]# vim /usr/local/apache/conf/httpd.conf
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

[root@localhost ~]# vim /usr/local/apache/conf/httpd.conf
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs/test.com"
    ServerName test.example.com
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/test.com/
    <Directory "/usr/local/apache/htdocs/test.com">
        Options none
        AllowOverride none
        Require all granted
    </Directory>
</VirtualHost>

[root@localhost ~]# vim /usr/local/apache/conf/httpd.conf
    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 ~]# vim /usr/local/apache/conf/httpd.conf  
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>
[root@localhost ~]# systemctl restart httpd

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/725230.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-26
下一篇 2022-04-26

发表评论

登录后才能评论

评论列表(0条)

保存