使用LNMP常见问题解答

༺小ʚɞ寞༻ Wiki评论18,6922字数 6921阅读23分4秒阅读模式

一、LNMP的安装

  1. ##先要下载,并根据不同系统进行安装:
  2. wget -c http://soft.vpser.net/lnmp/lnmp1.3.tar.gz
  3. tar zxvf lnmp1.3.tar.gz
  4. cd lnmp1.3
  5. ./install.sh #开始进行安装操作

以上为下载及进入安装过程,以下为安装前简易设置,切记输入个其它域名及牢记mysql密码:

  1. +------------------------------------------------------------------------+
  2. |          LNMP V1.2 for Ubuntu Linux Server, Written by Licess          |
  3. +------------------------------------------------------------------------+
  4. |        A tool to auto-compile & install LNMP/LNMPA/LAMP on Linux       |
  5. +------------------------------------------------------------------------+
  6. |          For more information please visit http://www.lnmp.org         |
  7. +------------------------------------------------------------------------+
  8. Please setup root password of MySQL.(Default password: root)
  9. Please enter: vpsmm.com #输入mysql的root密码
  10. MySQL root password: vpsmm.com
  11. ===========================
  12. Do you want to enable or disable the InnoDB Storage Engine?
  13. Default enable,Enter your choice [Y/n]: n #是否安装InnoDB
  14. You will disable the InnoDB Storage Engine!
  15. ===========================
  16. You have 5 options for your DataBase install.
  17. 1: Install MySQL 5.1.73
  18. 2: Install MySQL 5.5.42 (Default)
  19. 3: Install MySQL 5.6.23
  20. 4: Install MariaDB 5.5.42
  21. 5: Install MariaDB 10.0.17
  22. Enter your choice (1234 or 5): 3 #选择mysql版本
  23. You will Install MySQL 5.6.23
  24. ===========================
  25. You have 5 options for your PHP install.
  26. 1: Install PHP 5.2.17
  27. 2: Install PHP 5.3.29
  28. 3: Install PHP 5.4.41 (Default)
  29. 4: Install PHP 5.5.25
  30. 5: Install PHP 5.6.9
  31. Enter your choice (1234 or 5): 5 #选择php版本
  32. You will install PHP 5.6.9
  33. ===========================
  34. You have 3 options for your Memory Allocator install.
  35. 1: Don't install Memory Allocator. (Default)
  36. 2: Install Jemalloc
  37. 3: Install TCMalloc
  38. Enter your choice (12 or 3): 1 #小夜用不上,所以选择1
  39. You will install not install Memory Allocator.
  40. #按任意键,设置完成,正式进入安装,预计20-40分钟完成

常见lnmp管理命令:

  1. #1.2版本以后,不需要再执行/root/lnmp了,可以在任意位置执行lnmp命令
  2. lnmp #会出现一些提示信息
  3. lnmp restart #重启
  4. lnmp vhost add #添加网站绑定
  5. lnmp database add #添加数据库信息

二,域名绑定详解

其实所谓的域名绑定,就是通过命令的形式,简易创建一个conf文件到/usr/local/nginx/conf/vhost下面,这个过程完全可以手工创建conf,或者,平时修改目录、域名等,直接修改conf文件,效果完全一样:

  1. lnmp vhost add #执行lnmp添加网站命令
  2. +-------------------------------------------+
  3. |    Manager for LNMP, Written by Licess    |
  4. +-------------------------------------------+
  5. Please enter domain(example: www.lnmp.org): vpsmm.com #输入绑定的主域名
  6. ======================================
  7.  Your domain: vpsmm.com
  8. ======================================
  9. Do you want to add more domain name? (y/n) y #是否绑定其它域名
  10. Enter domain name(example: lnmp.org *.lnmp.org): www.vpsmm.com #输入其它域名
  11. domain list: www.vpsmm.com
  12. Please enter the directory for the domain: vpsmm.com
  13. (Default directory: /home/wwwroot/vpsmm.com): #默认创建的网站文件所在目录
  14. Virtual Host Directory: /home/wwwroot/vpsmm.com
  15. ===========================
  16. Allow Rewrite rule? (y/n)
  17. ===========================
  18. y #是否添加伪静态文件
  19. Please enter the rewrite of programme:
  20. wordpress,discuz,typecho,sablog,dabr rewrite was exist.
  21. (Default rewrite: other):typecho #小夜用的typecho程序
  22. ===========================
  23. You choose rewrite=typecho
  24. ===========================
  25. ===========================
  26. Allow access_log? (y/n)
  27. ===========================
  28. n #是否启用日志文件
  29. ======================================================
  30. Create database and MySQL user with same name (y/n)
  31. ======================================================
  32. y #是否创建mysql数据库
  33. verify your current MySQL root password: **** #输入安装时的mysql数据库root密码
  34. Warning: Using a password on the command line interface can be insecure.
  35. MySQL root password correct.
  36. Enter database name: vpsmm_user #创建数据库用户名
  37. Your will create a database and MySQL user with same name: vpsmm_user
  38. Please enter password for mysql user vpsmm_user: vpsmmpasswd
  39. Your password: vpsmmpasswd #创建相应密码
  40. Press any key to start create virtul host...
  41. Create Virtul Host directory......
  42. set permissions of Virtual Host directory......
  43. You select the exist rewrite rule:/usr/local/nginx/conf/typecho.conf
  44. Gracefully shutting down php-fpm . done
  45. Starting php-fpm  done
  46. Test Nginx configure file......
  47. nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
  48. nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
  49. Restart Nginx......
  50. Warning: Using a password on the command line interface can be insecure.
  51. Warning: Using a password on the command line interface can be insecure.
  52. User vpsmm_user create Sucessfully.
  53. Warning: Using a password on the command line interface can be insecure.
  54. Warning: Using a password on the command line interface can be insecure.
  55. Warning: Using a password on the command line interface can be insecure.
  56. Database: vpsmm_user create Sucessfully.
  57. Warning: Using a password on the command line interface can be insecure.
  58. Warning: Using a password on the command line interface can be insecure.
  59. GRANT ALL PRIVILEGES ON vpsmm_user Sucessfully.
  60. Warning: Using a password on the command line interface can be insecure.
  61. FLUSH PRIVILEGES Sucessfully.
  62. ================================================
  63. Virtualhost infomation:
  64. Your domain: vpsmm.com
  65. Home Directory: /home/wwwroot/vpsmm.com
  66. Rewrite: typecho
  67. Enable log: no
  68. Database username: vpsmm_user
  69. Database userpassword: vpsmmpasswd
  70. Database Name: vpsmm_user
  71. Create ftp account: no
  72. #以上为新创建网站的一些信息
  73. ================================================

