服务器ubuntu安装多版本php环境
服务器ubuntu安装多版本php环境
ubuntu安装配置php开发环境
1.设置软件源
sudo apt-get install software-properties-commonsudo add-apt-repository ppa:ondrej/phpsudo apt-get update2.安装php7以上的模板
php7.0
apt-get install -y php7.0-cli php7.0-curl php7.0-gd php7.0-json php7.0-mysql php7.0-opcache php7.0-xml php7.0-xmlrpc php7.0-bcmath php7.0-fpm php7.0-fpm php7.0-mbstring php7.0-mcrypt php7.0-soap php7.0-xsl php7.0-zip php7.0-intl
php7.1
apt-get install -y php7.1-cli php7.1-curl php7.1-gd php7.1-json php7.1-mysql php7.1-opcache php7.1-xml php7.1-xmlrpc php7.1-bcmath php7.1-fpm php7.1-fpm php7.1-mbstring php7.1-mcrypt php7.1-soap php7.1-xsl php7.1-zip php7.1-intl
php7.2
sudo apt install -y php7.2 php7.2-fpm php7.2-cli php7.2-common php7.2-mbstring php7.2-gd php7.2-intl php7.2-xml php7.2-mysql php7.2-zip php7.2-json php7.2-curl
3.快速切换php 版本
sudo update-alternatives --config php
4.安装nginx
apt-get install -y nginx
5.配置php-fpm和与nginx,由于安装了多版本的php,本人习惯创建不同的fpm sock 配置文件。如php7.0-fpm的配置,我会创建对应名为fastcgi_70.conf
upstream fastcgi_70 { server unix:/run/php/php7.0-fpm.sock; }
同理fastcgi_71.conf
upstream fastcgi_71 { server unix:/run/php/php7.1-fpm.sock; }
最后配置php项目的配置文件:
server { listen 80; server_name example.com; root /home/ubuntu/projects/example.com/public; index index.php index.html index.htm; location / { if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=/$1 last; break; } } location ~ .php$ { fastcgi_pass fastcgi_70;//只需要在这里更改一下,就可以切换不同的php-fpm版本 fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; fastcgi_buffer_size 128k; fastcgi_buffers 4 256k; fastcgi_busy_buffers_size 256k; } }
6.安装数据库MariaDB
apt-get install -y mariadb-server