Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install using LAMP source code

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain in detail how to use LAMP source code installation, the editor thinks it is very practical, so share it for you to do a reference, I hope you can get something after reading this article.

LAMP architecture

(built on the same server)

1.lamp introduction

Lamp, the open source software of a group of dynamic websites or servers of linux+apache+mysql/mariadb+php/perl/python, are all kinds of independent programs except linux, which are often used together and have strong compatibility to form a powerful web application platform.

Linux (operating system), Apache (HTTP server), Mysql (mariadb, database software), PHP (perl or python), establish web application platform

2.web Services Workflow web server resources are divided into two types: static and dynamic resources

Static resources: static content in which the resource that the client gets from the server is expressed in the same way as the source file. Resources stored directly in the file system (.mp3 / .mp4 / .jpg / .gif)

Dynamic resources: usually program files, which need to be returned to the client (.php / .asp / .py / .net) after the server executes.

How the web server handles client requests

Phase 1 shows that the httpd server (apache) and the php server communicate through the fastCGI protocol, and php runs as a separate service process.

Phase 2 shows that the php server and the mysql server communicate through the mysql protocol, and php has no contact with mysql itself, but the program written by php can interact with mysql, and the program written by python and perl can also interact with MySQL database.

2.1cgi and fastcgiCGI (common gateway lnterface, Universal Gateway Interface)

Cgi is the interface standard between external applications (cgi programs) and web services, and it is the process of transmitting information between cgi programs and web servers. The CGI specification allows the web server to execute external programs and send their output to the web server, and cgi turns a simple set of static hypermedia documents from web into a complete interactive media.

FastCGI (Fast common Gateway Interface) is an improved version of CGI

CGI processes each task request by starting an interpreter process, which consumes time and resources, while FastCGI processes each request in the form of master-worker, starts a master main process, and starts several worker processes according to the configuration. When the request comes in, master will choose one of the worker processes to process the request, thus avoiding the consumption caused by repeated generation and frequent cpu caused by killer processes.

There are three ways to combine 2.2httpd and php with php and httpd:

Method 1: modules (module): php will exist as an extension module of httpd. When you need to load dynamic resources, httpd can directly php the module to process the resources and return them to the client.

Httpd prefork:libphp5.so (multi-process model php)

Httpd event or worker:libphp5-zts.so (threaded mode php)

Method 2: when CGI:httpd needs to load dynamic resources, contact the php interpreter through CGI to obtain the result of php execution. At this time, httpd is responsible for establishing and disconnecting the connection with php.

Method 3: FastCGI: use php-fpm mechanism to start as a service process, php runs as a service, and https communicates with php through socket

FastCGI is the most commonly used, and few people use CGI to load dynamic resources

2.3web workflow

The client requests web server resources through the website protocol

After receiving the request, the web server determines whether the resource requested by the client is static or dynamic.

If a static resource is used, it is returned to the client directly from the local file system.

In the case of dynamic resources, contact the php server through the FastCGI protocol, schedule the worker process of the CGI program to obtain the dynamic resources requested by the client, and return the execution result to the website server through the FastCGI protocol. After receiving the execution result of the php, the website server encapsulates it as a http response message to the client. When executing the program to obtain the dynamic resources, if you need to obtain the resources in the database. The php server interacts with the Mysql (MariaDB) server through the mysql protocol, and then returns it to httpd,httpd to package the execution result received from the php server into a http response message to the client.

3.LAMP platform construction environment: the order in which the service centos/redhat192.168.136.145httpd-2.4/mysql-5.7/php/php-mysqllamp installed on the system platform ip is installed:

Httpd > mysql > php

Note that php requires httpd to be installed using prefock MPM and installed uniformly in lamp.

