ubuntu部署php7.1

来源:互联网 发布:云笔记 linux 编辑:程序博客网 时间:2024/04/27 23:51

先更新本机内置的程序。

sudo apt-get updatesudo apt-get upgrade

再判断系统是否内置了add-apt-repository命令,如果没有执行下列命令安装

sudo apt-get install software-properties-common

git

安装一下git程序,很多地方会用到

sudo apt-get install git

设置一下自己的git名字和邮箱

git config --global user.name "你的名字或昵称"git config --global user.email "你的邮箱"

php

添加最新php的源,然后安装php

sudo add-apt-repository ppa:ondrej/phpsudo apt-get updatesudo apt-get install php7.1 php7.1-common php7.1-fpm php7.1-dev sudo apt-get install php7.1-mbstring php7.1-xml

安装结束之后就可以执行php -i命令查看到php-cli的信息 
不过要配合nginx的话,需要用php-fpm来管理php的进程。

service php7.1-fpm startservice php7.1-fpm stopservice php7.1-fpm restart
安装 MySQL 5.7

安装 MySQL 运行命令:

apt-get -y install mysql-server mysql-client

你会被要求提供MySQL的root用户密码 :

New password for the MySQL “root” user: <– yourrootsqlpasswordRepeat password for the MySQL “root” user: <– yourrootsqlpasswor

nginx

直接安装nginx

sudo apt-get install nginx

nginx的操作命令如下:

service nginx startservice nginx stopservice nginx restart

查看nginx使用的config配置文件或者软重启的命令是

nginx -tnginx -s reload

一般配置文件在/etc/nginx目录下。

不过要配置一个新的网站,不需要在nginx.conf里添加,只需要在sites-enabled文件夹下加一个对应文件即可(文件名随意)

cd /etc/nginx/sites-enabledtouch demo

上面的demo文件是随便命名,用vi打开

vim demo

然后添加下面的内容

server {    listen 80;    server_name demo.com;    root /home/www/demo/public;    index index.html index.htm index.php;    location / {        try_files $uri $uri/ /index.php?$query_string;    }    location ~ \.php$ {        fastcgi_split_path_info ^(.+\.php)(/.+)$;        fastcgi_pass unix:/run/php/php7.1-fpm.sock;        fastcgi_index index.php;        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;        include fastcgi_params;    }}

解释一下上面的配置:

  1. 独立的一个服务器配置需要用server{}包裹起来
  2. listen 80表示监听80端口,也就是http访问的默认端口,其它端口在浏览器上需要输入端口号。
  3. server_name表示绑定的是哪个域名。
  4. root表示该域名访问到路径对应的实际文件夹
  5. index表示域名的path为空的时候对应访问哪个文件,默认都是index.html、index.htm和index.php
  6. location /这里是对所有路径做路由重写,里面的try_files $uri $uri/ /index.php?$query_string;是laravel框架的路径重写配置。
  7. location ~ \.php$是指访问所有后缀名带.php的路径时候,需要执行的操作,这里也就是配置php的fastcgi
  8. fastcgi里的最重要部分是fastcgi_pass,它代表nginx服务器如何与php通信,这里的unix:/run/php/php7.1-fpm.sock;是php7.1-fpm启动后生成的套接字文件,可以和nginx通信。
原创粉丝点击