[ad_1]
Discover ways to troubleshoot Apache 2 when it is not executing PHP recordsdata with this easy-to-follow, step-by-step tutorial.
What number of instances have you ever arrange an online server with Apache 2 solely to seek out out that whenever you try to view a web page with a .php extension, the web page both makes an attempt to save lots of onto the native drive or it shows the PHP code within the browser? That is unhealthy on a number of ranges. First off, your web site isn’t functioning correctly. Even worse, somebody might get a first-hand glimpse of your code, which isn’t solely a frustration however a doable safety challenge.
Contemplating that is a simple repair, there’s no purpose to keep away from working with PHP and Apache 2. However, how do you repair it? Let me present you.
Notice: I display this course of on Ubuntu Desktop 23.04, working the most recent releases of Apache 2 and PHP 8.1. This course of can work in most fashionable Linux distributions.
Leap to:
Putting in Apache 2 and PHP 8.1
Package deal administration makes the set up and configuration of Apache 2 and PHP 8.1 straightforward. Use the next instructions within the terminal to put in Apache 2, PHP 8.1, the PHP 8.1 command-line interpreter, and the module which configures Apache 2 and PHP 8.1 to work collectively:
sudo apt-get set up apache2 php8.1 php8.1-cli
libapache2-mod-php8.1 -y
Notice: The above line is damaged up due to the margin limitation on the web page. Using the backslash on the finish of the road is intentional.
SEE: Reap the benefits of this guidelines for managing and troubleshooting servers from TechRepublic Premium.
Beginning and enabling Apache 2
As soon as the set up of Apache 2 and the PHP modules is full, it is going to be crucial to start out Apache 2 and allow Apache 2. If you happen to begin Apache 2 however don’t allow it, then Apache 2 won’t restart whenever you reboot your system:
sudo systemctl begin apache2
sudo systemctl allow apache2
You may examine the standing of Apache 2 utilizing the command:
sudo systemctl standing apache2
This command will inform you if Apache 2 is working and whether it is enabled.
Verifying the PHP 8.1. set up
With Apache 2 put in and PHP 8.1 configured, it is going to be essential to confirm that the set up is working. You are able to do this by making a easy PHP script within the /var/www/html
listing.
By default, the Apache 2 package deal will create an index.html
file within the /var/www/html
listing. You may take away this with the command:
sudo rm /var/www/html/index.html
The sudo
command is critical as a result of this file is owned by root.
Now create a brand new file, /var/www/html/index.php
, as a replacement:
sudo nano /var/www/html/index.php
And on this file, place the next code:
<?php
phpinfo();
?>
In case you have a desktop atmosphere and an online browser put in in your server, you’ll be able to browse to the set up by way of the URL http://localhost. In any other case, you’ll be able to browse to the set up from one other laptop in your community utilizing the IP tackle of the server on which you carried out the set up.
If you happen to see a display screen that appears just like the one under, then congratulations! You’ve efficiently put in Apache 2 and PHP 8.1 (Determine A).
Determine A
When you’ve verified that your Apache 2 and PHP 8.1 installations are working, you need to undoubtedly sort out the phpinfo()
command, particularly when you have this working on a public-facing server:
<?php
//phpinfo();
?>
Subsequent steps: Securing your Apache 2 and PHP setup
Usually, let’s imagine “that’s it!” close to your Apache 2 and PHP setup, however that’s most definitely not the case. For starters, the default configuration for Apache 2 is very insecure; your subsequent plan of action must be to correctly safe it. You will get extra data on precisely how to do that from the next articles:
[ad_2]