安裝環境
說明:nginx、 mysql5.7、php7.0
1.安裝之前先更新系統
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
2.安裝nginx
sudo apt-get install nginx
3.安裝php7.0和php7.0-fpm
sudo apt-get install php7.0
sudo apt-get install php7.0-fpm
4.配置nginx使其解析php、檔案位置:
/etc/nginx/sites-available/default
server {
listen 80;
listen 443 ssl http2;
server_name api.homestead.com; #域名
root "/home/vagrant/laravel/public"; #配置檔案位置
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/homestead.test-error.log error;
sendfile off;
client_max_body_size 100m;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; #綁定php版本
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}
location ~ /\.ht {
deny all;
}
}
5.修改php7.0-fpm配置;檔案位置:
vim /etc/php/7.0/fpm/php.ini
找到cgi.fix_pathinfo=1,将其改為cgi.fix_pathinfo=0
重新開機: nginx service nginx restart
重新開機php7.0-fpm服務: service php7.0-fpm restart
6.安裝mysql5.7
sudo apt-get install mysql-server php7.0-mysql
sudo apt-get install mysql-client
7.安裝一些常用的擴充庫
sudo apt install php-mysql php-curl php-mcrypt php-gd php-memcached php-redis #此方式安裝會同時在多個版本下面分别安裝
8.檢視PHP可以安裝的其它擴充庫
sudo apt install php7.0 #按tab
9.顯示結果
php7.0
php7.0-fpm php7.0-mysql php7.0-sqlite3
php7.0-bcmath
php7.0-gd php7.0-odbc php7.0-sybase
php7.0-bz2
php7.0-gmp php7.0-opcache php7.0-tidy
php7.0-cgi
php7.0-imap php7.0-pgsql php7.0-xml
php7.0-cli
php7.0-interbase php7.0-phpdbg php7.0-xmlrpc
php7.0-common
php7.0-intl php7.0-pspell php7.0-xsl
php7.0-curl
php7.0-json php7.0-readline php7.0-zip
php7.0-dba
php7.0-ldap php7.0-recode
php7.0-dev
php7.0-mbstring php7.0-snmp
php7.0-enchant
php7.0-mcrypt php7.0-soap
10 其它版本PHP安裝,并切換
ppa的源提供了幾個版本的php 5.5、5.6、 7.0、7.1、7.2 也就是說我們可以安裝多個版本共存
sudo apt-get install php7.2
sudo apt-get install php7.2-fpm
切換版本:
update-alternatives --config php
根據自己的需要,切換不同的版本,好了,今天的部落格就更新到這裡了,如果感覺還不錯可以推薦給更多的人,謝謝您的觀看