曾经每次在Ubuntu安装上安装php都让我头疼一番,总是安装不好,因为要搭建LAMP框架,老是少一些组件,而不知道怎么办,其实本质上是我一开始不太会Ubuntu系统,我最初学的实际上是centos系统,虽说两者都是Linux系统,但是最为不一样的就是软件的管理上面,这也是让人烦恼的事情,我已经熟悉了centos的软件管理方法,但是对Ubuntu还不太了解,现在经过一段时间摸索,已经开始熟悉了。
Ubuntu如何安装php:
首先和centos一样,需要先配置软件源才能方便的下载软件,
在第一次使用 add-apt-repository 脚本前要先安装它

sudo apt install software-properties-common python-software-properties

添加源并更新

add-apt-repository ppa:ondrej/php
sudo apt update

#如果之前有其他版本PHP,在这边禁用掉

sudo a2dismod php5
sudo a2enmod php7.2

sudo apt-get install php7.0-mysql php7.0-curl php7.0-json php7.0-cgi

然后就可以安装了

sudo apt install php7.2   #版本可以自行选择

不过PHP需要用到很多的扩展组件,常用的有

sudo apt install php7.2-fpm php7.2-mysql php7.2-curl php7.2-json php7.2-mbstring php7.2-xml  php7.2-intl

还有另外一些可以按需安装,这里给大家列出来

sudo apt install php7.2-gd
sudo apt install php7.2-soap
sudo apt install php7.2-gmp    
sudo apt install php7.2-odbc       
sudo apt install php7.2-pspell     
sudo apt install php7.2-bcmath   
sudo apt install php7.2-enchant    
sudo apt install php7.2-imap       
sudo apt install php7.2-ldap       
sudo apt install php7.2-opcache
sudo apt install php7.2-readline   
sudo apt install php7.2-sqlite3    
sudo apt install php7.2-xmlrpc
sudo apt install php7.2-bz2
sudo apt install php7.2-interbase
sudo apt install php7.2-pgsql      
sudo apt install php7.2-recode     
sudo apt install php7.2-sybase     
sudo apt install php7.2-xsl
sudo apt install php7.2-cgi        
sudo apt install php7.2-dba 
sudo apt install php7.2-phpdbg     
sudo apt install php7.2-snmp       
sudo apt install php7.2-tidy       
sudo apt install php7.2-zip

此外还可以搜索有哪些php组件

sudo apt-cache search php7-* 

搜索结果如下,显示了组件及其用途

php7.0-common - Common files for packages built from the PHP source
libapache2-mod-php7.0 - server-side, HTML-embedded scripting language (Apache 2 module)
php7.0-cgi - server-side, HTML-embedded scripting language (CGI binary)
php7.0-cli - command-line interpreter for the PHP scripting language
php7.0-phpdbg - server-side, HTML-embedded scripting language (PHPDBG binary)
php7.0-fpm - server-side, HTML-embedded scripting language (FPM-CGI binary)
libphp7.0-embed - HTML-embedded scripting language (Embedded SAPI library)
php7.0-dev - Files for PHP7.0 module development
php7.0-dbg - Debug symbols for PHP7.0
php7.0-curl - CURL module for PHP
php7.0-gd - GD module for PHP
php7.0-imap - IMAP module for PHP
php7.0-intl - Internationalisation module for PHP
php7.0-ldap - LDAP module for PHP
php7.0-pgsql - PostgreSQL module for PHP
php7.0-pspell - pspell module for PHP
php7.0-recode - recode module for PHP
php7.0-snmp - SNMP module for PHP
php7.0-tidy - tidy module for PHP
php7.0-json - JSON module for PHP
php-all-dev - package depending on all supported PHP development packages
php7.0-sybase - Sybase module for PHP
php7.0-modules-source - PHP 7.0 modules source package
php7.0-sqlite3 - SQLite3 module for PHP
php7.0-mysql - MySQL module for PHP
php7.0-opcache - Zend OpCache module for PHP

查看php版本

 php -v 

安装后可以根据界面提示进行相应的操作,以启动服务
在这里插入图片描述
当然php的组件还远远不止这些,在不同的应用中其要求也不一样,如nextcloud的搭建,还需要其他组件,具体细节可以在安装时到nextcloud官网上看它需要哪些

Logo

更多推荐