简体   繁体   中英

Apache2 installed but unable to run php file

I've Apache 2.4.27, PHP 7.0 and MySQL installed in Ubuntu 16.04. Yesterday I was able to run php files on my local Apache server but today I'm getting this error

Firefox can’t establish a connection to the server at localhost.

Apache localhost server is working( when I type http://localhost in url, It Works! is displayed ) but I'm just not able to access files on the server. Files are stored in /var/www/html and here are some details from httpd.conf

ServerRoot "/usr/local/apache2"
Listen 8080
ServerName localhost 
DocumentRoot "/usr/local/apache2/htdocs"
<Directory "/usr/local/apache2/htdocs">

Ports.conf -

Listen 8080

<IfModule ssl_module>
        Listen 443
</IfModule>

<IfModule mod_gnutls.c>
        Listen 443
</IfModule>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

output of

 sudo iptables -t nat -nvL 
Chain PREROUTING (policy ACCEPT 22 packets, 3778 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain INPUT (policy ACCEPT 18 packets, 2394 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 4443 packets, 310K bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain POSTROUTING (policy ACCEPT 4443 packets, 310K bytes)
 pkts bytes target     prot opt in     out     source               destination         
    9   624 RETURN     all  --  *      *       192.168.122.0/24     224.0.0.0/24        
    0     0 RETURN     all  --  *      *       192.168.122.0/24     255.255.255.255     
    0     0 MASQUERADE  tcp  --  *      *       192.168.122.0/24    !192.168.122.0/24     masq ports: 1024-65535
    0     0 MASQUERADE  udp  --  *      *       192.168.122.0/24    !192.168.122.0/24     masq ports: 1024-65535
    0     0 MASQUERADE  all  --  *      *       192.168.122.0/24    !192.168.122.0/24 

You should call it from http://localhost:8080 because you have Listen 8080

Edit based on comments bellow

If your document route is the following:

DocumentRoot "/usr/local/apache2/htdocs"

It's normal that Apache doesn't find your files because it's looking into /usr/local/apache2/htdocs . You should move your file there or update your DocumentRoot and all occurrences of /usr/local/apache2/htdocs to /var/www/html .

Edit 2

DO NOT FORGET to restart apache with sudo systemctl restart apache2.service (or sudo /etc/init.d/apache2 restart if you don't have systemctl) after any change of httpd.conf

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM