乌班图系统搭建lnmp环境

LNMP环境搭建

安装系统选择 ubuntu 16.04

更新列表

apt-get update //更新列表
sudo apt-get install -y language-pack-en-base  //安装语言包
locale-gen en_US.UTF-8  //字符集

安装常用软件

sudo apt-get install -y vim git zip unzip

安装 PHP7

//请确保每一步没有出错,如果有报错,可尝试多安装几次

sudo apt-get install -y software-properties-common

sudo LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php

sudo apt-get update

apt-cache search php7.1

sudo apt-get install -y php7.1

sudo apt-get install -y php7.1-mysql

sudo apt-get install -y php7.1-fpm

sudo apt-get install -y php7.1-curl php7.1-xml php7.1-mcrypt php7.1-json php7.1-gd php7.1-mbstring

安装 Mysql

sudo apt-get install -y mysql-server

//安装完后需设置密码

安装 Nginx


//安装之前需确认是否安装了apache2,如果已经安装了apache2,需要先停止/卸载 apache2
//停止
sudo service apache2 stop
//卸载
sudo apt-get --purge remove apache2
sudo apt-get --purge remove apache2.2-common
sudo apt-get autoremove
//安装 nginx
sudo apt-get install -y nginx

配置 PHP7


//修改 cgi.fix_pathinfo=0 (注意去掉原有分号)

sudo vim /etc/php/7.1/fpm/pool.d/www.conf

//修改 listen = /var/run/php7.1-fpm.sock

配置 Nginx


//修改如下,根据自己的项目情况修改对应信息:'laravel-project'替换为你的项目,'server_domain_or_IP' 替换为你的网站域名或IP地址
server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/laravel-project/public;   //这里是项目地址

    index index.php index.html index.htm;

    server_name server_domain_or_IP;

    location / {
        try_files $uri $uri/ /index.php?$query_string;      
    }

    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php7.1-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

把项目拉取指定地址


//建议先将代码上传到云端代码仓库(github, coding)然后再在服务端上拉取

cd /var/www

git clone 地址

安装 Composer 并使用 Composer 安装代码依赖

php -r "if (hash_file('SHA384', 'composer-setup.php') === '669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

//然后移动 composer.phar
mv composer.phar /usr/local/bin/composer

//进入项目目录
cd /var/www/laravel-project

//执行 composer install
composer install

git拉取项目需要修改env文件,key,随后自定义数据库导入

修改权限

sudo chown -R www-data:www-data /var/www
sudo chmod -R 777 /var/www/laravel-project/storage

重启 Nginx 和 PHP7 fpm

service nginx restart
service php7.1-fpm restart
上一篇:LNMP环境一键部署


下一篇:Zabbix监控部署实战(基于LNMP架构)