# Realize the common application deployment of LAMP architecture

Implement LAMP architecture

1, Compile and install httpd2.4 and php7.3 environment< /h3>

Environment: Master server: 192.168.37.10 php+httpd service
Slave server: 192.168.37.20 mariadb server
Software version: httpd-2.4.39.tar.bz2
php-7.3.7.tar.xz
apr-util-1.6.1.tar.bz2
apr-1.7.0.tar.bz2
mariadb-10.2.25-linux-x86_64 .tar.gz
Slave server:
Install dependent packages:
yum install libaio -y
1. Unzip the specified folder of mariadb
[[emailprotected] ~] # tar -xvf mariadb-10.2.25-linux-x86_64.tar.gz -C /usr/local/
2, establish a soft link
[[email Protected] ~]# cd /usr/local /
[[email Protected] local]# ln -sv mariadb-10.2.25-linux-x86_64/ mysql
3. Create a mysql user and set file owner permissions
[[emailprotected ] local]# chown -R mysql.mysql mysql/
4. Prepare the configuration file
# mkdir /etc/mysql/
# cp support-files/my-large.cnf /etc/ my.cnf #support-files under the mysql directory
# vim /etc/my.cnf
Add three options in [mysqld]:
28 datadir = /data/mysql
29 innodb_file_per_table = on #Default storage engine innodb
30 skip_name_r esolve = on # Prohibit host name resolution, it is recommended to use
5. Create a database file
# cd /usr/local/mysql/
# ./scripts/mysql_install_db --datadir=/data/ mysql --user=mysql

6. Prepare the service script and start the service
# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld
# chkconfig mysqld on
# service mysqld start

7, PATH path
# echo PATH=/usr/local /mysql/bin:$PATH> /etc/profile.d/mysql.sh
#. /etc/profile.d/mysql.sh # Add environment variables to the startup script
8, start the service
service mysql start
8, security initialization
/user/local/mysql/bin/mysql_secure_installation # mysql security hardening sets the database administrator root password
prohibits root remote login
Delete anonymous user account
Delete test number

Main server
Compile and install httpd2.4
Before: Install dependent packages
yum -y install gcc pcre -devel openssl-devel expat-devel cc
8, decompression software
[[emailprotected] data]# tar -xvf apr-util-1.6.1.tar.bz2
[[emailprotected] data]# tar -xvf apr-1.7.0.tar.bz2
[[email Protected] data]# tar xvf httpd-2.4.39.tar.bz2
9. Move the pressurized file to the http directory
[[email Protected] data]# mv apr- 1.7.0 httpd-2.4.39/srclib/apr
[[email protected] data]# mv apr-util-1.6.1 httpd-2.4.39/srclib/apr-util
10, http Compile and install under the directory
[[emailprotected] httpd-2.4.39]#./configure --prefix=/app/httpd24 --sysconfdir=/etc/httpd24 --enable-so --enable-ssl- -enable-cgi --enable-rewrite --with-zlib --with-pcre --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork --with-included-apr- -with-included-apr-util
[[emailprotected] data]# make -j 4 && make install

11. Set environment variables
[[emailprotected] data]# echo PATH=/app/httpd24/bin/:$PATH> /etc/profile.d/httpd.sh
[[emailprotected] data]#. /etc/profile.d/httpd.sh
12, set up service script
[[email protected] data]# cp /app/httpd24/bin/apachectl /etc/init.d/httpd
13, start service
service httpd start
install php
12, install related dependency packages
[[emailprotected] data]# yum install libxml2-devel bzip2-devel libmcrypt-devel -y
13, Unzip the file
[[email protected] data]# tar -xvf php-7.3.7.tar.xz

14, compile and install
[[email protected] data]# cd php-7.3.7
[[email protected] php-7.3.7]#
./configure --prefix=/app/php --enable-mysqlnd --with-mysqli=mysqlnd- -with-pdo-mysql=mysqlnd --with-openssl --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr- -with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --enable-mbstring --enable-xml --enable-sockets --enable-fpm- -enable-maintainer-zts --disable-fileinfo

There may be a problem:
Sorry, I cannot run apxs. Possible reasons follow:

1. Perl is not installed
2. apxs was not found. Try to pass the path using --with-apxs2=/path/to/apxs
3. Apache was not built using --enable-so (the apxs usage page is displayed)

The output of /usr/local/apache/bin/ apxs follows:
./configure: line 6669: /usr/local/apache/bin/apxs: No such file or directory
configure: error: Aborting

