Home  >  Article  >  Backend Development  >  Detailed explanation of linux installation and testing of php

Detailed explanation of linux installation and testing of php

PHPz
PHPzOriginal
2023-03-29 10:13:29505browse

Installing and testing PHP under Linux

PHP is a widely used server-side scripting language. It is an open source language that can be used to create dynamic Web pages. It is very easy to install PHP on the Linux operating system. This article will introduce how to install and test PHP under the Linux system.

  1. Confirm whether Apache has been installed on the system

Before you begin, please make sure Apache is installed on your Linux system. If Apache is not installed on the system, please execute the following command first:

sudo apt-get update
sudo apt-get install apache2

After the installation is complete, you can check whether Apache is installed by using the following command Run:

sudo systemctl status apache2

If you see the words "Active: active (running)", it means that Apache has been successfully installed and running.

  1. Installing PHP

Now, we are ready to install PHP. Under Linux systems, PHP can be easily installed through the apt-get package manager. Open a terminal and execute the following command:

sudo apt-get install php

This command will automatically download and install PHP and its dependencies. After waiting for the installation to complete, we need to check whether the installation was successful.

  1. Testing PHP

To test that PHP has been installed correctly, create a .php file and add the following code to the file:

< ;?php
phpinfo();
?>

Now, name the file info.php and save it to Apache’s default web directory /var/www/html/ middle.

To access the PHP information page, enter the following URL into your web browser:

http://localhost/info.php

You You will see the PHP version, configuration information, PHP modules, and PHP settings. If you can see it and no errors appear, PHP is installed correctly and running.

  1. Install more PHP modules

If you need to use MySQL or some other PHP modules, you need to install them. You can install the MySQL module for PHP using the following command:

sudo apt-get install php-mysql

Similarly, you can install other PHP modules using the following command:

sudo apt-get install php-curl
sudo apt-get install php-gd

After the installation is complete, restart Apache and test online:

sudo systemctl restart apache2

  1. Conclusion

This article introduces how to install PHP in a Linux system and test it. If you encounter problems, check that the command was executed correctly or check the log file for error messages.

After completing the steps described in this article, you can start using PHP, create a new web application or adapt an existing application to meet your needs.

The above is the detailed content of Detailed explanation of linux installation and testing of php. 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