根据需求实现动静分离,当客户端访问nginx网站服务时,静态网页nginx本机反馈,动态网页访问PHP,所以需要在nginx服务器中部署论坛后需要拷贝到PHP服务器中。但是如果有NFS或GFS服务器时可以把nginx和php指定文件服务器。
安装LNMP
- 安装nginx
所需安装包如下:
安装并启动:
1. [root@nginx ~]# rpm -ivh /media/nginx-rpm/*.rpm --nodeps --force 2. 3. [root@nginx ~]# systemctl start nginx 4. 5. [root@nginx ~]# systemctl enable nginx 6. 7. Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
- 安装php
所需安装包如下:
安装并启动:
1. [root@nginx ~]# rpm -ivh /media/php-rpm/*.rpm --nodeps --force 2. 3. [root@nginx ~]# systemctl start php-fpm 4. 5. [root@nginx ~]# systemctl enable php-fpm 6. 7. Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.
- 安装mysql(mariadb)
所需安装包如下:
安装mysql并启动
1. [root@nginx ~]# rpm -ivh /media/mysql5.6-rpm/*.rpm --nodeps --force 2. 3. [root@nginx ~]# systemctl start mysqld 4. 5. [root@nginx ~]# systemctl enable mysqld 6. 7. 创建mysql密码 8. 9. [root@nginx ~]# mysqladmin -uroot password 10. 11. New password: //输入新密码 12. 13. Confirm new password: //再次输入新密码
应用安装
本次php可以搭建两个应用wordpress和wecenter,两个app搭建一个论坛即可。如搭建两个app需要测试机本地解析域名,通过域名访问虚拟主机。
搭建wordpress
注意:下面操作注意看服务器名称。
1. php服务器下载并解压wordpree包到/下并解压授权。
1. [root@php ~]# cp -rp /media/wordpress-4.9.4-zh_CN.zip / 2. 3. [root@php ~]# cd / 4. 5. [root@php /]# unzip wordpress-4.9.4-zh_CN.zip 6. 7. [root@php /]# chmod -R 777 /wordpress
2.nginx服务器创建虚拟主机配置文件
1. [root@nginx /]# vim /etc/nginx/conf.d/blog.conf 2. 3. server { 4. 5. listen 80; 6. 7. server_name www.blog.com; 8. 9. root /wordpress; 10. 11. index index.php index.html; 12. 13. 14. 15. location ~ \.php$ { 16. 17. root /wordpress; 18. 19. fastcgi_pass 192.168.1.6:9000; //指定php服务器IP 20. 21. fastcgi_index index.php; 22. 23. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 24. 25. include fastcgi_params; 26. 27. } 28. 29. } 30. 31. 32. 33. [root@nginx /]# nginx -t 34. 35. nginx: the configuration file /etc/nginx/nginx.conf syntax is ok 36. 37. nginx: configuration file /etc/nginx/nginx.conf test is successful 38. 39. [root@nginx /]# systemctl restart nginx
3.mysql服务器创建blog数据库和管理用户
1. [root@mysql ~]# mysql -uroot -p123 2. 3. //省略部分内容 4. 5. mysql> create database blog; 6. 7. Query OK, 1 row affected (0.00 sec) 8. 9. 10. 11. mysql> grant all on blog.* to lisi@'%' identified by '123456'; 12. 13. Query OK, 0 rows affected (0.00 sec) 14. 15. 16. 17. mysql> exit 18. 19. Bye
4.PHP服务器修改配置文件后把PHP服务器中的/wordpress文件复制到nginx服务器中。
1. [root@php ~]# vim /wordpress/wp-config-sample.php 2. 3. /** WordPress数据库的名称 */ 4. 5. define('DB_NAME', 'blog'); 6. 7. 8. 9. /** MySQL数据库用户名 */ 10. 11. define('DB_USER', 'lisi'); 12. 13. 14. 15. /** MySQL数据库密码 */ 16. 17. define('DB_PASSWORD', '123456'); 18. 19. 20. 21. /** MySQL主机 */ 22. 23. define('DB_HOST', '192.168.1.5'); 24. 25. [root@php /]# cd /wordpress/ 26. 27. [root@php wordpress]# mv wp-config-sample.php wp-config.php 28. 29. [root@php wordpress]# scp -rp /wordpress root@192.168.1.4:/ 30. 31. [root@php ~]# vim /etc/php-fpm.d/www.conf //修改下面两行内容 32. 33. listen = 192.168.1.6:9000 //PHP服务器IP 34. 35. listen.allowed_clients = 192.168.1.4 //web服务器IP,表示允许web主机访问php服务器 36. 37. [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.安装
1. [root@php ~]# mkdir /zh 2. 3. [root@php ~]# cp -rp /media/WeCenter_3-3-4.zip /zh 4. 5. [root@php ~]# cd /zh 6. 7. [root@php zh]# unzip WeCenter_3-3-4.zip 8. 9. [root@php zh]# chmod -R 777 /zh
2.nginx服务器创建虚拟主机配置文件
1. [root@nginx ~]# vim /etc/nginx/conf.d/zh.conf 2. 3. server { 4. 5. listen 80; 6. 7. server_name www.zh.com; 8. 9. root /zh; 10. 11. index index.php index.html; 12. 13. 14. 15. location ~ \.php$ { 16. 17. root /zh; fastcgi_pass 192.168.1.6:9000; 18. 19. fastcgi_index index.php; 20. 21. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 22. 23. include fastcgi_params; 24. 25. } 26. 27. } 28. 29. [root@nginx ~]# nginx -t 30. 31. nginx: the configuration file /etc/nginx/nginx.conf syntax is ok 32. 33. nginx: configuration file /etc/nginx/nginx.conf test is successful 34. 35. [root@nginx ~]# systemctl restart nginx
3.mysql服务器创建zh数据库和管理用户
1. mysql> create database zh; 2. 3. Query OK, 1 row affected (0.00 sec) 4. 5. 6. 7. mysql> grant all on zh.* to zh@'%' identified by '123456'; 8. 9. Query OK, 0 rows affected (0.00 sec) 10. 11. 4.PHP服务器修改配置文件后把PHP服务器中的/zh文件复制到nginx服务器中。 12. 13. [root@php ~]# cd /zh/system/config/ 14. 15. [root@php config]# mv system.php databaes.php 16. 17. [root@php config]# vim databaes.php //添加下面文档 18. 19. 20. 21. $config['charset'] = 'utf8mb4';^M 22. 23. $config['prefix'] = 'aws_';^M 24. 25. $config['driver'] = 'MySQLi';^M 26. 27. $config['master'] = array ( 28. 29. 'charset' => 'utf8mb4', 30. 31. 'host' => '192.168.1.5', //数据库主机IP 32. 33. 'username' => 'zh', //用户名 34. 35. 'password' => '123456', //用户密码 36. 37. 'dbname' => 'zh', //数据库名称 38. 39. );^M 40. 41. $config['slave'] = false;^M 42. 43. [root@php config]# systemctl restart php-fpm 44. 45. [root@php config]# scp -rp /zh root@192.168.1.4:/
5.验证
访问http://www.zh.com查看配置无误后点击下一步,输入{数据库主机,账号,密码,名称}后点击开始安装。
新建管理员用户密码,输入邮箱号后点击完成。