Ubuntu 16.04 LTS 安装lavarel 环境, php7, nginx1.9, mysql5.7

最近有个小的项目是用laravel写的,本来想用虚拟机搞定,可是正好赶上朋友的公司淘汰一批12寸的本,有好多台跟新的差不多,就要了一台来安装ubuntu 来做开发.

Ubuntu 16.04 的repo 自带了最新版本的php7, nginx1.9, mysql5.7, 正合适laravel 的开发环境

下面是详细的安装过程,正好做一个备份方向以后查找

1.更新本地的repo index以及相关的程序

sudo apt-get update

sudo apt-get upgrade

2.移除apache(在某些发行版上会自带apache)

sudo apt-get remove apache2*
sudo apt-get autoremove
sudo apt-get autoclean

3.安装nginx, 可以用apt cache show nginx 查看repo中的nginx版本

sudo apt-get install nginx

sudo systemctl start nginx

sudo systemctl status nginx

4.安装mysql, 可以用apt  cache show mysql 查看repo中的mysql版本

sudo apt-get install mysql-server mysql-client

5. 初始化mysql

sudo mysql_secure_installation
sudo systemctl status mysql

6.安装php7

sudo apt install php php-fpm php-mysql php-mbstring php-curl php-xml php-mcrypt

7. 配置nginx和php7

至此,基本的环境就安装好了,下面就是配置nginx和php7,让他们协同合作

7.1 对于php fpm,我们需要调整cgi.fix_pathinfo

echo ‘cgi.fix_pathinfo=0’ >> /etc/php/7.0/fpm/php.ini

sudo systemctl restart php7.0-fpm

7.2 配置nginx 主机

修改/etc/nginx/sites-available/default为以下:

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

root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;

server_name server_domain_or_IP;

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

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}

location ~ /\.ht {
deny all;
}
}

8. 自己设个phpinfo的文件看看配置

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.