Cannot Access .php File Through Browser

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?

Gravatar — онлайн-сервис, позволяющий пользователям Интернета поддерживать постоянную картинку на большинстве сайтов.

William Moore

2 months ago

2 answers

133 views

Rating

08
Answer

Answers

Gravatar — онлайн-сервис, позволяющий пользователям Интернета поддерживать постоянную картинку на большинстве сайтов.

Tiago Oliveira

1 month 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
Gravatar — онлайн-сервис, позволяющий пользователям Интернета поддерживать постоянную картинку на большинстве сайтов.

Alessandro Gallo

1 month 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