最近接手了一个 PHP 项目,之前没做过 PHP,于是从搭建PHP环境开始学习下,同时写篇 Ubuntu 安装 PHP 的教程。
sudo apt-get purge `dpkg -l | grep PHP| awk '{print $2}' |tr "\n" " "` sudo apt autoremove
二、添加PPA
sudo apt-get install -y language-pack-en-base sudo LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/PHP sudo apt-get update
三、安装PHP
PHP 5.6 版本
sudo apt-get install PHP5.6 PHP5.6-cli sudo apt-get install PHP5.6-dev PHP5.6-fpm PHP5.6-cgi sudo apt-get install PHP5.6-mbstring PHP5.6-mcrypt PHP5.6-MysqL PHP5.6-gd PHP5.6-curl PHP5.6-memcache
PHP 7.1 版本
sudo apt-get install PHP7.1 PHP7.1-cli sudo apt-get install PHP7.1-dev PHP7.1-fpm PHP7.1-cgi sudo apt-get install PHP7.1-MysqL PHP7.1-gd PHP7.1-curl PHP7.1-memcache
四、Nginx配置
# Pass all .PHP files onto a PHP-fpm/PHP-fcgi server. location ~ [^/]\.PHP(/|$) { fastcgi_split_path_info ^(.+?\.PHP)(/.*)$; if (!-f $document_root$fastcgi_script_name) { return 404; } fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; # fastcgi_pass unix:/run/PHP/PHP5.6-fpm.sock; fastcgi_pass unix:/run/PHP/PHP7.1-fpm.sock; fastcgi_index index.PHP; include fastcgi_params; }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程小技巧。