最近接手了一个 PHP 项目,之前没做过 PHP,于是从搭建PHP环境开始学习下,同时写篇 Ubuntu 安装 PHP 的教程。
一、删除遗留的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-basesudo LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/phpsudo apt-get update
三、安装PHP
PHP 5.6 版本
sudo apt-get install php5.6 php5.6-clisudo apt-get install php5.6-dev php5.6-fpm php5.6-cgisudo 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-clisudo apt-get install php7.1-dev php7.1-fpm php7.1-cgisudo 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;}
IIS7站长之家提示您:这篇文章你看完了!