Home > Article > Backend Development > PHP is downloaded. How to install it?
PHP is a server-side scripting language that is often used to dynamically generate web content on web servers. If you have already downloaded PHP, then you need to install it. This article will guide you through the installation process of PHP so that you can start writing programs in PHP.
1. Installation environment preparation
Before installing PHP, you need to configure the web server first. Commonly used web servers include Apache, Nginx, etc. Here we take the Apache server as an example.
1. Install Apache
First, open a terminal and install Apache through the package manager. In Linux distributions such as Debian and Ubuntu, you can install it with the following command:
sudo apt-get update sudo apt-get install apache2
In Linux distributions such as CentOS, you can install it with the following command:
sudo yum update sudo yum install httpd
2. Install PHP
After installing Apache, you need to install PHP next. It can be installed through the following command:
In Linux distributions such as Debian and Ubuntu, it can be installed through the following command:
sudo apt-get update sudo apt-get install php
In Linux distributions such as CentOS, it can be installed through the following command:
sudo yum update sudo yum install php
2. Configure PHP
After the installation is completed, some configurations of PHP are required.
Open the terminal and open the php.ini file with the following command:
sudo nano /etc/php/7.2/apache2/php.ini
Search for the following in the opened file Content:
upload_max_filesize = 2M post_max_size = 8M
Modify the values of these two configuration items according to your needs, for example, modify them to the following values:
upload_max_filesize = 50M post_max_size = 100M
Save and exit.
After completing the modification, save and exit the php.ini file. Next, restart the Apache server so that it loads the PHP module.
In Linux distributions such as Debian and Ubuntu, you can restart Apache through the following command:
sudo service apache2 restart
In Linux distributions such as CentOS, you can restart Apache through the following command:
sudo systemctl restart httpd
3. Verify PHP installation
At this point, PHP has been installed. You can now verify that PHP was installed successfully by accessing the phpinfo.php file.
1. Create the phpinfo.php file
Open the terminal and enter the following command to create a file named phpinfo.php:
sudo nano /var/www/html/phpinfo.php
Enter the following in the opened file Code:
<?php phpinfo(); ?>
Save and exit the file.
2. Open the phpinfo.php file in the browser
Copy the following code into the browser address bar and press the Enter key:
http://localhost/phpinfo.php
If successful After the phpinfo.php file is opened and PHP-related information is displayed, the PHP installation is completed.
4. Summary
Installing and configuring PHP is the first step to enable you to develop server-side scripts. In this article, we introduced how to install and configure PHP on a Linux system and demonstrated how to verify that PHP was installed successfully. If you encounter any problems, please try to solve them by referring to this article.
The above is the detailed content of PHP is downloaded. How to install it?. For more information, please follow other related articles on the PHP Chinese website!