Cannot Access .php File Through Browser (Edited)

I set up a VPS and created a folder inside the /home/ directory named share-br. I’m trying to access an index.php file located at /home/share-br/index.php through my browser.
The URL I’m using is:

		
http:///share-br/index.php

However, the browser returns a 404 error, and the page doesn’t load.
How can I access my PHP file on the server?

William Moore

16 days ago

2 answers

86 views

Rating

08
Answer

Answers

Tiago Oliveira

3 days ago

Rating

00

The /home/ directory is not meant to serve web content directly. To make your PHP file accessible via the browser, you need to place it in a directory that your web server serves, such as /var/www/html/.

Steps to fix it:

Install a web server (like Apache) and the necessary PHP components:

		
sudo yum install httpd php php-fpm

After installation, start and enable the web server:

		
sudo systemctl start httpd sudo systemctl enable httpd

Now, move your PHP file to a directory accessible by the web server:

		
sudo mv /home/share-br/index.php /var/www/html/

After moving the file, try accessing it via your browser:

		
http:///index.php

Now, your PHP file should be accessible through the web server.

Reply

Alessandro Gallo

5 days ago

Edited

Rating

00

That's not how web services work.

You need a web server that can handle HTTP requests and serve files. Either you write an HTTP server to do that, or you use Nginx, Apache, or PHP-FPM to handle PHP scripts.

Reply