LNMP搭建静态网页服务器
chattr -i default/.user.ini
LNMP搭建使用
1.安装screen,命令或者操作可以一直运行下去
yum install screen
2.获取及安装 LNMP
wget http://soft.vpser.net/lnmp/lnmp1.6.tar.gz -cO lnmp1.6.tar.gz && tar zxf lnmp1.6.tar.gz && cd lnmp1.6 && ./install.sh lnmp
============================== Check install ==============================
Checking ...
Nginx: OK
MySQL: OK
PHP: OK
PHP-FPM: OK
Clean Web Server src directory...
+------------------------------------------------------------------------+
| LNMP V1.6 for CentOS Linux Server, Written by Licess |
+------------------------------------------------------------------------+
| For more information please visit https://lnmp.org |
+------------------------------------------------------------------------+
| lnmp status manage: lnmp {start|stop|reload|restart|kill|status} |
+------------------------------------------------------------------------+
| phpMyAdmin: http://IP/phpmyadmin/ |
| phpinfo: http://IP/phpinfo.php |
| Prober: http://IP/p.php |
+------------------------------------------------------------------------+
| Add VirtualHost: lnmp vhost add |
+------------------------------------------------------------------------+
| Default directory: /home/wwwroot/default |
+------------------------------------------------------------------------+
| MySQL/MariaDB root password: root |
+------------------------------------------------------------------------+
+-------------------------------------------+
| Manager for LNMP, Written by Licess |
+-------------------------------------------+
| https://lnmp.org |
+-------------------------------------------+
============================== Check ==============================
3.添加虚拟主机
[root@iZwz91gqesu0znselju9vhZ lnmp1.6]# lnmp vhost add
+-------------------------------------------+
| Manager for LNMP, Written by Licess |
+-------------------------------------------+
| https://lnmp.org |
+-------------------------------------------+
4.输入要添加网站的域名
Please enter domain(example: www.lnmp.org): rabidhare.com
Your domain: rabidhare.com
# 询问是否添加更多域名
Enter more domain name(example: lnmp.org *.lnmp.org):
Please enter the directory for the domain: rabidhare.com
5. 设置网站的目录 Enter默认
网站目录不存在的话会创建目录。也可以输入已经存在的目录或要设置的目录(注意如要输入必须是全路径即以/开头的完整路径!!!)。不输入直接回车的话,采用默认目录:/home/wwwroot/域名
Default directory: /home/wwwroot/rabidhare.com:
Virtual Host Directory: /home/wwwroot/rabidhare.com
6.伪静态可以使URL更加简洁也利于SEO,如程序支持并且需要设置伪静态的话,如启用输入 y ,不启用输入 n 回车(注意LNMPA或LAMP模式没有该选择项!)。
Allow Rewrite rule? (y/n) y
Please enter the rewrite of programme,
wordpress,discuzx,typecho,thinkphp,laravel,codeigniter,yii2 rewrite was exist.
(Default rewrite: other):
You choose rewrite: other
7.是否启用pathinfo 不需要pathinfo的网站程序开启pathinfo会访问出现各种问题 默认回车不启用,启用请输入 y 后回车。
Enable PHP Pathinfo? (y/n) y
Enable pathinfo.
8.设置日志,如启用日志输入 y ,不启用输入 n 回车。
Allow access log? (y/n) n
Disable access log.
9.是否添加数据库
Create database and MySQL user with same name (y/n) n
10.添加SSL功能
Add SSL Certificate (y/n) n
Press any key to start create virtul host...
Create Virtul Host directory......
set permissions of Virtual Host directory......
You select the exist rewrite rule:/usr/local/nginx/conf/rewrite/other.conf
Test Nginx configure file......
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
Reload Nginx......
Reload service php-fpm done
================================================
Virtualhost infomation:
Your domain: rabidhare.com
Home Directory: /home/wwwroot/rabidhare.com
Rewrite: other
Enable log: no
Create database: no
Create ftp account: no
================================================
11.进入主机目录
[root@iZwz91gqesu0znselju9vhZ lnmp1.6]# cd /home/wwwroot/rabidhare.com
12.上传网站程序
13.上传网站后建议执行,chown www:www -R /path/to/dir 对网站目录进行权限设置
[root@iZwz91gqesu0znselju9vhZ rabidhare.com]# chown www:www -R /home/wwwroot/rabidhare.com/
# 提示可以忽视
chown: changing ownership of ‘/home/wwwroot/rabidhare.com/.user.ini’: Operation not permitted
14伪静态管理
#LNMPA或LAMP可以直接使用网站根目录下放.htaccess 来设置伪静态规则(具体规则可以去程序官网网站找google百度),但是在LNMP下,需要使用Nginx伪静态规则。
#伪静态可以随时添加或删除,如果添加完虚拟主机后忘记或没有添加伪静态,可以通过修改配置文件来添加伪静态。
#虚拟主机配置文件在:/usr/local/nginx/conf/vhost/域名.conf
#伪静态规则文件需要放在/usr/local/nginx/conf/ 下面。
#编辑虚拟主机配置文件,可以使用vi、nano或winscp,后2个工具对新手来说简单些。
[root@iZwz91gqesu0znselju9vhZ rabidhare.com]# cd /usr/local/nginx/conf
vi /nginx.conf
#例如前面我们添加的虚拟主机,打开后前半部分配置会显示如下:
#---------------------------------------------------
server
{
listen 80 default_server reuseport;
#listen [::]:80 default_server ipv6only=on;
server_name _;
index index.html index.htm index.php;
# 修改主机地址文件
root /home/wwwroot/rabidhare.com;
#error_page 404 /404.html;
# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
include enable-php.conf;
location /nginx_status
{
stub_status on;
access_log off;
}
#---------------------------------------------------
15.重新启动 lnmp
[root@iZwz91gqesu0znselju9vhZ ~]# lnmp restart
+-------------------------------------------+
| Manager for LNMP, Written by Licess |
+-------------------------------------------+
| https://lnmp.org |
+-------------------------------------------+
Stoping LNMP...
Stoping nginx... done
Shutting down MySQL. SUCCESS!
Gracefully shutting down php-fpm warning, no pid file found - php-fpm is not running ?
Starting LNMP...
Starting nginx... done
Starting MySQL.. SUCCESS!
Starting php-fpm done
16.查看lnmp 状态
[root@iZwz91gqesu0znselju9vhZ ~]# lnmp status
+-------------------------------------------+
| Manager for LNMP, Written by Licess |
+-------------------------------------------+
| https://lnmp.org |
+-------------------------------------------+
nginx (pid 30843) is running...
php-fpm is runing!
SUCCESS! MySQL running (31349)
最后浏览器访问页面
命令
# 添加主机
lnmp vhost add
# 列出主机列表
lnmp vhost list
# 删除主机
lnmp vhost del
删除网站会先列出当前已有虚拟主机,按提示输入要删除的虚拟主机域名 回车确认。
删除网站会先列出当前已有虚拟主机,按提示输入要删除的虚拟主机域名 回车确认。
当执行chown或chmod对网站目录属主属组或权限进行操作时可能会提示chown: changing ownership of `/home/wwwroot/default/.user.ini': Operation not permitted,不需要理会,如果有强迫症可以参考前面先进行chattr -i的操作。
lnmp start|stop|reload|restart|kill|status
# 重启LNMP
lnmp restart
# LNMP状态查看
lnmp status