当前位置:网站首页>Web Service (04) -- Introduction and construction of lamp +discuz Forum
Web Service (04) -- Introduction and construction of lamp +discuz Forum
2022-07-27 01:36:00 【A simple comparison】
List of articles
LAMP Introduction and construction of +DISCUZ Forum
Preface
WEB The server is also known as WWW(WORLD WIDE WEB web ) The server , The main function is to provide online information browsing services . And common web The server has :httpd(apache)、nginx+PHPtomcat、jsp+html 、win:IIS.
And one of LAMP Of Apache(HTTPD) class LINUX System ——Linux+Apache+Mysql/MariaDB+Perl/PHP/Python A set of open source software commonly used to build dynamic websites or servers , They are independent procedures , But because it's often used together , Higher and higher compatibility , Together, a powerful Web Application platform .
With the vigorous development of open source trend , Open source Of LAMP Already with J2EE and .net Commercial software has formed a tripartite trend , And the software development project is on the software side The investment cost is low , So suffer the whole IT The attention of the world . From the traffic of the website ,50% The above traffic yes LAMP To provide ,LAMP Is the most powerful website solution .
One 、LAMP An introduction to the
LAMP Architecture is one of the mature enterprise website application modes , It refers to a whole system and related software working together , Can provide dynamic web Site service and its application development environment .LAMP It's an abbreviation , Specific include Linux operating system ,Apache Web server ,MySQL database server ,PHP( or perl,Python) Web programming language .
In the build LAMP Platform time , The installation sequence of each component is Linux,Apache,MySQL,PHP, among Apache and MySQL There is no strict sequence requirement for the installation of , and PHP The installation of the environment is usually at the end of the day , Responsible for communication web Servers and database systems to work together .
The main functions of each component are :
( platform )Linux: As LAMP The foundation of Architecture , Provide for support Web The operating system of the site , Can provide better stability with the other three components , Compatibility (AMP Components also support Windows、UNIX Such as platform ) .
( The front desk )Apache: As LAMP The front end of the architecture , It's a powerful , Stable Web Server program , The server provides website access directly to users , Send web page , Pictures, etc . The main function : Static page —— Send static request ; Forward dynamic requests .
( backstage )MySQL: As LAMP The back end of the architecture , Is a popular open source relational database system . On the corporate website 、 Business systems and other applications , All kinds of account information 、 Product information , Customer information 、 Business data can be stored in MySQL database , Other programs can be done through SQL Statement to query , Change this information . database —— data storage / Read .
( The middle link )PHP/Perl/Python: As three programming languages for developing dynamic web pages , Responsible for interpreting dynamic web files , Responsible for communication Web Servers and database systems to work together , And provide Web Application development and running environment . among PHP Is a widely used open source multi-purpose scripting language , It can be embedded in HTML in , Especially suitable for Web application development . Dynamic pages —— Dynamic request .
When setting up services, we prefer to compile and install manually , Its advantages are :1. With a large degree of freedom , Features can be customized .2. Timely access to the latest software version 3. Generally applicable to most Linux edition , Easy to use all the time .
LAMP The working process of architecture :
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-OfVlccRo-1658393735801)(https://s2.loli.net/2022/07/19/47cBSnxfoiqUtp2.png)]
1. When the client requests static resources ,web The server will return the static resources directly to the client .
2. When the client requests a dynamic resource ,http Of php The module performs the corresponding dynamic resource operation , If this process also needs the data of the database as the operation parameters ,php Will link mysql Take the data and do the operation , The result of the operation is that the static resources have web The server returns to the client .
Two 、Apache service
Apache HTTPD Server abbreviation Apache, yes Apache An open source web server of the software foundation , It can run on most computer operating systems , Because of its multi platform and security is widely used , It's the most popular Web One of the server-side software .
It's fast 、 Reliable and accessible through simple API Expand , take Perl/Python Wait for the interpreter to compile Translate to the server !Apache HTTP The server is a modular server , Each function uses modularization to plug and unplug ! At present, we support Windows,Linux,Unix Such as platform .
Apache Software foundation ( That is to say Apache Software Foundation, Referred to as ASF), It's dedicated to running an open source software project Apache Groups that provide support to non-profit organizations , This open source software project is Apache project . So our HTTPD Also only Apache One of the open source projects .
Major open source projects :HTTP Server,Ant,DB,iBATIS,Jakarta,Logging,Maven,Struts,Tomcat,Tapestry,Hadoop wait . But the most famous is HTTP Server, So what we're talking about now is Apache It's already HTTPD Server It's the code number of ! What we see more is Tomcat,Hadoop Projects such as .
Apache The main features of :
• Open source 、 Cross platform application 、 Compatibility is good. .
• Support multiple web programming languages 、 Universal gateway interface (cgi)、 Virtual host 、http authentication 、 The server contains commands (ssi)、 Security socket layer 、FastCGI、java servlets.
• Modular design 、 Stable operation 、 Good security .
• Integrate perl、 Integrated proxy server .
The current maximum version of the software is 1.3( Stable operation 、 Compatibility 、 Lack of new functions )、2.4( Multi function ).
Official website :http://www.apache.org/httpd:http://httpd.apache.org/
3、 ... and 、LAMP Service setup
Manual compilation and installation LAMP The software packages required for the service are :
1.apache——apr-1.6.2.tar.gz、apr-util-1.6.0.tar.gz、httpd-2.4.29.tar.bz2
2.MYSQL——mysql-5.7.17.tar.gz、boost_1_59_0.tar.gz
3.PHP——php-7.1.24.tar.gz
1. Compilation and installation apache service
tar zxf apr-1.6.2.tar.gz # decompression apr Compressed package
tar zxf apr-util-1.6.0.tar.gz # decompression apr-util Compressed package
tar jxf httpd-2.4.29.tar.bz2 ## decompression httpd Compressed package
mv apr-1.6.2 httpd-2.4.29/srclib/apr # take apr Put the catalog in httpd Of srclib Under the table of contents
mv apr-util-1.6.0 httpd-2.4.29/srclib/apr-util # take apr-util Put the catalog in httpd Of srclib Under the table of contents
# Environment required for installation
yum -y install \
gcc \ #C Compiler of language
gcc-c++ \ #C++ The compiler
make \ # Source code compiler ( Convert source code to binary file )
pcre \ #pcre It's a Perl function library , Include perl Compatible regular expression library
pcre-devel \ #perl Interface development package for
expat-devel \ # Used to support website parsing HTML、XML file
perl #perl Language compiler
# Optimize the configuration file path , And put httpd The executable program file of the service is put into the directory of the path environment variable to facilitate system identification
ln -s /usr/local/httpd/conf/httpd.conf /etc/
ln -s /usr/local/httpd/bin/* /usr/local/bin/# stay httpd Compile and install in the directory of
./configure \ # The script will run some tests to guess some system related variables and detect the special settings of your operating system , And finally create some files in the production tree to record what it finds
--prefix=/usr/local/httpd \ # Appoint httpd The installation path of the service program
--enable-so \ # Enable dynamic load core module support , send httpd With the ability to further expand functions
--enable-rewrite \ # Enable Web address rewriting , For website optimization 、 Security chain and directory migration maintenance
--enable-charset-lite \ # Start character set support , To support pages encoded with various character sets
--enable-cgi # Enable CGI( Universal gateway interface ) Scripting support , It is convenient for the external expansion of the website and the application access ability
make && make install # Compile and install
# Optimize the configuration file path , And put httpd The executable program file of the service is put into the directory of the path environment variable to facilitate system identification
ln -s /usr/local/httpd/conf/httpd.conf /etc/
ln -s /usr/local/httpd/bin/* /usr/local/bin/
cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd # Easy service management
vim /etc/init.d/httpd # Edit the auto start httpd Service document

chkconfig --add httpd # take httpd Add to system manager
vim /usr/local/httpd/conf/httpd.conf # edit httpd Master profile




2. Compilation and installation MYSQL service
tar zxvf mysql-5.7.17.tar.gz -C /opt # decompression mysql Compressed package
tar zxvf boost_1_59_0.tar.gz -C /usr/local/ # decompression boost Compressed package
mv /usr/local/boost_1_59_0 /usr/local/boost
# Environment required for installation
yum -y install \
gcc \
gcc-c++ \
ncurses \ # Dynamic library of graphic interaction function under character terminal
ncurses-devel \ #ncurses Development kit
bison \ # parsers
cmake #mysql Need to use cmake Compilation and installation
# stay mysql Directory
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ # Appoint mysql Installation path for
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \ # Appoint mysql The process listens to socket files ( Database connection file ) Storage path for
-DSYSCONFDIR=/etc \ # Specify the storage path of the configuration file
-DSYSTEMD_PID_DIR=/usr/local/mysql \ # Specifies the storage path of the process file
-DDEFAULT_CHARSET=utf8 \ # Specifies the default character set encoding , Such as utf8
-DDEFAULT_COLLATION=utf8_general_ci \ # Specifies the character set collation rules to be used by default
-DWITH_EXTRA_CHARSETS=all \ # Specify support for other character set encoding
-DWITH_INNOBASE_STORAGE_ENGINE=1 \ # install INNOBASE Storage engine
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \ # install ARCHIVE Storage engine
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ # install BLACKHOLE Storage engine
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \ # install FEDERATED Storage engine
-DMYSQL_DATADIR=/usr/local/mysql/data \ # Specify the storage path of the database file
-DWITH_BOOST=/usr/local/boost \ # Appoint boost The path of , If you use mysql-boost Integration package installation is -DWITH_BOOST=boost
-DWITH_SYSTEMD=1 # Generation facilitates systemctl Administrative document
# Be careful : If in CMAKE There are errors in the process of , When the error is resolved , Need to put the source directory of CMakeCache.txt File deletion , And then... Again CMAKE, Otherwise, the mistake remains .
make && make install # Compilation and installation
Storage engine options :
MYISAM,MERGE,MEMORY and cSv The engine is compiled to the server by default , There is no need to explicitly install . Statically compile a storage engine to the server , Use -DWITH engine STORAGE ENGINE= 1
The available storage engine values are :ARCHIVE,BLACKHOLE,EXAMPLE,FBDERATBD,IMNOBASB(InnoDB),PARTTTON(partitioning support), and PERFSCHEMA(Performance schema)
useradd -s /sbin/nologin mysql # Create common user management mysql
chown -R mysql:mysql /usr/local/mysql/
chown mysql:mysql /etc/my.cnf # Change management master / Group
vim /etc/my.cnf # Modify the configuration file

In the last line sql_mode Common values are as follows :
NO_ENGINE_SUBSTITUTION: If the required storage engine is disabled or not compiled , Then throw an error . When this value is not set , Replace... With the default storage engine , And throw an exception .
STRICT_TRANS_TABLES: In this mode , If a value cannot be inserted into a transaction table , Then interrupt the current operation , No restrictions on non transaction tables .
NO_AUTO_CREATE_USER: prohibit GRANT Create a user with a blank password .
NO_AUTO_VALUE_ON_ZERO:mysql The self growing columns in can be derived from O Start . By default, self growing columns are generated from 1 At the beginning , If you insert a value of 0 The data will report an error .
NO_ZERO_IN_DATE: Zero days and months are not allowed .
NO_ZERO_DATE:mysql Database is not allowed to insert zero date , Inserting a zero date throws an error instead of a warning .
ERROR_FOR_DIVISION_BY_ZERO: stay INSERT or UPDATE In the process , If the data is divided by zero , It's a mistake, not a warning . By default, when data is divided by zero MysQL return NULL.
PIPES_As_CONCAT: take "||" Treat as the concatenation operator of a string, not as the or operator , This sum Oracle The database is the same , And string concatenation function Concat Similar .
ANSI_QUOTES: Enable ANSI_QUOTES after , You can't use double quotes to refer to strings , Because it's interpreted as an identifier .
# Set the environment variable , Affirming / Declare mysql The command is easy for the system to recognize
echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
source /etc/profile
# Initialize database
cd /usr/local/mysql/bin/
./mysqld \
--initialize-insecure \ # Generate initialization password is empty
--user=mysql \ # Specify the administrative user
--basedir=/usr/local/mysql \ # Specify the installation directory of the database
--datadir=/usr/local/mysql/data # Specify the storage path of the database file
cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
systemctl daemon-reload # Refresh recognition
systemctl start mysqld.service # Opening service
systemctl enable mysqld # Boot up
netstat -napt | grep 3306 # Check the port
# to root Account setup password
mysqladmin -u root -p password "123456"
3. Compilation and installation PHP service
tar zxvf php-7.1.24.tar.gz # decompression php Compressed package
# install GD Kuhe GD Library correlator , Used to process and generate images
yum -y install \
gd \
libjpeg libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel
# To php Directory
./configure \
--prefix=/usr/local/php7 \ # Specify the PHP The installation path of the program
--with-apxs2=/usr/local/httpd/bin/apxs \ # Appoint Apache httpd service-provided apxs The file location of the module support program
--with-mysql-sock=/usr/local/mysql/mysql.sock \ # Appoint mysql The storage path of the database connection file
--with-config-file-path=/usr/local/php7 # Set up PHP Configuration file for php.ini Where will it be stored
--with-mysqli \ # add to MySQL Extended support #mysqli Extension technology can not only call MySQL Stored procedure 、 Handle MySQL Business , It can also make the work of accessing database more stable
--with-zlib \ # Support zlib function , Provides data compression
--with-curl \ # Turn on curl Extend the functionality , Realization HTTP Of Get To download and Post Requested method
--with-gd \ # Activate gd Library support
--with-jpeg-dir \ # Activate jpeg Support for
--with-png-dir \ # Activate png Support for
--with-freetype-dir \
--with-openssl \
--enable-mbstring \ # Enable multi byte string function , In order to support Chinese and other codes
--enable-xml \ # Open the extensible markup language module
--enable-session \ # conversation
--enable-ftp \ # Text transfer protocol
--enable-pdo \ # function library
--enable-tokenizer \ # Token interpreter
--enable-zip #ZIP Compressed format
make && make install # Compilation and installation
# Copy template file , And make changes
cp /opt/php-7.1.24/php.ini-development /usr/local/php7/php.ini
vim /usr/local/php7/php.ini

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-mJF2B3n0-1658393735804)(https://s2.loli.net/2022/07/18/A8xsjySHKuXUOCW.png)]
# Optimize PHP The executable program file of is put into the directory of path environment variable to facilitate system identification
ln -s /usr/local/php7/bin/* /usr/local/bin/
# modify Apache Configuration files let Apache Support PHP
vim /etc/httpd.conf




This is what we can test on the web index.php page :

Be careful : install httpd We need a clean environment when serving , Otherwise I can't recognize php Web page file , Install... In compilation php Warning will appear when , for example :

At this time we need to pass yum remove The command will change the previous httpd Service to delete , And in httpd Through the directory make clean Command clear cache , Compile and install again apache that will do .
Four 、 build DISCUZ Forum
build bbs The purpose of the forum is to complete a simple LAMP framework , Mainly through sql Statement to complete :
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-iJzt7ytl-1658393735806)(https://s2.loli.net/2022/07/19/RnteA98UfvV7pCd.jpg)]



At this time, our forum has basically been set up , You can verify the installation in the web page :

But at this time, the directory file does not exist , Can't go on to the next step :


At this time, we need to go back to Linux Modify the owner of the forum directory in the system :


At this point, we proceed to the next step to continue the installation :





summary
LAMP What is architecture ? Take restaurants for example :
(1) Apache It's like a hotel front desk , Specifically used to accept customer requests , And do some static page processing ( Buy only drinks ).
(2) PHP Like a waiter , It is specially used to parse and handle what cannot be handled by the front desk ” Order ”, If the user wants to eat a bowl of spaghetti , The waiter needs to communicate with the kitchen , And make corresponding arrangements . Then return the processed result to the foreground , The front desk will give it to the user , Because the waiter is so ugly , No one can see .
(3) MySQL It looks like a kitchen , It is specially used for storing food materials , And only the middle waiter can communicate with the kitchen , To get what ingredients .

The professional explanation is as follows
(1) Client sends request connection web Server's 80 port , from Apache Respond to and process the user's static requests .
(2) If the client requests dynamic resources , from Apache Load calls libphpX.so modular ( install php Program bring ) Do parsing .
(3) If the processing needs to communicate with the background database , So by the php Program to complete .
(4) Php The program returns the processed results to Apache, from Apache Return to the client .
END
边栏推荐
猜你喜欢
随机推荐
Longest common substring
ESP8266 STA_UDP_Client
记一次RawImage渲染出来的场景错乱
Longest substring without duplicate characters
markdown
MQTT协议------上
[SQL injection] joint query
Unity a user-friendly UI grayscale shader
Esp8266 connects to the IOT of Lexin cloud platform_ Demo
C语言之数据存储汇总
7、 Loop statement
MySQL closes the problem of automatic submission of connection transactions
11、 Echo
四、数值变量的运算
FaceNet
[by pass] bypass method of WAF
Shell脚本——自动部署DNS服务
十一、echo
Unity 使用NavMesh实现简易的摇杆功能
ESP8266 STA_ Server