Solution: Find the existing path of apxs, then modify the apxs2 compilation path
[[email protected] php-7.3.7]# find / -name apxs
/data/httpd-2.4.39/support/apxs< br />/usr/bin/apxs
/app/httpd24/bin/apxs

15、Install
make && make install

Two, Configure fastcgi and httpd to support php


1, copy fpm to the configuration file
cp php.ini-production /etc/php.ini
cp sapi/fpm/ init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
cd /app/php/etc
cp php-fpm.conf.default php-fpm.conf
cp php-fpm.d/www.conf.default php- fpm.d/www.conf
service php-fpm start


[[emailprotected] etc]# vim /etc/httpd24/httpd.conf
1 、Start proxy_fcgi, proxy
Uncomment the following two lines
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
2, modify the following lines

DirectoryIndex index.php index.html

3, modify the following line

DirectoryIndex index.php index.html >> >>>>>>>>General support for php (in normal lamp mode, add the following three)

add the following four lines
AddType application/x-httpd-php .php >>>>>>>>>>>General support php
AddType application/x-httpd-php-source .phps>>>>>>>>>>>>>General support php
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/app/httpd24/htdocs/$1 index.php storage directory
4, verification,< br />rm -rf /app/http24/htdocs/index.html
cat /app/httpd24/htdocs/index.php
$mysqli=new mysqli("127.0 .0.1", "root", "");
if(mysqli_connect_errno()){
echo "Failure";
$mysqli=null;
exit;
}
echo "OK";
$mysqli->close();
?>


phpinfo( );
?>

Verify the screenshot
title

2, Deploy phpMyadmin

Experimental environment: Server: 192.168.37. 10
httpd.x86_64 0:2.4.6-89.el7.centos
mariadb-server.x86_64 1:5.5.60-1.el7_5 php.x86_64 0:5.4.16-46.el7< br /> php-mysql.x86_64 0:5.4.16-46.el7
phpMyAdmin-4.4.15.10-all-languages.tar.xz

1. Deploy the LAMP system and start the service
[[email Protected] ~]# yum -y install httpd mariadb-server php php-mysql
[[email Protected] ~]# systemctl start httpd
[[email Protected] ~] # systemctl start mariadb
2. Initialize Mariadb database
[[emailprotected] pma]# mysql_secure_installation
3. Unzip phpMyadmin and establish a soft link
[[emailprotected] pma]# tar -xvf phpMyAdmin-4.4.15.10-all-languages.tar.xz -C /var/www/html/
[[email Protected] pma]# cd /var/www/html/
[ [email protected] pma]# ln -sv phpMyAdmin-4.4.15.10-all-languages/ pma
[[emailprotected] pma]# cp config.sample.inc.php config.inc.php

4. At this time, login will prompt the lack of mbstring software
[[emailprotected] pma]# yum -y install php-mbstring
systemctl reload httpd

5, test
192.168.37.10/pma

3, build WordPress

Environment: Server 1: apache+php 192.168.37.10 < br /> Server 2: mariadb-server 192.168.37.20 

1, install lamp architecture
yum install php php-mysql httpd -y

2, test php
vim /var/www/html/index.php
echo date("Y/m/d H:i:s");
phpinfo();
?>
3. Modify the wrong time zone
vim /etc/php.ini
date.tomezone=Asia/shanghai
Server 2:
4, Start the service
systemctl start mariadb
5 Set up database creation and account creation
crteate database wordpree
grant all on wordpree.* to [emailprotected]'192.168.37.%' identified by'centos';
flush grant

The client connects to the database
6, mysql -uwruser -pcentos

7, Unzip WordPress (recommended to var/www/html)
tar wordpree-5.0.4-zh_CN.tar.gz -C /data/WordPress
8, set the word configuration file
![title](.local/ static/2019/6/4/1564017791824.1564017791912.png)
or
you can also copy
cp /wordpress/config.simple.ico.conf /var/www/html (can be directly on the page Configuration database)
setfacl -mu:apache:rwx /var/wwww/html/wordpres s
9, cp /data/wordpress /var/www/html
10, test
192.168.37.10/wordress

4, build DISCUZ

lamp to build the same WordPress steps as above

unzip discuz_x3.c.zip
cd dicuz/upload
cp upload /var/www/html/ forum
setfacl -mR u:apache:xrw /var/www/html/forum

Server 2:
greate database ultrax
grant all on ultax.* to [email protected]'192.168.37.%' identified by'centos';

5, PowerDNS build

