Home  >  Article  >  Backend Development  >  How to install php from linux command line

How to install php from linux command line

藏色散人
藏色散人Original
2020-09-02 09:29:062809browse

How to install php from the Linux command line: First install PHP and the Apache PHP module through the "sudo apt install php libapache2-mod-php" command; then restart the Apache service.

How to install php from linux command line

Recommended: "PHP Video Tutorial"

Preparation Conditions

Before starting this tutorial, make sure you are logged in as a user with sudo privileges.

Install PHP 7.2 using Apache service

If you use Apache as your web server, you need to install PHP and the Apache PHP module, please run the following command:

sudo apt install php libapache2-mod-php

After installing the package, restart the Apache service:

sudo systemctl restart apache2

Install PHP 7.2 using Ngnix service

Unlike Apache, Nginx does not have built-in processing for PHP files, so we need to install a separate application like PHP FPM ("fastCGI Process Manager") which will handle PHP files.

To install PHP and the PHP FPM package, run the following command:

sudo apt install php-fpm
* php7.2-fpm.service - The PHP 7.2 FastCGI Process Manager
   Loaded: loaded (/lib/systemd/system/php7.2-fpm.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2018-06-30 23:56:14 PDT; 1min 28s ago
     Docs: man:php-fpm7.2(8)
 Main PID: 10080 (php-fpm7.2)
   Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec"
    Tasks: 3 (limit: 2321)
   CGroup: /system.slice/php7.2-fpm.service
           |-10080 php-fpm: master process (/etc/php/7.2/fpm/php-fpm.conf)

You can now edit the Nginx server block and add the following lines so that Nginx can process PHP files:

server {
    # . . . other code
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
    }
}

Don’t forget to restart the Nginx service for the new configuration to take effect:

sudo systemctl restart nginx

Install PHP extension

To To extend the core functionality of PHP, you can install some additional extensions. PHP extensions are available as packages and can be easily installed by:

sudo apt install php-[extname]

For example, if you want to install the MySQL and GD PHP extensions, you can run the following command:

sudo apt install php-mysql php-gd

Install New PHP After scaling, don't forget to restart the Apache or PHP FPM service, depending on your setup.

Testing PHP Processing

To test that your web server is properly configured for PHP processing, use the following code to create a file called info.php in the /var/www/html directory The new file:

<?php
phpinfo();
?>

Save the file, open the browser of your choice and visit http://your_server_ip/info.php

phpinfo function will print the information about the PHP configuration as shown below Show:

How to install php from linux command line

The above is the detailed content of How to install php from linux command line. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn