Detailed description of LAMP service architecture

Keywords: Linux PHP MySQL Apache MariaDB

Introduction to LAMP

LAMP: Short for Linux Apache MySQL PHP, which installs Apache, MySQL and PHP on Linux system to form an environment to run PHP scripting language, usually a website.

Apache is the most commonly used web service software, while MySQL is a relatively small database software. Both software and PHP can be installed on one machine or separately. When Apache and PHP can be installed on the same machine, PHP exists as a module of Apache, and apxs is a tool of httpd, because it can automatically install the PHP module into Mod of httpd. Under the ules directory, that is to say, PHP will work together as a module with httpd. It can also be installed on different machines, where PHP exists as a reverse proxy for the server.

a: apache (httpd): receives users'web requests; static resources respond directly; dynamic resources are PHP scripts, requests for such resources will be run by php;

m: mysql, mariadb: data management system

p: php, perl, python: run PHP programs

The way http combines with php:

FastCGI (Server Independent)

Modules (compiling php into httpd modules)

2. Practical jobs: Deploy lamp to install wordpress, phpwind, discuz on the virtual host; (centos7 as an example)

Dead work:
<1. All software installation uses yum

Modules: package, httpd, php, php-mysql, mariadb-server

FastCGI: Package, httpd, php-fpm, php-mysql, mariadb-server

<2. Close iptables and selinux on all hosts to prevent the experiment from proceeding smoothly. Execute the following commands:

[root@centos7 ~]# systemctl stop firewalld
[root@centos7 ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@centos7 ~]# setenforce 0
[root@centos7 ~]# vim /etc/selinux/config 
SELINUX=disabled

1. Building wordpress blog Based on lamp

httpd-server host:

<1. Configure httpd configuration file

[Note] There is no need to modify the main configuration file of httpd under CentOS 7, because in CentOS 7, the configuration file of httpd host is disabled by default when the virtual host exists (httpd host is disabled under CentOS 6 to enable the virtual host function by annotating the Document Root line of the httpd main configuration file), so you can directly enter the new and compiled files under the / etc/httpd/conf.d / directory. Just edit the virtual host configuration file

[root@centos7 ~]# yum -y install httpd php mariadb-server php-mysql
[root@centos7~]# systemctl stop firewalld; setenforce 0

Create and edit the virtual host configuration file

[root@centos7 ~]# vim /etc/httpd/conf.d/vhost.conf 
</VirtualHost>
<VirtualHost *:80>
ServerName  blog.magedu.com
DocumentRoot "/app/blog/htdocs"
CustomLog "logs/blog.magedu.com_access_log" combined
ErrorLog "logs/blog.magedu.com_error_log" 
<Directory "/app/blog/htdocs">
Require all granted
</Directory>
</VirtualHost>

Restart service

[root@centos7~]# systemctl restart httpd

Edit mysql master configuration file

[root@centos7 ~]# vim /etc/my.cnf
[mysqld]
skip_name_resolve                       //Skip domain name resolution

Restart database services

[root@centos7 ~]# systemctl restart mariadb

Create a shared resource directory

[root@centos7 blog]# mkdir -pv /app/blog

Install wordpress program files to this directory and set their configuration files

[root@centos7 blog]# tar xvf wordpress-4.9.4-zh_CN.tar.gz -C /app/blog/
[root@centos7 blog]# mv wordpress wordpress-4.9.4

Create soft links

[root@centos7(nanyibo) blog]# ln -sv wordpress-4.9.4 htdocs
[root@centos7(nanyibo) blog]# ll
total 4
lrwxrwxrwx. 1 root   root        15 Oct 19 15:32 htdocs -> wordpress-4.9.4
drwxr-xr-x. 5 nobody nfsnobody 4096 Feb  8  2018 wordpress-4.9.4

Setting permissions for shared directories

[root@centos7 ~]# cd /app/blog/
[root@centos7 blog]# setfacl -m u:apache:rwx htdocs/

Note: Because in the httpd virtual host configuration file, it is decided whether to use php-fpm proxy or not according to whether the file name suffix of the resource requested by the client is ".php", which has nothing to do with the content of the file suffixed with ".php", there is no need to modify the configuration file in wordpress file, and there is no need for content in index.php file, just corresponding at the php-fpm proxy server side. You can specify the contents in the file.

Enter mysql client and create users, databases, tables and fields

[root@centos7 ~]# mysql
MariaDB [(none)]> create database wpdb;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all on wpdb.* to 'wpuser'@'192.168.153.%' identified by 'wppass';
Query OK, 0 rows affected (0.02 sec)

Enter the domain name blog.magedu.com in the browser and start installation

Note: Don't add anything extra to the mysql configuration file. I added read_only to my mysql master-slave experiment, and the result was that the database could not be read-only and the line needed to be commented out.

2. Building PHP myadmin and discuz based on lamp of php-fpm mode

[root@centos7 ~]# yum -y install httpd php-fpm php-mysql mariadb-server

Setting up proxy profile