Deployment environment: Server 1: apache+php 192.168.37.10 
Server 2: mariadb-server 192.168.37.20

1. Installation package: Based on EPEL source
yum install -y pdns pdns-backend-mysql
2. View relevant information
rpm -ql pdsn pdns-
3. Database building, authorization, table building
CREATE DATABASE powerdns;
GRANT ALL ON powerdns.* TO'powerdns '@'192.168.37.%' IDENTIFIED BY'magedu';


CREATE TABLE domains (
id INT AUTO_INCREMENT,
name VARCHAR(255) NOT NULL ,
master VARCHAR(128) DEFAULT NULL,
l ast_check INT DEFAULT NULL,
type VARCHAR(6) NOT NULL,
notified_serial INT DEFAULT NULL,
account VARCHAR(40) DEFAULT NULL,
PRIMARY KEY (id)
>) Engine=InnoDB;

CREATE UNIQUE INDEX name_index ON domains(name);


CREATE TABLE records (
id BIGINT AUTO_INCREMENT,
domain_id INT DEFAULT NULL,
name VARCHAR(255) DEFAULT NULL,
type VARCHAR(10) DEFAULT NULL,
content VARCHAR(64000) DEFAULT NULL,
ttl INT DEFAULT NULL,
prio INT DEFAULT NULL,
change_date INT DEFAULT NULL,
disabled TINYINT(1) DEFAULT 0,
ordername VARCHAR(255) BINARY DEFAULT NULL,
auth TINYINT(1) DEFAULT 1,
PRIMARY KEY (id)
) Engine=InnoDB;

CREATE INDEX nametype_index ON r ecords(name,type);
CREATE INDEX domain_id ON records(domain_id);
CREATE INDEX recordorder ON records (domain_id, ordername);


CREATE TABLE supermasters (
ip VARCHAR(64) NOT NULL,
nameserver VARCHAR(255) NOT NULL,
account VARCHAR(40) NOT NULL,
PRIMARY KEY (ip, nameserver)
) Engine=InnoDB;


CREATE TABLE comments (
id INT AUTO_INCREMENT,
domain_id INT NOT NULL,
name VARCHAR(255) NOT NULL,
type VARCHAR(10) NOT NULL,
modified_at INT NOT NULL,
account VARCHAR(40) NOT NULL,
comment VARCHAR(64000) NOT NULL,
PRIMARY KEY (id)
) Engine=InnoDB;

CREATE INDEX comments_domain_id_idx ON comments (domain_id);
CREATE INDEX comments_name_type_idx ON comments (name, type);
CREATE INDEX comments_order_idx ON comments (domain_id, modified_at);


CREATE TABLE domainmetadata (
id INT AUTO_INCREMENT,
domain_id INT NOT NULL,
kind VARCHAR(32),
content TEXT,
PRIMARY KEY (id)
) Engine=InnoDB;

CREATE INDEX domainmetadata_idx ON domainmetadata (domain_id, kind);


CREATE TABLE cryptokeys (
id INT AUTO_INCREMENT,
domain_id INT NOT NULL,
flags INT NOT NULL,
active BOOL,
content TEXT,
PRIMARY KEY(id)
) Engine=InnoDB;

CREATE INDEX domainidindex ON cryptokeys(domain_id);


CREATE TABLE tsigkeys (
id INT AUTO_INCREMENT,
name VARCHAR(255),
algorithm VARCHAR(50),
secret VARCHAR(255),
PRIMARY KEY (id)
) Engine=InnoDB;
CREATE UNIQUE INDEX namealgoindex ON tsigkeys(name, algorithm);

4. Configure Powersna main file

vim /etc/pdn/pdns.conf
launch=gmysql
gmysql-host=192.168.37.17
gmysql-port=3306
gmysql-dbname=powerdns
gmysql-user=powerdns
gmysql -password=magedu
5, start the service
systemctl start pdns
systemctl enable pdns

6, install the service
install httpd and php related packages
yum -y install httpd php php-devel php-gd php-mcrypt php-imap php-ldap php-mysql php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-mhash gettext
7. Start the service
systemctl start httpd
systemctl enable httpd

8. Download the poweradmin program and unzip it to the corresponding directory
cd /var/www/ html
wget http://downloads.sourceforge.net/project/poweradmin/poweradmin-2.1.7.tgz

9, unzip to /var/www/html
tar xvf poweradmin-2.1.7.tgz -C /var/www/html/poweradmin

1, realize mariadb

