How to install and configure a PHP development environment in Ubuntu?
To install and configure a PHP development environment on Ubuntu, you can follow the steps below:
- Install PHP:
Open the terminal and run the following command to install PHP:
sudo apt update
sudo apt install php
- Install PHP extensions:
You may also need to install some PHP extensions to meet your development needs. For example, if you need to use a MySQL database, you can install PHP’s MySQL extension.
sudo apt install php-mysql
- Installing Apache Server:
Typically, a web server is needed for running PHP scripts in a PHP development environment. You can install Apache server to work in conjunction with PHP.
sudo apt install apache2
- The configuration file for the default website in Apache can be found under /etc/apache2/sites-available/000-default.conf.
sudo nano /etc/apache2/sites-available/000-default.conf
In the configuration file, you can specify your website’s root directory and other settings.
- – The local host address is http://localhost/
- the listed address is http://127.0.0.1/
- – PHP index file
<?php
phpinfo();
?>
Save and close the file, then enter http://localhost/index.php in the browser. You should see a PHP information page, indicating that PHP has been successfully installed and configured.
By following the above steps, you can install and configure a PHP development environment in Ubuntu.