Home > Article > Operation and Maintenance > How to install and configure PHP on Linux
How to install and configure PHP on Linux
PHP is an open source server-side scripting language widely used in web development. Installing and configuring PHP on Linux can provide us with a powerful development environment. This article explains how to install and configure PHP on Linux and provides some sample code.
On Ubuntu or Debian systems, use the following command:
$ sudo apt-get install php
On CentOS or RHEL system, use the following command:
$ sudo yum install php
First, we need to edit the PHP configuration file php.ini. Run the following command in the terminal to edit:
$ sudo vim /etc/php/php.ini
You can make some common configurations according to actual needs. For example, we can modify the time zone settings.
Find the following line:
;date.timezone =
Change it to:
date.timezone = Asia/Shanghai
Save and exit the editor.
First, we need to enable the PHP module. Run the following command in the terminal:
$ sudo a2enmod php
Then, restart the Apache server:
$ sudo service apache2 restart
First, create a file named "index.php" and run the following command in the terminal:
$ touch index.php
Then, edit The file:
$ vim index.php
Paste the following code into the file:
<!DOCTYPE html> <html> <body> <?php echo "Hello, World!"; ?> </body> </html>
Save and exit the editor.
Now, we can view the results through the browser. Enter "http://localhost/index.php" in the browser, and you can see "Hello, World!" output on the page.
Summary
This article explains how to install and configure PHP on Linux and provides some sample code. With these simple steps, we can set up a powerful PHP development environment on Linux for web development and other application development. Installing and configuring PHP is a basic skill and an essential step for developers who want to do web development on Linux.
The above is the detailed content of How to install and configure PHP on Linux. For more information, please follow other related articles on the PHP Chinese website!