Does ubuntu come with php?
PHP - Scripting LanguagePHP is a general-purpose scripting language suited for Web development. PHP scripts can be embedded into HTML. This section explains how to install and configure PHP in an Ubuntu System with Apache2 and MySQL. Show
This section assumes you have installed and configured Apache2 Web Server and MySQL Database Server. You can refer to the Apache2 and MySQL sections in this document to install and configure Apache2 and MySQL respectively. InstallationPHP is available in Ubuntu Linux. Unlike Python, which is installed in the base system, PHP must be added. To install PHP and the Apache PHP module you can enter the following command at a terminal prompt:
You can run PHP scripts at a terminal prompt. To run PHP scripts at a terminal prompt you should install the php-cli package. To install php-cli you can enter the following command:
You can also execute PHP scripts without installing the Apache PHP module. To accomplish this, you should install the php-cgi package via this command:
To use MySQL with PHP you should install the php-mysql package, like so:
Similarly, to use PostgreSQL with PHP you should install the php-pgsql package:
ConfigurationIf you have installed the libapache2-mod-php or php-cgi packages, you can run PHP scripts from your web browser. If you have installed the php-cli package, you can run PHP scripts at a terminal prompt. By
default, when libapache2-mod-php is installed, the Apache 2 Web server is configured to run PHP scripts using this module. Please verify if the files Once you have installed the PHP related packages and enabled the Apache PHP module, you should restart the Apache2 Web server to run PHP scripts, by running the following command:
TestingTo verify your installation, you can run the following PHP phpinfo script:
You can save the content in a file References
Finally, the third part of our LAMP tutorial series: how to install PHP on Ubuntu. In this tutorial, we’ll show you how to install various versions of PHP, including PHP 7.4, PHP 8.0 and the latest PHP 8.1. This tutorial should work for any Ubuntu release and other Ubuntu-based releases. Ubuntu 18.04,
Ubuntu 20.04, Ubuntu 22.04, Ubuntu 21.10, and should even work for Xubuntu, Kubuntu and similar distros. Tutorials here:
For the first part of our LAMP series, go to our How to Install and Optimize Apache on Ubuntu tutorial. And for the second part, go to How to Install MySQL/MariaDB on Ubuntu. Before we begin installing PHP on Ubuntu
Now, onto our tutorial. PHP 7.4 is included by default in Ubuntu 20.04’s repositories. So the instructions are pretty similar to other variations. The instructions are also similar for Ubuntu 22.04, but Ubuntu 22.04 will use whatever the default PHP version it’s using. We don’t recommend using PHP 7.4, so you should skip to some of the other installation methods below. Use 8.0 or 8.1 instead. Update UbuntuAgain, before doing anything, you should update your server: apt-get update && apt-get upgrade Install PHP 7.4Next, to install PHP 7.4 on Ubuntu 20.04, just run the following command: apt-get install php This command will install PHP 7.4, as well as some other dependencies. To verify if PHP is installed, run the following command: php -v You should get a response similar to this: PHP 7.4.3 (cli) (built: Nov 25 2021 23:16:22) ( NTS ) And that’s it. PHP 7.4 is installed on your Ubuntu 20.04 server. Install PHP 7.4 modules (extensions)These are the most common PHP 7.4 modules often used by php applications. You may need more or less, so check the requirements of the software you’re planning to use: apt-get install php-pear php-fpm php-dev php-zip php-curl php-xmlrpc php-gd php-mysql php-mbstring php-xml libapache2-mod-php To check all the PHP modules available in Ubuntu, run: apt-cache search --names-only ^php How to install PHP 8.1 on Ubuntu 22.04 or 20.04PHP 8.1 is the newest PHP version released on 25 Nov 2021. You can start using it now. These are the instructions on how to install it on Ubuntu 22.04 or Ubuntu 20.04 (or any other Ubuntu) Update UbuntuFirst, update your Ubuntu server: apt-get update && apt-get upgrade Add the PHP repositoryTo install PHP 8.0 you’ll need to use a third-party repository. We’ll use the repository by Ondřej Surý that we previously used. First, make sure you have the following package installed so you can add repositories: apt-get install software-properties-common Next, add the PHP repository from Ondřej: add-apt-repository ppa:ondrej/php And finally, update your package list: apt-get update Install PHP 8.1After you’ve added the repository, you can install PHP 8.1 with the following command: apt-get install php8.1 This command will install additional packages:
And that’s it. To check if PHP 8.1 is installed on your server, run the following command: php -v Which should return something like this: PHP 8.1.1 (cli) (built: Dec 31 2021 07:26:20) (NTS) Install PHP 8.1 modules (extensions)You may need additional packages and modules depending on your applications. The most commonly used modules can be installed with the following command: apt-get install libapache2-mod-php8.1 php8.1-fpm libapache2-mod-fcgid php8.1-curl php8.1-dev php8.1-gd php8.1-mbstring php8.1-zip php8.1-mysql php8.1-xml And that’s all. You can now start using PHP on your Ubuntu server. If you want to further tweak and configure your PHP, read our instructions below. How to install PHP 8.0 on Ubuntu 22.04 or 20.04Instead of using the older PHP version that’s included by default in Ubuntu 20.04, you should use PHP 8.0 or 8.1. Here are the instructions on how to install PHP 8.0 on Ubuntu 20.04/22.04 Update UbuntuOf course, as always, first update Ubuntu: apt-get update && apt-get upgrade Add the PHP repositoryYou can use a third-party repository to install the latest version of PHP. We’ll use the repository by Ondřej Surý. First, make sure you have the following package installed so you can add repositories: apt-get install software-properties-common Next, add the PHP repository from Ondřej: add-apt-repository ppa:ondrej/php And finally, update your package list: apt-get update Install PHP 8.0After you’ve added the repository, you can install PHP 8.0 with the following command: apt-get install php8.0 This command will install additional packages:
And that’s it. To check if PHP 8.0 is installed on your server, run the following command: php -v Install PHP 8.0 modulesYou may need additional packages and modules depending on your applications. The most commonly used modules can be installed with the following command: apt-get install libapache2-mod-php8.0 php8.0-fpm libapache2-mod-fcgid php8.0-curl php8.0-dev php8.0-gd php8.0-mbstring php8.0-zip php8.0-mysql php8.0-xml And that’s all. You can now start using PHP on your Ubuntu server. If you want to further tweak and configure your PHP, read our instructions below. How to change the PHP version you’re usingIf you have multiple PHP versions installed on your Ubuntu server, you can change what version is the default one. To set PHP 8.1 as the default, run: update-alternatives --set php /usr/bin/php8.1 To set PHP 8.0 as the default, run: update-alternatives --set php /usr/bin/php8.0 You can verify what version of PHP you’re using with the following command: php -v If you’re following our LAMP tutorials and you’re using Apache, you can configure Apache to use PHP 8.0 with the following command: a2enmod php8.1 And then restart Apache for the changes to take effect: systemctl restart apache2 How to upgrade to PHP 7.4, 8.0 or 8.1 on UbuntuIf you’re already using an older version of PHP with some of your applications, you can upgrade by:
Speed up PHP by using an opcode cacheYou can improve the performance of your PHP by using a caching method. We’ll use APCu, but there are other alternatives available. If you have the ‘php-pear’ module installed (we included it in our instructions above), you can install APCu with the following command: pecl install apcu There are also other ways you can install APCu, including using a package. To start using APCu, you should run the following command for PHP 8.1: echo "extension=apcu.so" | tee -a /etc/php/8.1/mods-available/cache.ini Or this command for PHP 8.0: echo "extension=apcu.so" | tee -a /etc/php/8.0/mods-available/cache.ini If you’re following our LAMP tutorials and you’re using Apache, create a symlink for the file you’ve just created. For PHP 8.1: ln -s /etc/php/8.1/mods-available/cache.ini /etc/php/8.1/apache2/conf.d/30-cache.ini For PHP 8.0: ln -s /etc/php/8.0/mods-available/cache.ini /etc/php/8.0/apache2/conf.d/30-cache.ini And finally, reload Apache for the changes to take effect: systemctl restart apache2 To further configure APCu and how it works, you can add some additional lines to the cache.ini file you previously created. The best configuration depends on what kind of server you’re using, what applications you are using etc. Either google it and find a configuration that works for you, or contact professionals and let them do it for you. That’s it for our basic setup. Of course, there are much more options and configurations you can do, but we’ll leave them for another tutorial. Does Ubuntu include PHP?PHP is a programming language used for developing web applications. You must install PHP packages on a Ubuntu system to run the application written on it. Generally, it is used to create e-commerce websites, blogs, and API applications. If you're looking for an easy way to install PHP on Ubuntu 22.04, look no further.
Does Ubuntu 20.04 have PHP?Verify the installation of PHP on Ubuntu
You can now see that version 7.4. 3 of PHP is installed on Ubuntu 20.04 LTS.
How do I know if PHP is installed Ubuntu?Open a bash shell terminal and use the command “php –version” or “php -v” to get the version of PHP installed on the system.
Where is PHP in Ubuntu?The default location for the php. ini file is: Ubuntu 16.04: /etc/php/7.0/apache2.
|