Home >Backend Development >PHP Problem >How to install PHP into Apache server
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:
upload_max_filesize=64M
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!