Current Location: Home> Latest Articles> How to Fix PHP Not Parsing on CentOS – Troubleshooting and Configuration Guide

How to Fix PHP Not Parsing on CentOS – Troubleshooting and Configuration Guide

gitbox 2025-06-23

When deploying a web application, issues with PHP not parsing correctly on CentOS can disrupt your website’s functionality. These problems are often caused by misconfigurations, missing modules, or improper file permissions. This guide will help you systematically troubleshoot and resolve these common issues.

Check if PHP is Installed

First, make sure PHP is installed on your system. Run the following command in the terminal:

php -v

If you see the PHP version information, it means PHP is installed. If it returns "command not found", you need to install PHP first.

Install PHP and Common Extensions

You can install PHP and its commonly used extensions using the YUM package manager with the command below:

sudo yum install php php-cli php-mysqlnd php-gd

After installation, confirm it worked by checking the PHP version again.

Verify and Edit the PHP Configuration File

The main PHP configuration file is usually located at /etc/php.ini. Use a text editor to open it:

sudo vi /etc/php.ini

Pay close attention to the following settings:

  • error_reporting: Set it to E_ALL to display all errors.
  • display_errors: Set to On to help with debugging during development.

Ensure the Web Server Parses PHP Correctly

If you're using Apache, make sure the relevant PHP modules are installed:

sudo yum install php-mbstring php-xml

Then, check Apache’s main configuration file at /etc/httpd/conf/httpd.conf to ensure PHP is enabled:

LoadModule php7_module modules/libphp7.so

After making changes, don’t forget to restart Apache.

Fix File Permissions and Ownership

Incorrect file ownership or permissions can prevent PHP files from being executed. Make sure the web server user (e.g., apache) has access to your PHP files:

sudo chown apache:apache /path/to/your/phpfile.php

Then, set the proper file permissions:

sudo chmod 644 /path/to/your/phpfile.php

Restart the Apache Service

After making the changes, restart the Apache service to apply them:

sudo systemctl restart httpd

Check Apache Error Logs

If PHP still doesn't parse, examine Apache’s error log for more detailed information. By default, it's located at:

/var/log/httpd/error_log

Use this command to monitor the log output:

sudo tail -f /var/log/httpd/error_log

Conclusion

PHP not parsing on CentOS is typically caused by installation issues, missing modules, or misconfigured settings. By following the steps outlined in this guide, you should be able to identify the root cause and resolve the issue. Regularly reviewing your server configuration helps ensure stable and secure operation.