On Ubuntu, use the following commands to install Apache server:
Once installed, you can check the status of the Apache service with the following command:
Apache's configuration files are primarily found in two directories: `/etc/apache2` and `/var/www/html`. The former contains Apache’s configuration files, while the latter is the default web root directory for Apache.
To navigate to the configuration file directory, use the following command:
By default, Apache’s homepage is located in the `/var/www/html` directory. You can either change this directory or create a custom `index.html` file in the directory.
To change the default homepage directory, edit the configuration file with the following command:
Locate the following line:
Modify `/var/www/html` to your desired directory, then save and exit.
Reload the Apache configuration:
Use the following command to install PHP and its related modules:
After installation, check the PHP version with the following command:
The PHP configuration file is located at `/etc/php/7.4/apache2/php.ini`. You should adjust the path based on the PHP version you have installed.
Edit the PHP configuration file with the following command:
In the file, you can adjust settings such as memory limits, file upload sizes, and other PHP configurations. After making changes, save and exit.
After modifying the PHP configuration, restart the Apache service to apply the changes:
In your browser, enter your server’s IP address or domain. If everything is configured correctly, you should see a page displaying PHP information, including version, configuration, and installed modules.
To test PHP, create a simple PHP file and place it in Apache’s default root directory. Use the following commands to create the file:
In the opened file, add the following content:
Save and exit, then access `http://your-server-ip/info.php` in your browser. If everything is set up correctly, you will see the PHP information page.
After completing these steps, you have successfully set up the PHP development environment on Ubuntu (Apache + PHP). This will provide you with a powerful platform for developing and deploying PHP applications.