Getting blank PHP page over Apache

前端 未结 8 1594
南方客
南方客 2020-12-14 10:37

In a newly setup digitalOcean cloud server (CentOS), I have installed php and Apache. The webserver is running fine:

[root@a2m5cent01 httpd]# service httpd s         


        
相关标签:
8条回答
  • 2020-12-14 10:46

    Are you navigating to the php file directly? Or are you just going to the directory root?

    If the later, Apache might not be recognizing .php as the directory index.

    To test, try create a .htaccess file in your web root containing the following line:

    DirectoryIndex index.php
    
    0 讨论(0)
  • 2020-12-14 10:48

    check out your phpinfo() script.

    <?php
    phpinfo();
    ?>
    

    missing the "php" behind the first "?" will give a blank page

    0 讨论(0)
  • 2020-12-14 10:49

    It's been sometime, but I wanted to come back to this question to update that the issue was with the directory permission setup.

    The FPM user I was using didn't have necessary permission to execute the index.php file in the web root.

    To avoid these issues in the future, I have created an automated bash script that will automatically create and configure webservers in DigitalOcean boxes. Please take a look here https://github.com/akash-mitra/fairy

    This script will automatically,

    • Installs Nginx
    • Create virtual server block for nginx
    • Installs PHP, PHP APC, PHP Curl etc.
    • Supports PHP Fast Process Manager (php-fpm)
    • Installs Memcached
    • Installs Database (MariaDB / MySQL)
    • Optionally Installs PHP Composer and Laravel
    • Configures and Strengthens SSH
    • Activates Firewall
    • Optionally enables SWAP space in DO server and fixes a locale issue
    0 讨论(0)
  • 2020-12-14 10:55

    Sorry to repost an old thread...this is important.

    I also was having these problems where no html response was outputting

    After double-checking php.ini or my apache conf files and was still receiving no output, I later found out that I was suppressing the error of an include / require of a class, with @, which was nested within a constructor function. There was a syntax error in the included file, which stopped all output altogether when errors were thrown.

    So, check your handlers first. If you are storing all your output into vars first and you are including various scripts first that fail you'll have to see those errors. If you suppress file handler errors, you'll get a blank screen if you have a syntax error in the file.

    Search your files for all instances of @ in your php code. Then turn @include "/path_to/script.php"; to include "/path_to/script.php"; or anything @$foo into $foo as such var might reference a dependency that is causing your script to end with nothing showing in the httpd error log or in the http response.

    0 讨论(0)
  • First of all you should check the permissions of your file. If you don't grant read-permission to public, Apache produces a blank page without showing any errors.

    0 讨论(0)
  • 2020-12-14 11:02

    I think your php installation with apache is faulty. Thats why you can not see any php page in your webserver. Clean remove all the existing apps, like httpd,php,php-fpm,php-cli etc. and try to clean isntall in this order

    yum install httpd -y
    yum install php php-common php-cli php-gd php-curl php-fpm -y
    

    then make sure you restart yout httpd server.

    service httpd restart
    

    Install mod_fastcgi:

    yum install  mod_fastcgi
    

    Start the service:

    service php-fpm start
    

    Restart Apache:

    service httpd restart
    

    5. Configuration of Apache with PHP-FPM

    Open the fastcgi.conf file:

    nano /etc/httpd/conf.d/fastcgi.conf
    

    Add this to the end of the file:

    <IfModule mod_fastcgi.c>
                    DirectoryIndex index.html index.shtml index.cgi index.php
                    AddHandler php5-fcgi .php
                    Action php5-fcgi /php5-fcgi
                    Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
                    FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -host 127.0.0.1:9000 -pass-header Authorization
    </IfModule>
    

    After that search after "FastCgiWrapper" and make sure it's set to "off" then save the file.

    The /usr/lib/cgi-bin/ directory must exist, so we create it:

    mkdir /usr/lib/cgi-bin/ 
    

    If mod_php is installed and enabled, we need to disable it so open the configuration at /etc/httpd/conf.d/php.conf:

    nano /etc/httpd/conf.d/php.conf
    

    Comment out the AddHandler and AddType lines so it looks like here:

    #
    # PHP is an HTML-embedded scripting language which attempts to make it
    # easy for developers to write dynamically generated webpages.
    #
    <IfModule prefork.c>
      LoadModule php5_module modules/libphp5.so
    </IfModule>
    <IfModule worker.c>
      LoadModule php5_module modules/libphp5-zts.so
    </IfModule>
    #
    # Cause the PHP interpreter to handle files with a .php extension.
    #
    #AddHandler php5-script .php
    #AddType text/html .php
    #
    # Add index.php to the list of files that will be served as directory
    # indexes.
    #
    DirectoryIndex index.php
    #
    # Uncomment the following line to allow PHP to pretty-print .phps
    # files as PHP source code:
    #
    #AddType application/x-httpd-php-source .phps
    

    Save the file and restart Apache:

    service httpd restart
    
    0 讨论(0)
提交回复
热议问题