[root@centos7~]# vim /etc/php-fpm.d/www.conf
listen = 0.0.0.0:9000                                      Fill in the host's IP address(Cannot write 127.0.0.1),Port is mandatory
listen.allowed_clients = 172.18.254.202 ==>                     Fill in the proxy here. httpd Host of the service IP address
[root@centos7 ~]# mkdir /var/lib/php/session

Modify authority

[root@centos7 ~]# chown apache.apache /var/lib/php/session

Restart service

[root@centos7 ~]# systemctl restart php-fpm
[root@centos7 ~]# ss -ntl |grep 9000
LISTEN     0      128          *:9000                     *:*

Edit and modify configuration files

[root@centos7 ~]# vim /etc/httpd/conf.d/pma.conf
DirectoryIndex index.php                
<VirtualHost *:80>                      
ServerName pma.magedu.com
DocumentRoot /vhosts/pam/htdocs
ProxyRequests Off                                //Close the Forward Agent
ProxyPassMatch ^/(.*\.php)$  fcgi://172.18.254.202:9000/vhosts/pam/htdocs/$1*/ pattern matching its content
<Directory "/vhosts/pam/htdocs">
Options None                                            
AllowOverride None                                      
Require all granted                                     
</Directory>                                    
</VirtualHost>       
[root@centos7 ~]# cd /vhosts/pam/

Install the phpMyAdmin program file to this directory and set its configuration file

[root@centos7 pam]# unzip phpMyAdmin-4.0.10.20-all-languages.zip
[root@centos7 pam]# ln -sv phpMyAdmin-4.0.10.20-all-languages htdocs
'htdocs' -> 'phpMyAdmin-4.0.10.20-all-languages'
[root@centos7 pam]# ll
total 4
lrwxrwxrwx. 1 root root   34 Oct 19 17:27 htdocs -> phpMyAdmin-4.0.10.20-all-languages
drwxr-xr-x. 9 root root 4096 Mar 28  2017 phpMyAdmin-4.0.10.20-all-languages
[root@centos7 htdocs]# cp config.sample.inc.php config.inc.php 
[root@centos7 htdocs]# vim config.inc.php
$cfg['Servers'][$i]['host'] = '172.18.254.202';
[root@centos7 htdocs]# yum -y install php-mbstring
[root@centos7 htdocs]# systemctl restart php-fpm
[root@centos7 htdocs]# mysql
MariaDB [(none)]> grant all on *.* to 'root'@'172.18.254.202' identified by 'magedu' with grant option;                
Query OK, 0 rows affected (0.00 sec)

Note: with grant option: Authorized users can re-authorize

Enter pma.magedu.com through the browser to access phpmyadmin and log in with the account created above.

Install discuz

[root@centos7 ~]# cd /etc/httpd/conf.d
[root@centos7 conf.d]# cp pma.conf bbs.conf
[root@centos7 conf.d]# vim bbs.conf 
DirectoryIndex index.php
<VirtualHost *:80>
ServerName bbs.magedu.com
DocumentRoot /vhosts/bbs/htdocs
ProxyRequests Off                           //Close the Forward Agent
ProxyPassMatch ^/(.*\.php)$  fcgi://172.18.254.202:9000/vhosts/bbs/htdocs/$1*//pattern matching its content
<Directory "/vhosts/bbs/htdocs">
Options None
AllowOverride None
Require all granted
</Directory>
</VirtualHost>

Modification in windows hosts

172.18.254.202 bbs.magedu.com

[root@centos7 conf.d]# mkdir /vhosts/bbs -pv
mkdir: created directory '/vhosts/bbs'
[root@centos7 ~]# mkdir /vhosts/bbs/discuz-x3.3
[root@centos7 ~]# mv Discuz_X3.3_SC_UTF8.zip /vhosts/bbs/discuz-x3.3
[root@centos7~]# cd /vhosts/bbs/discuz-x3.3
[root@centos7 discuz-x3.3]# unzip Discuz_X3.3_SC_UTF8.zip 
[root@centos7 ~]# cd /vhosts/bbs/

Shared forum resources are in the upload directory, so you just need to put them in this directory.

[root@centos7 bbs]# ln -s discuz-x3.3/upload htdocs
[root@centos7 bbs]# ll
total 0
drwxr-xr-x. 5 root root 80 Oct 19 17:41 discuz-x3.3
lrwxrwxrwx. 1 root root 18 Oct 19 17:42 htdocs -> discuz-x3.3/upload
[root@centos7 bbs]# setfacl -R -m u:apache:rwx htdocs/

Create database and user authorization for discuz through phpmyadmin. Then enter bbs.magedu.com on the browser to install discuz

Editing windows hosts

win+r Open Run: Notepad C:\WindowsSystem32driversetchosts

172.18.254.202 bbs.magedu.com

Enter the domain name bbs.magedu.com in the browser to start installation and login.

Posted by nuttynibbles on Mon, 28 Jan 2019 08:48:14 -0800