Linux Phase 9: Interim Architecture LNMP Chapter

Keywords: Linux MySQL PHP libiconv Nginx

IX. Interim Framework LNMP Chapter

(1) Description of the LNMP architecture

1) Concatenate front-end web services with back-end storage services
 2) Mainly implements handling PHP program dynamic requests	

(2) How the LNMP architecture works

 L Linux  N nginx M mysql P php

(3) LNMP Architecture Deployment

1) Install LNMP related software

1. Deploy Linux system
Basic tuning operation to complete (firewall shutdown selinux/tmp permission 1777)
(2) Deploying nginx services
See previous chapter
3. Deploy mysql service
yum deploy software, compile and install software, binary package deploy mysql service

First mileage: download and unzip the mysql software program

The official download link for MySQL is ftp://ftp.jaist.ac.jp/pub/mysql/Downloads/MySQL-5.6/
Upload mysql software program for upload using xftp software
tar xf mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz
mv mysql-5.6.34-linux-glibc2.5-x86_64 /application/mysql-5.6.34

Second mileage: Create software program soft links

ln -sf /application/mysql-5.6.34/ /application/mysql

Third milestone: Create database management users and authorize data catalogs

useradd mysql -M -s /sbin/nologin 
chown -R mysql.mysql /application/mysql/data/

Fourth mileage: Initializing database services

/application/mysql/scripts/mysql_install_db --basedir=/application/mysql --datadir=/application/mysql/data/ --user=mysql

Fifth mileage: Start mysql service

cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld
sed -ri 's#/usr/local#/application#g' /etc/init.d/mysqld /application/mysql/bin/mysqld_safe
cp /application/mysql/support-files/my-default.cnf /etc/my.cnf
/etc/init.d/mysqld start

Sixth mileage: set the database root user login password

/application/mysql/bin/mysqladmin -uroot password "oldboy123"
/application/mysql/bin/mysql -uroot -poldboy123

IV. PHP software installation and deployment process

Mileage 1: Solving PHP software dependencies

 yum install -y zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel

 libiconv Software Installation---Character Set Conversion Library(Installation is not allowed by default)
 cd /server/tools
 #wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
 tar zxf libiconv-1.14.tar.gz
 cd libiconv-1.14
 ./configure --prefix=/usr/local/libiconv
 make
 make install
 cd ../

 #wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
 yum -y install libmcrypt-devel mhash mcrypt
 rpm -qa libmcrypt-devel mhash mcrypt

Second mileage: download the decompressed PHP software

php Official website download: php.net
cd /server/tools/
tar xf php-5.5.32.tar.gz
cd php-5.5.32
./configure \
--prefix=/application/php-5.5.32 \
--with-mysql=/application/mysql-5.6.34 \
--with-pdo-mysql=mysqlnd \
--with-iconv-dir=/usr/local/libiconv \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--with-mcrypt \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-soap \
--enable-short-tags \
--enable-static \
--with-xsl \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-ftp \
--enable-opcache=no

##Error proof (the following information may not be configured)
ln -s /application/mysql/lib/libmysqlclient.so.18  /usr/lib64/
touch ext/phar/phar.phar
make
make install
ln -s /application/php-5.5.32/ /application/php


Third mileage: set PHP program profile

 php.ini php-fpm.ini
 cp php.ini-production /application/php-5.5.32/lib/
cd /application/php/etc/
cp php-fpm.conf.default php-fpm.con

Fourth mileage: start php program service

/application/php/sbin/php-fpm
netstat -lntup|grep php
 tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      6251/php-fpm

2) Direct software integration

	   nginx and php Combining: Writing nginx configuration file
	   location ~* .*\.(php|php5)?$ {
          fastcgi_pass  127.0.0.1:9000;
          fastcgi_index index.php;
          include fastcgi.conf;
       }
	   
	   php and mysql Combining: Writing php Program Code
	   <?php
           //$link_id=mysql_connect('host name','user','password');
           //Mysql-u user-p password-h host
           $link_id=mysql_connect('localhost','root','oldboy123') or mysql_error();
           if($link_id){
                        echo "mysql successful by oldboy !\n";
                       }else{
                        echo mysql_error();
                       }
       ?>

3) Deploy a real website

First mile: download and upload website code

Second milestone: Unzip the program code, save it to the site directory, and authorize it

 tar xf wordpress-4.7.3-zh_CN.tar.gz 
 mv wordpress/* /application/nginx/html/blog/
 chown -R www.www /application/nginx/html/blog/

Third mileage: Visit the blog site directly for initialization

 Create a database:
 create database wordpress;
 show databases;
Create Connection Data User Information
grant all on wordpress.* to 'wordpress'@'localhost' identified by 'oldboy123';
select user,host from mysql.user;

Posted by Jarod on Sun, 03 May 2020 22:12:49 -0700