Ubuntu 16.04 LTS 安装 Nginx/PHP 5.6/MySQL 5.7 (LNMP) 与Laravel

Ubuntu 16.04 LTS 安装 Nginx/PHP 5.6/MySQL 5.7 (LNMP) 与Laravel

1、MySQL安装【安装 MariaDB】
MariaDB是MySQL的一个分支
首先,更新升级系统
$ sudo apt update
$ sudo apt upgrade
安装MariaDB:
$ sudo apt install mariadb-server
启动MariaDB服务:
$ sudo systemctl start mysql
$ sudo systemctl enable mysql
查看状态:
$ sudo systemctl status mysql

为例提高MariaDB的安全,我们可以执行初始化安全脚本:
$ sudo mysql_secure_installation
默认root密码为空;然后设置root密码和其他选项:
- Set root password? [Y/n] y
- Remove anonymous users? [Y/n] y
- Disallow root login remotely? [Y/n] y
- Remove test database and access to it? [Y/n] y
- Reload privilege tables now? [Y/n] y
登陆MariaDB命令行:
$ sudo mysql -u root -p

2、安装php5.6
Ubuntu 16.04 默认提供的是php7.0,版本太高,本人想测试Laravel,需要5.6版本的PHP
实现方法如下:
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php5.6
【需要额外安装一些extension如:php5.6-gd php5.6-mbstring php5.6-mysql php5.6-zip php5.6-xml php5.6-mcrypt】【fpm???】

3、安装Nginx
如果安装了apache2先卸载再安装nginx
service apache2 stop
update-rc.d -f apache2 remove
apt-get remove apache2

安装ngnix【安装过程不会自动创建目录,需要手动创建如/var/www/html】
apt-get install ngnix
service ngnix start

浏览器浏览验证是否安装成功,出现下面页面说明安装成功

4、配置ngnix

server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html/blogtest/public;
index index.html index.php index.htm index.nginx-debian.html;

server_name 192.168.198.138;

location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.php?$query_string;
}

location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php5.6-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name
;
include fastcgi_params;
}
}
--------------------------
重启ngnix:
service ngnix restart

==================================================================
5、安装Laravel及新建工程
apt-get install composer
composer global require "laravel/installer"

在/var/www/html中【composer不建议施用root用户来执行命令】
sudo composer create-project --prefer-dist laravel/laravel blogtest

修改文件所有者:
chown -R www-data:www-data blogtest/

6、浏览器访问

上一篇:Ubuntu 16.04 LTS 64位系统 安装Docker


下一篇:java – 嵌入式Jetty 8.x / Spring MVC / WebApplicationInitializer