动静分离LNMP
创始人
2024-02-15 12:13:46
0

目录

安装LNMP

搭建wordpress

搭建WeCenter


        根据需求实现动静分离,当客户端访问nginx网站服务时,静态网页nginx本机反馈,动态网页访问PHP,所以需要在nginx服务器中部署论坛后需要拷贝到PHP服务器中。但是如果有NFS或GFS服务器时可以把nginx和php指定文件服务器。

 

安装LNMP

  • 安装nginx 

        所需安装包如下:

 

        安装并启动:

[root@nginx ~]# rpm -ivh /media/nginx-rpm/*.rpm --nodeps --force[root@nginx ~]# systemctl start nginx[root@nginx ~]# systemctl enable nginxCreated symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
  • 安装php 

        所需安装包如下:

 

         安装并启动:

[root@nginx ~]# rpm -ivh /media/php-rpm/*.rpm --nodeps --force[root@nginx ~]# systemctl start php-fpm[root@nginx ~]# systemctl enable php-fpmCreated symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.
  • 安装mysql(mariadb)

        所需安装包如下:

 

        安装mysql并启动

[root@nginx ~]# rpm -ivh /media/mysql5.6-rpm/*.rpm --nodeps --force[root@nginx ~]# systemctl start mysqld[root@nginx ~]# systemctl enable mysqld创建mysql密码[root@nginx ~]# mysqladmin -uroot passwordNew password: //输入新密码Confirm new password: //再次输入新密码

应用安装

        本次php可以搭建两个应用wordpress和wecenter,两个app搭建一个论坛即可。如搭建两个app需要测试机本地解析域名,通过域名访问虚拟主机。

搭建wordpress

注意:下面操作注意看服务器名称。

        1. php服务器下载并解压wordpree包到/下并解压授权。

[root@php ~]# cp -rp /media/wordpress-4.9.4-zh_CN.zip /[root@php ~]# cd /[root@php /]# unzip wordpress-4.9.4-zh_CN.zip[root@php /]# chmod -R 777 /wordpress

        2.nginx服务器创建虚拟主机配置文件

[root@nginx /]# vim /etc/nginx/conf.d/blog.confserver {listen 80;server_name www.blog.com;root /wordpress;index index.php index.html;location ~ \.php$ {root /wordpress;fastcgi_pass 192.168.1.6:9000; //指定php服务器IPfastcgi_index index.php;                        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}}[root@nginx /]# nginx -tnginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful[root@nginx /]# systemctl restart nginx

        3.mysql服务器创建blog数据库和管理用户

[root@mysql ~]# mysql -uroot -p123//省略部分内容mysql> create database blog;Query OK, 1 row affected (0.00 sec)mysql> grant all on blog.* to lisi@'%' identified by '123456';Query OK, 0 rows affected (0.00 sec)mysql> exitBye

        4.PHP服务器修改配置文件后把PHP服务器中的/wordpress文件复制到nginx服务器中。

[root@php ~]# vim /wordpress/wp-config-sample.php/** WordPress数据库的名称 */define('DB_NAME', 'blog');/** MySQL数据库用户名 */define('DB_USER', 'lisi');/** MySQL数据库密码 */define('DB_PASSWORD', '123456');/** MySQL主机 */define('DB_HOST', '192.168.1.5');[root@php /]# cd /wordpress/[root@php wordpress]# mv wp-config-sample.php wp-config.php [root@php wordpress]# scp -rp /wordpress root@192.168.1.4:/[root@php ~]# vim /etc/php-fpm.d/www.conf  //修改下面两行内容listen = 192.168.1.6:9000 //PHP服务器IPlisten.allowed_clients = 192.168.1.4 //web服务器IP,表示允许web主机访问php服务器[root@php ~]# systemctl restart php-fpm

        5.通过客户端服务器验证

