Home >Backend Development >PHP Problem >How to install PHP into Apache server

How to install PHP into Apache server

PHPz
PHPzOriginal
2023-04-24 14:52:54976browse

When developing web applications, you usually need to install PHP and Apache servers. PHP is a scripting language that enables web servers to dynamically generate web page content. Apache is a popular web server that runs on many operating systems. In this article, we will explain how to install PHP into your Apache server.

Step 1: Install Apache

First, you need to install the Apache server. Apache is a free, open source software that is easily available through the official website or your operating system's package manager.

For example, in Ubuntu system, you can use the following command to install Apache:

sudo apt-get install apache2

After the installation is completed, Apache will start automatically. You can test whether your Apache installation was successful by entering your server's IP address or URL into your web browser.

Step 2: Install PHP

Next, you need to install PHP. Likewise, PHP can be installed using the official website or package manager.

In Ubuntu systems, you can install PHP using the following command:

sudo apt-get install php

After the installation is complete, make sure to restart Apache for the configuration to take effect :

sudo service apache2 restart

Step 3: Test PHP

After the installation is complete, you can test whether PHP is installed correctly on the Apache server. To do this, create a file called "test.php" and add the following code to the file:

Then add The file is saved to the default website document root directory of the Apache server ("/var/www/html" in the Ubuntu system).

You can then enter the following URL in your web browser to view the output of the phpinfo() function:

http://server IP address or domain name/test.php

If everything is fine, you will be able to see the PHP version information and other configuration details.

Step Four: Configure PHP

In some cases, you may need to configure PHP after installing it. For example, you may need to install certain PHP extensions or change some settings in the PHP.ini file.

You can view the list of installed PHP extensions by running the "php -m" command in the terminal. If you need to install other PHP extensions, use the following command:

sudo apt-get install php-extension-name

For example, to install the MySQL extension, use the following command:

sudo apt-get install php-mysql

If you need to change the settings in the PHP.ini configuration file, please do the following:

  1. Open "/etc/php/version /apache2/php.ini" file (where "version number" is the PHP version number you installed).
  2. Change the desired settings. For example, to change the file upload limit to 64MB, find the following line and change it to the desired value:

upload_max_filesize=64M

  1. Save and close the file.
  2. Restart the Apache server:

sudo service apache2 restart

Now you have successfully installed PHP into the Apache server and can start writing dynamic web app.

The above is the detailed content of How to install PHP into Apache server. 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