LAMP架构

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LAMP架构相关的知识,希望对你有一定的参考价值。

基于源码编译FCGI的模式的LAMP的wordpress和discuz!的多虚拟主机
1、准备

环境:一台主机apache,fgci服务器,一台主机mysql server  
软件版本:mariadb-10.2.23-linux-x86_64.tar.gz  
         apr-1.7.0.tar.gz  
         apr-util-1.6.1.tar.gz  
         httpd-2.4.39.tar.bz2  
         php-7.3.5.tar.bz2  
         wordpress-5.2.tar.gz  
         Discuz_X3.3_SC_UTF8.zip  

2、编译安装httpd

主机A:192.168.2.6

    -、下载软件
[[email protected] data]# yum -y install gcc pcre-devel openssl-devel expat-devel autoconf libtool gcc-c++

[email protected] ~]# wget http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.39.tar.bz2

[[email protected] ~]# wget http://mirror.bit.edu.cn/apache//apr/apr-1.7.0.tar.bz2

[[email protected] ~]# wget http://mirror.bit.edu.cn/apache//apr/apr-util-1.6.1.tar.bz2

    -、解压
[[email protected] data]# tar -xvf httpd-2.4.39.tar.bz2
[[email protected] data]# tar xvf apr-1.7.0.tar.bz2
[[email protected] data]# tar xvf apr-util-1.6.1.tar.bz2 

    -、合并文件到httpd-2.4.39
[[email protected] data]# cp -r apr-1.7.0 httpd-2.4.39/srclib/apr
[[email protected] data]# cp -r apr-util-1.6.1 httpd-2.4.39/srclib/apr-util

    -、设置功能特性,开始编译
[[email protected] httpd-2.4.39]# ./configure > --prefix=/app/httpd24 > --enable-so > --enable-ssl > --enable-cgi > --enable-rewrite > --with-zlib > --with-pcre > --with-included-apr > --enable-modules=most > --enable-mpms-shared=all > --with-mpm=prefork 
[[email protected] httpd-2.4.39]# make -j 4 && make install

    -、加入环境变量,启动服务
[[email protected] httpd-2.4.39]# vim /etc/profile.d/httpd24.sh
PATH=/app/httpd24/bin:$PATH
[[email protected] ~]# . /etc/profile.d/httpd24.sh
[[email protected] ~]# apachectl start
[[email protected] ~]# ll /app/httpd24/htdocs/index.html   #主页面位置

    -浏览器访问测试
http://192.168.2.6/

    -、设置开机启动
[[email protected] conf]# ll /etc/rc.d/rc.local 
-rwxr-xr-x. 1 root root 236 May 12 10:05 /etc/rc.d/rc.local     #赋予执行权限
[[email protected] conf]# vim /etc/rc.d/rc.local
/app/httpd24/bin/apachectl start

    -、创建apache账号,供apache软件使用
[[email protected] ~]# useradd -r -s /sbin/nologin apache
[[email protected] ~]# vim /app/httpd24/conf/httpd.conf    #修改配置
User apache    #172行
Group apache    #173行

    -修改配置文件
[[email protected] ~]# vim /app/httpd24/conf/httpd.conf 
User apache         #172行
Group apache        #173行

LoadModule proxy_module modules/mod_proxy.so    #120行
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so  #124行
DirectoryIndex index.php index.html     #261行加入.php
AddType application/x-httpd-php .php    #尾部添加
AddType application/x-httpd-php-source .phps

<virtualhost *:80>
documentroot /data/wordpress
servername blog.huahua.com
ProxyRequests off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/data/wordpress/$1
<directory /data/wordpress>
require all granted
</directory>
</virtualhost>

<virtualhost *:80>
documentroot /data/discuz
servername forum.huahua.com
ProxyRequests off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/data/discuz/$1
<directory /data/discuz>
require all granted
</directory>
</virtualhost>

[[email protected] ~]# apachectl restart

3、编译安装基于fcgi的php

主机A:192.168.2.6
    -安装依赖包
[[email protected] data]# yum -y install libxml2-devel bzip2-devel libmcrypt-devel

    -解压缩
[[email protected] data]# tar xvf php-7.3.5.tar.bz2
[[email protected] data]# cd php-7.3.5

    -编译安装
[[email protected] php-7.3.5]# ./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
[[email protected] php-7.3.5]# make && make install

    -准备ini配置文件
[[email protected] php-7.3.5]# cp php.ini-production /etc/php.ini
[[email protected] php-7.3.5]# vim /etc/php.ini
date.timezone = "Asia/Shanghai"     #960行时区