三、自定义伪静态规则

如果lnmp默认的伪静态规则不能满足你的需要,或者,你要自行定义伪静态规则,可以新建一个conf文件,放置于 /usr/local/nginx/conf 下,在域名配置文件,即:/usr/local/nginx/conf/vhost/legcloud.com.conf 里引用。

  1. server
  2.   {
  3.     listen       80;
  4.     server_name legcloud.com www.legcloud.com; #绑定的域名
  5.     index index.html index.htm index.php default.html default.htm default.php; #首页文件
  6.     root  /home/legcloud.com; #网站存放目录
  7.     include wordpress.conf; #伪静态规则文件,可自定义成你需要的
  8.     location ~ .*\.(php|php5)?$
  9.       {
  10.         try_files $uri =404;
  11.         fastcgi_pass  unix:/tmp/php-cgi.sock;
  12.         fastcgi_index index.php;
  13.         include fcgi.conf;
  14.       }
  15.     location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  16.       {
  17.         expires      30d;
  18.       }
  19.     location ~ .*\.(js|css)?$
  20.       {
  21.         expires      12h;
  22.       }
  23.     access_log off;
  24.   }

修改设置以后,一定要重新载入lnmp或者,重新载入nginx,以下任决命令都一样:

  1. /root/lnmp reload #使用lnmp重新载入配置
  2. /etc/init.d/nginx reload #只重新载入nginx配置,我一般用这个

四、自定义404、503等常见错误

不管是404还是503等常见错误,还是设置/usr/local/nginx/conf/vhost/legcloud.com.conf文件来完成:

  1. listen       80;
  2. server_name legcloud.com www.legcloud.com;
  3. index index.html index.htm index.php default.html default.htm default.php;
  4. root  /home/legcloud.com;
  5. error_page 404 /404.php; #放在这里,可自定义文件名,再重载nginx就可以了
  6. include wordpress.conf;

五、判断当前域名并自动301到主域名

  1. if ($host != 'vpsmm.com' ) {rewrite ^/(.*)$ http://www.vpsmm.com/$1 permanent;}
  2. #判断当前域名,如果不是则自动301到主域名,放置于error_page ...;上下均可。

六、关闭或开启FSO等php函数

lnmp最新版,默认禁用了一些函数,例如fso等,可修改/usr/local/php/etc/php.ini

  1. disable_functions = passthru,exec,system,chroot,scandir....
  2. #----这是禁用函数,把不想禁用的删除即可----如果自用主机,最简单的修改方案:
  3. disable_functions =
  4. ; passthru,exec,system,chroot,scandir....
  5. #----设置为全部开启

修改后,使用/etc/init.d/php-fpm restart,重新启动php

七、升级PHP和NGINX版本

  1. cd lnm0.9 #进入lnmp安装目录  
  2. ./upgrade_nginx.sh #升级nginx,只要输入你要升级的版本即可(可见nginx.org)  
  3. ./upgrade_php.sh #升级php,只要输入你要升级的版本即可(可见php.net)  

weinxin
LuckTang's Blog 站长语录
LuckTang's Blog,欢迎各位来访!这是我的QQ,扫一扫,加好友。大家一起交流博客建站技术,分享前沿资讯!
Wiki最后更新:2018-1-13
如何在Linux下禁用IPv6 Linux

如何在Linux下禁用IPv6

IPv6被认为是IPv4——互联网上的传统32位地址空间——的替代产品,它用来解决现有IPv4地址空间即将耗尽的问题。然而,由于已经有大量主机、设备用IPv4连接到了互联网上,所以想在一夜之间将它们全...
Nginx 启用 proxy_cache 缓存 Wiki

Nginx 启用 proxy_cache 缓存

顾名思义,proxy_cache 是用于 proxy 模式(一般也可称为反代)的缓存功能。本文介绍其基本用法。 proxy_cache 在 Nginx 配置的 http 段、server 段(loca...
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定