How to install php from linux command line

藏色散人
Release: 2023-03-05 16:12:01
Original
2805 people have browsed it

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
Copy after login

After installing the package, restart the Apache service:

sudo systemctl restart apache2
Copy after login

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)
Copy after login

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;
    }
}
Copy after login

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

sudo systemctl restart nginx
Copy after login

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]
Copy after login

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
Copy after login

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();
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!