基于Module和Fastcgi实现LAMP架构!

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_43551152/article/details/86421291

 

实验环境

实验在192.168.245.17上安装apache,php-mysql,php,mariadb.server

并创建数据库,用户名,密码

Module(模块)模式实现wordpress,phpmyadmin,discuz

  1. 布署phpMyadmin

192.168.245.27上创建登陆账户

MariaDB [(none)]> grant all on *.* to test@'192.168.245.%' identified by 'centos';

下载phpMyAdmin-4.0.10.20-all-languages.tar.xz(https://www.phpmyadmin.net/)

将phpMyAdmin-4.0.10.20-all-languages.tar.xz传到虚拟机/data/www目录解压

cd /data/www/

此目录为httpd网页路径,可修改/etc/httpd/conf/httpd.conf选项DocumentRoot "/data/www",指定网页存放路径

[root@centos7 www]#tar xvf phpMyAdmin-4.0.10.20-all-languages.tar.xz

扫描二维码关注公众号,回复: 6203984 查看本文章

[root@centos7 www]#mv phpMyAdmin-4.0.10.20-all-languages pma

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

[root@centos7 www]#rpm -q php php-mysql mariadb-server httpd

php-5.4.16-45.el7.x86_64

php-mysql-5.4.16-45.el7.x86_64

mariadb-server-5.5.56-2.el7.x86_64

httpd-2.4.6-80.el7.centos.x86_64

[root@centos7]#cd pma/

[root@centos7 pma]#cp config.sample.inc.php config.inc.php

[root@centos7 pma]#vim config.inc.php

[root@centos7 pma]#vim config.inc.php

修改默认的密码

$cfg['blowfish_secret'] = 'a8b7c6ddsdasda';

[root@centos7 pma]#yum install php-mbstring

[root@centos7 pma]#systemctl restart httpd

打开浏览器http://192.168.245.17/pma/

默认账号密码为数据库的root centos

 

 

 

  1. 布署wordpress

下载wordpress,部署wordpress博客,官网https://cn.wordpress.org/download/

[root@centos7 www]#rz

rz waiting to receive.

Starting zmodem transfer.  Press Ctrl+C to cancel.

Transferring wordpress-5.0-zh_CN.zip...

  100%   11685 KB    11685 KB/sec    00:00:01       0 Errors 

[root@centos7 www]#unzip wordpress-5.0-zh_CN.zip

[root@centos7 www]#cd wordpress/

[root@centos7 wordpress]#mv wp-config-sample.php wp-config.php

改配置文件名字

[root@centos7 wordpress]#vim wp-config.php

修改配置文件,输入上面创建的数据库名称和密码

define('DB_NAME', 'wordpress');

/** MySQL数据库用户名 */

define('DB_USER', 'wpuser');

 

/** MySQL数据库密码 */

define('DB_PASSWORD', 'centos');

 

/** MySQL主机 */

define('DB_HOST', '192.168.245.17');

 

大功告成

打开浏览器,输入http://192.168.245.17/wordpress/,安装wordpress

博客站点完成

 

输入账号密码

 

  1. discuz论坛搭建与部署

Discuz_X3.3_SC_UTF8.zip

[root@centos7 wordpress]#cd /data/www

此目录为httpd网页路径,可见/etc/httpd/conf/httpd.conf选项DocumentRoot "/data/www",指定网页存放路径

[root@centos7 www]# rz

rz waiting to receive.

Starting zmodem transfer.  Press Ctrl+C to cancel.

Transferring Discuz_X3.3_SC_UTF8.zip...

  100%   10666 KB    10666 KB/sec    00:00:01       0 Errors

[root@centos7 www]#unzip Discuz_X3.3_SC_UTF8.zip

[root@centos7 www]#cd upload/

打开浏览器,输入http://192.168.245.17/upload/,安装

 

文件目录没有权限修改权限

[root@centos7 upload]#cd ..

[root@centos7 www]#setfacl -R -m u:apache:rwx upload/

刷新浏览器页面

 

密码全为centos

点击最下面的进入论坛,输入admin centos登陆

安装完成

 

fastcgi模式实现wordpress,phpMyAdmin,discuz

实验:源码编译LAMP,实现fastcgi模式

环境:

apr-1.6.5.tar.bz2

apr-util-1.6.1.tar.bz2

httpd-2.4.37.tar.bz2

mariadb-10.2.19-linux-x86_64.tar.gz

php-7.1.18.tar.bz2

wordpress-4.9.4-zh_CN.tar.gz

 

 

1 准备apache

useradd -r -s /sbin/nologin apache

 

./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

 

 

2 准备mysql

 

3 准备php

yum install libxml2-devel bzip2-devel libmcrypt-devel

 

tar xvf php-7.1.7.tar.bz2

cd php-7.1.7/

./configure --prefix=/app/php \

--enable-mysqlnd \

--with-mysqli=mysqlnd \

--with-openssl \

--with-pdo-mysql=mysqlnd \

--enable-mbstring \

--with-freetype-dir \

--with-jpeg-dir \

--with-png-dir \

--with-zlib \

--with-libxml-dir=/usr \

--enable-xml \

--enable-sockets \

--enable-fpm \

--with-config-file-path=/etc \

--with-config-file-scan-dir=/etc/php.d \

--enable-maintainer-zts \

--disable-fileinfo

 

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

 

 

4 修改httpd支持php

vim /app/httpd24/conf/httpd.conf

取消下面两行的注释

LoadModule proxy_module modules/mod_proxy.so

LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

修改下面行

<IfModule dir_module>

DirectoryIndex index.php index.html

</IfModule>

加下面四行

AddType application/x-httpd-php .php

AddType application/x-httpd-php-source .phps

ProxyRequests Off

ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/app/httpd24/htdocs/$1

 

步骤同上,不过是将apache服务、fastcgi服务、数据库分别放在单独的主机上进行分离

主机192.168.245.17  安装apache提供httpd

主机192.168.245.27  安装php-fpm php-mysql

主机192.168.245.37  mariadb

 

1.主机192.168.245.17创建配置文件fcgi.conf指向27上的php

vim /etc/httpd/conf.d/fcgi.conf

写入

DirectoryIndex index.php

ProxyRequests Off

ProxyPassMatch ^/(.*\.php)$ fcgi://192.168.245.27:9000/data/html/$1

2.主机192.168.245.27上修改fpm配置文件,指向37上的服务器

vim /etc/php-fpm.d/www.conf

将listen = 127.0.0.1:9000 改为listen = 9000

将listen.allowed_clients = 127.0.0.1前面加#注释掉

[root@centos7 ~]#mkdir /data/html

[root@centos7 ~]#cd /data/html

[root@centos7 html]#vim pdo.php

<?php

try {

$user='test';

$pass='centos';

$dbh = new PDO('mysql:host=192.168.245.37;dbname=mysql', $user, $pass);                                 

foreach($dbh->query('SELECT user,host,password from user') as $row) {

print_r($row);

}

$dbh = null;

} catch (PDOException $e) {

print "Error!: " . $e->getMessage() . "<br/>";

die();

}

?>

[root@centos7 html]#systemctl restart httpd

 

3.主机192.168.245.37  安装数据库,并创建用户

[root@centos7 ~]#mysql

创建用户

MariaDB [(none)]> grant all on *.* to test@'192.168.245.%' identified by 'centos';

 

猜你喜欢

转载自blog.csdn.net/weixin_43551152/article/details/86421291