Ubuntu 17.04 安装LNMP开发环境

一、nginx安装

添加ppa:

sudo add-apt-repository ppa:nginx/stable
sudo apt-get update
sudo apt-get -y install nginx

配置虚拟主机:

生成域名为名称的nginx配置文件

tail /etc/nginx/sites-available/default -n 13 | cut -c 2- | sudo tee /etc/nginx/sites-available/example.com 1> /dev/null

修改配置文件内容

server {
    listen 80;
    listen [::]:80;

    server_name example.com;

    root   /var/www/html/example.com;
    index  index.php index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}

生成主机根目录:

sudo mkdir -p /var/www/html/example.com/

创建配置文件软链接并重启

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled
sudo rm /etc/nginx/sites-enabled/default
sudo systemctl restart nginx

更多nginx配置参考https://www.linode.com/docs/web-servers/nginx/how-to-configure-nginx/

二、php7.1安装

添加ppa:

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update && sudo apt-get upgrade
sudo apt-get -y install php7.1 

#查看php7有哪些扩展
apt-cache search php7.1-

#安装需要的扩展
sudo apt-get install php7.1-cli php7.1-cgi php7.1-fpm

#查看已安装的扩展
php -m

修改配置文件:

server {
        listen 80;
        listen [::]:80;

        server_name example.com;

        root /var/www/html/example.com;
        index index.php index.html;

        location / {
                try_files $uri $uri/ =404;
        }
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                include fastcgi_params;
                fastcgi_pass unix:/run/php/php7.1-fpm.sock;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }
}

重启

sudo systemctl restart php7.1-fpm nginx

三、mysql安装

安装并输入密码

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

配置数据库

#登录
mysql -u root -p

#注册
CREATE DATABASE web;
CREATE USER 'webuser' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON web.* TO 'webuser';
quit

重启

sudo systemctl restart php7.1-fpm

数据库更多配置参考:http://www.jianshu.com/p/a355ca20ebdf

到此为止,lnmp环境安装完毕。

你可能感兴趣的:(Ubuntu 17.04 安装LNMP开发环境)