143 lines
3.6 KiB
Markdown
143 lines
3.6 KiB
Markdown
---
|
||
title: 搭建 lnmp
|
||
date: 2018/2/16 22:49
|
||
tags: [CentOS, LNMP, php, vps, 网站, 搭建]
|
||
categories: 技术
|
||
permalink: 21.html
|
||
---
|
||
|
||
安装包编译的时间很长,而且如果你的服务器配置再低级一些的话,可能就要更久,或者遇到服务器直接休克宕机!然而,今天我们介绍一个方法,可以直接把基于最新的LNMP安装到你的服务器中!
|
||
|
||
本文以centos7.1为例
|
||
|
||
安装
|
||
=======
|
||
|
||
Nginx
|
||
-------
|
||
|
||
直接到 [官网](http://nginx.org/packages/) 下载你的平台所需的包
|
||
|
||
比如我的是centos,就点centos,然后根据自己系统版本和所需的nginx版本选择rpm包!
|
||
|
||
64位的就是x86_64,32位的就是i386!
|
||
|
||
定位到所需的nginx版本后,右击复制链接地址
|
||
|
||
然后回到自己的ssh,输入:
|
||
|
||
```bash
|
||
rpm -ivh 你的复制的链接
|
||
nginx -v
|
||
```
|
||
|
||
然后nginx就这样装好了!
|
||
|
||
mysql
|
||
--------
|
||
|
||
对于MySQL,本人推荐是mariadb,用法和MySQL一模一样,对我们来说仅仅,就仅仅是换了个名字而已!
|
||
|
||
使用yum安装。
|
||
|
||
```bash
|
||
vi /etc/yum.repos.d/MariaDB.repo
|
||
|
||
[mariadb]
|
||
name = MariaDB
|
||
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
|
||
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
|
||
gpgcheck=1
|
||
```
|
||
|
||
```bash
|
||
yum install MariaDB-server MariaDB-client
|
||
service mariadb start
|
||
mysql_secure_installation
|
||
```
|
||
|
||
MySQL搭建好了!
|
||
|
||
php
|
||
-------
|
||
|
||
首先安装两个Yum源:
|
||
|
||
### CentOS/RHEL 7.x:
|
||
|
||
```bash
|
||
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
|
||
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
|
||
```
|
||
|
||
### CentOS/RHEL 6.x:
|
||
|
||
```bash
|
||
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
|
||
rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm
|
||
```
|
||
|
||
```bash
|
||
yum list php*
|
||
```
|
||
|
||
提醒下,必须要装的是结合MySQL的,还有php-fpm模块!不然你的网站跑不起来的!
|
||
|
||
### 安装php7
|
||
|
||
```bash
|
||
yum -y install php70w php70w-cli php70w-common php70w-fpm php70w-gd php70w-mysql
|
||
service php-fpm start
|
||
chkconfig php-fpm on
|
||
```
|
||
|
||
具体模块和版本依照自己的程序来,建议使用php5.6,因为php7的兼容性还不是很好,不然白费功夫出现莫名的bug!
|
||
|
||
至此,LNMP已经安装成功,一般从头到尾不需要两分钟的!
|
||
|
||
配置
|
||
======
|
||
|
||
首先统一下web服务器运行的用户:
|
||
|
||
```bash
|
||
sed -i 's/user = apache/user = nginx/' /etc/php-fpm.d/www.conf
|
||
sed -i 's/group = apache/group = nginx/' /etc/php-fpm.d/www.conf
|
||
```
|
||
|
||
然后在/etc/nginx/conf.d里面创建你的网站配置文件:
|
||
|
||
```bash
|
||
vi /etc/nginx/conf.d/echoteen.com.conf
|
||
```
|
||
|
||
```
|
||
server {
|
||
listen 80;
|
||
server_name www.echoteen.com echoteen.com; #你的网站域名
|
||
access_log off;
|
||
index index.html index.htm index.php;
|
||
root /home/wwwroot/echoteen.com; #你的网站文件路径
|
||
location ~ \.php$ {
|
||
root html;
|
||
fastcgi_pass 127.0.0.1:9000;
|
||
fastcgi_index index.php;
|
||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||
include fastcgi_params;
|
||
}
|
||
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
|
||
expires 30d;
|
||
access_log off;
|
||
}
|
||
location ~ .*\.(js|css)?$ {
|
||
expires 7d;
|
||
access_log off;
|
||
}
|
||
}
|
||
```
|
||
|
||
对于wordpress等需要伪静态规则的,直接在这里添加伪静态规则,具体规则自行百度!然后 `service nginx restart` `service php-fpm restart` 。
|
||
|
||
最后绑定下你的域名,就可以直接访问了!
|
||
|
||
这样很快的就搭建了自己的web服务器,而且功能和版本可以自定义,简单快捷!大大节省了服务器磁盘空间和内存!不需要一键安装包那么无脑,遇到问题没法解决! |