注意下面使用测试机1.10访问。

        因为只搭建了第一个app,所以直接访问IP即可,如多个app需要通过修改本机hosts文件或者搭建DNS访问 。http://192.168.1.4,后台网址为http://192.168.1.4/wp-admin。根据下图点击(现在就开始!)。

 

        创建站点标题,用户名密码后点击安装。

        登录管理用户密码后即进入账户首页,根据自己需求添加或修改即可。

 

搭建WeCenter

        1.安装

[root@php ~]# mkdir /zh[root@php ~]# cp -rp /media/WeCenter_3-3-4.zip /zh[root@php ~]# cd /zh[root@php zh]# unzip WeCenter_3-3-4.zip[root@php zh]# chmod -R 777 /zh

        2.nginx服务器创建虚拟主机配置文件

[root@nginx ~]# vim /etc/nginx/conf.d/zh.confserver {listen 80;server_name www.zh.com;root /zh;index index.php index.html;location ~ \.php$ {root /zh;                fastcgi_pass 192.168.1.6:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}}[root@nginx ~]# nginx -tnginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful[root@nginx ~]# systemctl restart nginx

        3.mysql服务器创建zh数据库和管理用户

mysql> create database zh;Query OK, 1 row affected (0.00 sec)mysql> grant all on zh.* to zh@'%' identified by '123456';Query OK, 0 rows affected (0.00 sec)4.PHP服务器修改配置文件后把PHP服务器中的/zh文件复制到nginx服务器中。[root@php ~]# cd /zh/system/config/[root@php config]# mv system.php databaes.php[root@php config]# vim databaes.php  //添加下面文档$config['charset'] = 'utf8mb4';^M$config['prefix'] = 'aws_';^M$config['driver'] = 'MySQLi';^M$config['master'] = array ('charset' => 'utf8mb4','host' => '192.168.1.5', //数据库主机IP'username' => 'zh', //用户名'password' => '123456', //用户密码'dbname' => 'zh', //数据库名称);^M$config['slave'] = false;^M[root@php config]# systemctl restart php-fpm[root@php config]# scp -rp /zh root@192.168.1.4:/

        5.验证

        访问http://www.zh.com查看配置无误后点击下一步,输入{数据库主机,账号,密码,名称}后点击开始安装。

        新建管理员用户密码,输入邮箱号后点击完成。

相关内容

热门资讯

国有资产法草案拟初审:规定国有... 【大河财立方消息】12月19日,全国人大常委会法制工作委员会举行记者会,发言人黄海华介绍立法工作有关...
3个娃两都非亲生,男子离婚三年... 近日,云南禄劝彝族苗族自治县人民法院审结一起离婚后损害责任纠纷案。 王某甲与赵某甲2017年结婚,婚...
南京博物院涉仇英《江南春画卷》... 12月17日晚间,南京博物院发布通报回应“明代仇英《江南春画卷》为何现身拍卖市场”,称该院依照《博物...
一起普通师生纠纷,何以演变为“... ▲石门县第二中学。图/澎湃新闻 今年9月底,一起因拉人进群而被跨省传唤的事件,登上新闻热搜。 澎湃新...
图达通(02665.HK)披露... 截至2025年12月19日收盘,图达通(02665)报收于14.41元,较前一交易日下跌8.22%。...
法律服务6秒触手可及!安图县综... 当邻里争执难解难分,打工维权不知门路,合同陷阱防不胜防,法律疑问无人解答……这些曾经让人发愁的难题,...
董毅智律师:“全网最低价”或滥... 12月17日,市场监管总局举行发布会,介绍民生领域反垄断执法相关情况。其中提到,平台要求商家“全网最...
2025年继承律师,遗嘱律师,... 一、遗嘱继承律师产品行业背景 随着社会财富积累与人口老龄化加剧,家庭资产传承需求日益凸显,遗嘱继承律...
立案侦查32人,执行到位634... 极目新闻通讯员 朱静 12月17日上午,荆州市政府新闻办召开新闻发布会,介绍该市政法机关“打击拒执犯...
已起诉!公牛集团索赔420万元... “10户中国家庭,7户用公牛”,是插线板巨头公牛集团(603195.SH)长期使用的宣传语。值得注意...