[[email protected] php-7.3.5]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm                  #服务脚本
[[email protected] php-7.3.5]# chmod +x /etc/init.d/php-fpm 

[[email protected] php-7.3.5]# cd /app/php/etc      #进入编译路径
[[email protected] etc]# cp php-fpm.conf.default php-fpm.conf      #使配置文件生效
[[email protected] etc]# cd php-fpm.d/
[[email protected] php-fpm.d]# cp www.conf.default www.conf      #使配置文件生效

[[email protected] php-fpm.d]# vim www.conf
user = apache           #23行
group = apache          #24行
listen = 127.0.0.1:9000

[[email protected] data]# service php-fpm restart

4、二进制安装mariadb-server

主机B:192.168.2.16
    -解压到/usr/local/
[[email protected] ~]# tar xvf mariadb-10.2.23-linux-x86_64.tar.gz -C /usr/local/

    -进入目录
[[email protected] ~]# cd /usr/local/

    -创建软连接
[[email protected] local]# ln -s mariadb-10.2.23-linux-x86_64/ mysql

    -更改所有者,所属组
[[email protected] local]# chown -R root:root mysql/

    -创建用户、家目录
[[email protected] local]# useradd -r -s /sbin/nologin mysql -d/data/mysql
[[email protected] local]# mkdir /data/mysql -p
[[email protected] local]# chown mysql:mysql /data/mysql

    -运行脚本,指定数据存放位置
/usr/local/mysql/scripts/mysql_install_db
[[email protected] mysql]# scripts/mysql_install_db --user=mysql --datadir=/data/mysql

    -创建配置文件
[[email protected] mysql]# mkdir /etc/mysql/
[[email protected] mysql]# pwd
/usr/local/mysql
[[email protected] mysql]# cp support-files/my-huge.cnf /etc/mysql/my.cnf
[[email protected] mysql]# vim /etc/mysql/my.cnf
[mysqld]
datadir=/data/mysql         #在mysqld加入数据路径  

    -作启动脚本
[[email protected] mysql]# pwd
/usr/local/mysql
[[email protected] mysql]# cp support-files/mysql.server /etc/init.d/mysqld

    -加入chkconfig
[[email protected] mysql]# chkconfig --add mysqld

    -加入PATH环境变量
[[email protected] mysql]# vim /etc/profile.d/lamp.sh
PATH=/usr/local/mysql/bin:$PATH
[[email protected] mysql]# . /etc/profile.d/lamp.sh

    -启动服务
[[email protected] mysql]# service mysqld start
[[email protected] mysql]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.2.23-MariaDB-log MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

MariaDB [(none)]> 

    -跑安全加固脚本
[[email protected] mysql]# mysql_secure_installation

    -建库
MariaDB [(none)]> create database wordpress;

    -建授权账号
MariaDB [(none)]> grant all on wordpress.* to [email protected]‘192.168.2.6‘ identified by ‘123456‘;
Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> grant all on ultrax.* to [email protected]‘192.168.2.6‘ identified by ‘123456‘;

5、准备相关php程序文件

    -解压wordpress、Discuz
[[email protected] data]# tar xvf wordpress-5.2.tar.gz
[[email protected] data]# unzip Discuz_X3.3_SC_UTF8.zip

    -配置wordpress
[[email protected] data]# cd wordpress
[[email protected] wordpress]# cp -r wp-config-sample.php wp-config.php
[[email protected] wordpress]# vim wp-config.php       #连接数据库
/** The name of the database for WordPress */
define( ‘DB_NAME‘, ‘wordpress‘ );

/** MySQL database username */
define( ‘DB_USER‘, ‘wpuser‘ );

/** MySQL database password */
define( ‘DB_PASSWORD‘, ‘123456‘ );

/** MySQL hostname */
define( ‘DB_HOST‘, ‘192.168.2.16‘ );

/** Database Charset to use in creating database tables. */
define( ‘DB_CHARSET‘, ‘utf8‘ );

/** The Database Collate type.

    -配置Discuz!:
[[email protected] data]# mv upload/ discuz
[[email protected] data]# setfacl -R -m u:apache:rwx /data/discuz/

以上是关于LAMP架构的主要内容,如果未能解决你的问题,请参考以下文章

基础运维终章:深入浅出LAMP架构

linux下Yum搭建lamp网站架构

LAMP的基本配置

ansible roles详解+搭建LAMP架构

lamp架构-访问控制-禁止php解析屏蔽curl命令访问

LAMP架构搭建以及基于LAMP架构的主流论坛和博客搭建过程详解