搭建PHP的運行環境對新手來講有點難度,對老手來講也比較繁瑣,今天寫一篇來記錄下。
系統版本是 Ubuntu 14.04.5 LTS.php
一些準備工做html
sudo apt-get update sudo apt-get install -y language-pack-en-base locale-gen en_US.UTF-8 sudo apt-get install software-properties-common sudo LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php sudo apt-get update
安裝PHP7mysql
sudo apt-get -y install php7.1 php7.1-mysql php7.1-fpm //安裝經常使用擴展 sudo apt-get install php7.1-curl php7.1-xml php7.1-mcrypt php7.1-json php7.1-gd php7.1-mbstring php -v
輸出下面的內容表示PHP安裝成功
nginx
sudo apt-get -y install mysql-server-5.6 //安裝過程會提示輸入roor用戶的密碼 mysql -uroot -p //登陸mysql
sudo apt-get -y install nginx sudo service nginx start
打開瀏覽器,輸入本機的IP
laravel
前面安裝部分比較簡單,接下來配置。sql
sudo vim /etc/php/7.1/fpm/php.ini // 將cgi.fix_pathinfo=1這一行去掉註釋,將1改成0 sudo vim /etc/php/7.1/fpm/pool.d/www.conf // 配置這個 listen = /var/run/php7.1-fpm.sock sudo service php7.1-fpm restart
sudo vim /etc/nginx/sites-available/default //Nginx 基礎配置以下: listen 80 default_server; listen [::]:80 default_server ipv6only=on; root /vagrant/public; index index.php index.html index.htm; # Make site accessible from http://localhost/ server_name localhost; 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; # Uncomment to enable naxsi on this location # include /etc/nginx/naxsi.rules } 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; }
配置完成後重啓Nginx 服務json
sudo service nginx restart
至此,安裝配置結束。vim
最後,我在vagrant目錄下部署了laravel項目。
須要注意的點,在線上部署時項目目錄全部者爲: www-data:www-data ,給storage 文件夾權限,修改配置文件後記得重啓服務。瀏覽器
sudo chown -R www-data:www-data 項目目錄
參考連接
https://laravist.com/discuss/...php7