Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

PHP PHP gets commented

hebrerillo

Active Coder
Hello there!

I had a local server in Apache and PHP that was working fine, but it has stopped working suddenly.

If I enter the URL "http://localhost/index.php", the PHP code gets commented out in the response:
Screenshot 2024-08-21 at 08.38.23.png

I searched in the web but found nothing. I read somewhere else that the PHP is not executed in my local server. Please, help me fix this.

I attach the file httpd.conf located in '/etc/apache2' folder.

My computer is MacOS Monterey, version 12.6.3

Thank you so much!!
 
Hello there!

I had a local server in Apache and PHP that was working fine, but it has stopped working suddenly.

If I enter the URL "http://localhost/index.php", the PHP code gets commented out in the response:
View attachment 2773

I searched in the web but found nothing. I read somewhere else that the PHP is not executed in my local server. Please, help me fix this.

I attach the file httpd.conf located in '/etc/apache2' folder.

My computer is MacOS Monterey, version 12.6.3

Thank you so much!!
Hi there.
Can you copy and paste the php code here? I want to eliminate any syntax errors
 
You said that it stopped working suddenly. I see that you're on a Mac. How did you install Apache and PHP? Did you use something like Homebrew to install, or did you install some other package?

Have you recently updated MacOS? I know updating MacOS can sometimes break packages installed for web development so it's possible the update somehow removed the associations between Apache and PHP.

Also, to rule out the obvious, your file has a .php extension, correct?
 
I don't know how macs work but, on linux you can do systemctl status apache2 in a terminal and find out if it's running.
Apache is running. I can access regular HTML files
You said that it stopped working suddenly. I see that you're on a Mac. How did you install Apache and PHP? Did you use something like Homebrew to install, or did you install some other package?

Have you recently updated MacOS? I know updating MacOS can sometimes break packages installed for web development so it's possible the update somehow removed the associations between Apache and PHP.

Also, to rule out the obvious, your file has a .php extension, correct?
Hello, sorry for the late response.

Yes, I am on a Mac. I am using the default Apache installation that comes with MAC OS.
To be honest, I do not remember how I installed PHP. It was long ago. Besides, I have another PHP installation via Homebrew that another coworker installed on my computer. So maybe they are having problems coexisting with each other.

Although they have been coexisting with each other for a long time. It's been recently that one of the PHP installations stopped working all of a sudden.

It is not a problem, I can use the Homebrew installation.

Thank you all for your help!
I
 
Apache is running. I can access regular HTML files
just because you can access HTML files does not mean Apcahe is running or correctly, Apache deals with PHP. You can run HTML without any programs 🙂

Try this:-

1. Ensure PHP is installed:
Open Terminal and run the following command to see if PHP is installed on your system:

Code:
   php -v

If it returns a version number, PHP is installed. If not, you'll need to install PHP.

2. Check Apache’s PHP module is enabled:
You need to make sure Apache is set up to handle PHP files. On a Mac, the Apache config file is typically located at /etc/apache2/httpd.conf. You can open it by running:

Code:
   sudo nano /etc/apache2/httpd.conf

Look for the following line:

Code:
   #LoadModule php_module libexec/apache2/libphp7.so

If it has a # in front of it, that means the PHP module is disabled. Remove the # to enable it, like this:

Code:
   LoadModule php_module libexec/apache2/libphp7.so

Save the file by pressing CTRL + X, then Y, and Enter to exit.

3. Restart Apache:
After making changes to httpd.conf, you need to restart Apache for the changes to take effect:

Code:
   sudo apachectl restart

4. Test again:
Now try going to http://localhost/index.php again. If everything is set up correctly, it should execute your PHP code and display the output (e.g., "hello") instead of the raw PHP code.

Let me know if this resolves the issue. 🙂
 

New Threads

Buy us a coffee!

Back
Top Bottom