3.1 install httpd#redhat source [root@clq ~] # cat / etc/yum.repos.d/CentOS-Stream-CentOS-Stream-AppStream.repo CentOS-Stream-HighAvailability.repoCentOS-Stream-BaseOS.repo CentOS-Stream-Media.repoCentOS-Stream-Debuginfo.repo CentOS-Stream-PowerTools.repoCentOS-Stream-Extras.repo CentOS-Stream-RealTime.repo# install Epel source [root@clq ~] # yum-y install epel-release # View package group [root@clq ~] # yum grouplist # installation package group [root@clq ~] # dnf-y groups mark install "Development Tools" # create apache user [root@clq ~] # useradd-r-M-s / sbin/nologin apache # install dependency package (openssl-devel: encrypted transport module) [root@cb ~] # yum-y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make# download and install apr and apr-util and httpd [root @ Cb ~] # cd / usr/src/# download three packages using wget # tar decompress package # enter apr package to modify [root@cb apr-1.7.0] # vim configurecfgfile= "${ofile} T" trap "$RM\" $cfgfile\ " Exit 1 "1 215$ RM" $cfgfile "# delete or comment on this line # apr compilation three steps. / configure-- prefix=/usr/local/aprmakemake install#apr-util compilation three steps. / configure-- prefix=/usr/local/apr-util-- with-apr=/usr/local/aprmakemake install#httpd compilation three steps. / 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=preforkmakemake install# installs the configuration environment variable: echo 'export PATH=/usr/local/apache/bin:$PATH' > / etc/profile.d/apache.sh read: source / etc/profile.d/httpd.sh header file image Shoot: ln-s / usr/local/apache/include / usr/include/httpd help documentation: vim / etc/man_db.conf 22 MANDATORY_MANPATH / usr/local/share/man 23 MANDATORY_MANPATH / usr/local/apache/man# cancel the comment in front of ServerName (warning message is not important) [root@cb src] # vim / etc/httpd24/httpd.confServerName# start Apache [root @ cb src] # systemctl stop firewalld [root@cb src] # systemctl disbles firewalld [root@cb src] # / usr/local/apache/bin/apachectl start [root@cb src] # ss-antlState Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 128 0.0.0.0 22 0.0.0.0 : * LISTEN 0128 *: 80 *: * LISTEN 0128 [:]: 22 [:]: * # Note to delete the apache# of the system itself and write the service file Realize self-boot # write httpd.service file: two specific paths in vim / etc/systemd/system/httpd.service file:. Configuration file path: / etc/httpd24/httpd.conf. Program file path: / usr/local/apache/bin/httpd# system load file: systemctl daemon-reload# startup systemctl start httpd# self-startup systemctl enable httpd [root@clq ~] # vim / etc/systemd/system httpd.service [root@clq system] # cat httpd.service [Unit] Description=Start httpd [service] Type=simpleEnvironmentFile=/etc/httpd24/httpd.confExecStart=/usr/local/apache/bin/httpd-k start-DFOREGROUNDExecReload=/usr/local/apache/bin/httpd-k gracefulExecStop=/bin/kill- WINCH ${MAINPID} [Install] WantedBy=multi-user.target3.2 install mysql# installation dependency package (cmake: compile automatic configuration tool) dnf-y install ncurses-devel openssl-devel openssl cmake mariadb-devel# create user useradd-r-M-s / sbin/nologin mysql# download mysql5.7.31 package # decompress and put it under / usr/local # rename to facilitate the operation of cd / usr/localmv mysql5.7.31 mysql# to the main chown-R mysql.mysql mysql/# ring Context variable echo 'export PATH=/usr/local/mysql/bin:$PATH' > / etc/profile.d/mysql.shsource / etc/profile.d/mysql.sh# header file mapping ln-s / usr/local/mysql/include / usr/include/mysql# library file vim / etc/ld.so.conf.d/mysql.conf/usr/local/mysql/libldconfig # reread # help document vim / etc/man_db.conf 23 MANDATORY_MANPATH / usr/local/apache/man 24 MANDATORY_MANPATH / usr/local/mysql/man# create data directory mkdir / opt/datachown-R mysql.mysql / opt/data# initialize mysqld-- initialize-- user=mysql-- datadir=/opt/data # write configuration file cat > / etc/my.cnf

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report