Compile and install mariadb
chown -R rootroot mysql/< br />
craeate data base wordress
grant all on wordpress.* to [email protected]'192.168.37.%' identifit by'centos'

6. Deploy xcache module-accelerated access

1 , Installation method:
(1) Yum source direct installation: from epel source
(2) Compile and install
Example:

Environment: Main server: 192.168.37.10 centos7.6< br /> Client: 192.168.37.20 centos7.6
Main service node:
1. Install xcache dependency tools
[[emailprotected] ~]# yum install php-devel gcc cc< br />2, unzip
[[email protected] data]# tar -xvf xcache-3.2.0.tar.gz
3, generate the compilation environment
[[email protected] data] # cd xcache-3.2.0
[[emailprotected] xcache-3.2.0]# phpize --clean && phpize
4, compile
[[emailprotected] xcache-3.2.0 ]# ./configure --enable-xcache
[[email protected] xcache-3.2.0]# make && make install
5. Copy the configuration file to the php configuration directory
[[ email protected] xcache-3.2.0]# cp xcache.ini /etc/php.d/
[[email protected] xcache-3.2.0]# systemctl start httpd
Client node:
6. Test
[[emailprotected] ~]# ab -c 120 -n 1000 192.168.37.10/messages
[[emailprotected] ~]# ab -c 120 -n 1000 192.168. 37.10/messages.php

7, fastcgi

The full name of FastCGI is Fast Common Gateway Interface (FastCommonGatewayInterface).
FastCGI is like a long-live CGI, it can be executed all the time, as long as it is activated, it will not take time to fork every time (this is the most criticized fork-and of CGI -execute mode). It also supports distributed computing, that is, FastCGI programs can be executed on hosts other than the web server and accept requests from other web servers.
FastCGI is a language-independent, scalable architecture CGI open extension. Its main behavior is to keep the CGI interpreter process in memory and thus obtain higher performance. As we all know, the repeated loading of the CGI interpreter is the main reason for the low performance of CGI. If the CGI interpreter is kept in memory and is scheduled by the FastCGI process manager, it can provide good performance, scalability, fail-over features, etc.

(1)Principle

1. Load FastCGI process manager (IIS ISAPI or Apache Module) when Web Server starts.
2. FastCGI process manager itself Initialization, start multiple CGI interpreter processes (see multiple php-cgi) and wait for the connection from the Web Server.
3. When a client request arrives at the Web Server, the FastCGI process manager selects and connects to a CGI interpreter. The Web server sends the CGI environment variables and standard input to the FastCGI subprocess php-cgi.
4. After the FastCGI sub-process completes the processing, it returns the standard output and error information from the same connection to the Web Server. When the FastCGI child process closes the connection, the request is processed. The FastCGI child process then waits and processes the next connection from the FastCGI process manager (running in the Web Server). In CGI mode, php-cgi exits here.

(2) fastcgi configuration

fcgi service configuration file: /etc/php-fpm.conf, /etc/php-fpm.d/*. conf
Official document: http://php.net/manual/zh/install.fpm.configuration.php
Connection pool: pm = static|dynamic
static: a fixed number of child processes; pm. max_children
dynamic: The number of child processes is managed in a dynamic mode, the default value is
pm.max_children = 50
pm.start_servers =5
pm.min_spare_servers =5
pm.max_spare_servers =35
pm.max_requests = 500 The number of requests that each process can handle
Make sure that the user running the php-fpm process has read and write permissions to the session directory
mkdir /var/lib/php/session
chown apache. apache /var/lib/php/session

(1) Configure httpd
Add /etc/httpd/conf.d/fcgi.conf configuration file, the content is similar< /p>

DirectoryIndex index.php
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/html/$1
UDS (unix domain socket) method
ProxyPassMatch ^/(.*\.php)$ unix:/var/run/php.sock|fcgi://localhost/app/httpd24/htdocs/$1
See: http://httpd.apache.org/docs/2.4/mod/mod_proxy_fcgi.html
Note: The proxy_fcgi_module module must be enabled on the HTTPD server to act as a PHP client
httpd –M | grep fcgi
cat /etc/ httpd/conf.modules.d/00-proxy.conf

2) Virtual host configuration

vim /etc/httpd/conf.d/vhosts .conf
DirectoryIndex index.php

ServerName www.b.net
DocumentRoot /apps/vhosts/b.net
ProxyRequests Off< br />ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/apps/vhosts/b.net/$1

Options None
AllowOverride None
Require all granted

Leave a Comment

Your email address will not be published.