Where or how to find the document root when launching localhost - php

I'm fairly new to programming in general and even more on PHP, so basically I'm following this tutorial on how to print "Hello World" on a localhost but looking at the tutorial I see that the document root is shown when the localhost is launched compared to mine showing less information. So I'm unable to save my program in the right location since i can't seem to figure out where is that document root.

Your document root is configured in Apache (assuming you use PHP through Apache httpd server here).
Look in your httpd.conf file, you will find directive DocumentRoot, which will show you what directory it uses. It will most probably be something like .../htdocs or .../www or .../html.

Related

.htaccess file is not read in linux

I have a .htaccess file in a php project, I have the apache2 server downloaded and running, but it ignores my project's .htaccess.
When I test the project on Windows or put it on my hosting it works normally.
I already tried to edit the apache2.conf file, among several other methods that I found to solve, and nothing worked, the project worked correctly on the computer of my friends who have linux.
I start the project with the command php -S localhost: 1990 inside the folder that has my files, I tried other ways and nothing worked.
Can someone help me? I've been looking for a long time and nothing has resolved.
I apologize for my English, I'm Brazilian and I still can't speak English very well.
I start the project with the command php -S localhost: 1990
This uses the webserver built-in to PHP, not Apache. Consequently, this does not use a .htaccess file (or apache2.conf).
You need to call your PHP files through Apache - which you say is already "running". (?)
(Aside: There should be no space between localhost: and 1990.)
Reference:
https://www.php.net/manual/en/features.commandline.webserver.php

php url and folder name

I just installed the latest MAMP on Mac, and found this hard to understand:
The document root seems to be "~/MAMP/htdocs", because "localhost" will open the index.php file under this folder.
However, "localhost/MAMP/?language=English" opens "~/MAMP/bin/mamp/index.php". I know that in URL strings between "/"s are not necessaries folders, but if they are not folders, how was it constructed and how does the system know where to find the right files?
I know this is a pretty basic question which I can probably get answers by myself, but I don't know what key word to search. Tried "php url construction" and "php url folder" but no luck. So a proper keyword suggestion is also appreciated.
It is setup by default by MAMP. If you open up MAMP/conf/apache/httpd.conf in a text editor and scroll down to around line 368/369 and specifically line 408 you will see that it is an Apache Alias. it is setup for easy navigation, instead of having to type http://localhost:8888/bin/mamp you can just type http://localhost:8888/MAMP. It is also setup as an Alias to ensure that you can still access the web tools if you change the document root from something other than /Applications/MAMP/htdocs.
Are you sure http://localhost:8888 has the docroot set to ~/MAMP/htdocs as you suggest? Reason I ask is that looking at your first image the text says the docroot is /Applications/MAMP/htdocs. Also the docs say it should be in the /Applications/MAMP/htdocs. I think the issue is that you do not have MAMP in the Applications folder where it needs to be.
https://www.mamp.info/en/documentation/
Where should I store my HTML and PHP pages?
By default, PHP and HTML Pages should be stored inside the MAMP
"htdocs" folder which is located in the MAMP Application directory
/Applications/MAMP. This folder is called "Document Root". You can
change the path for the Document Root in the MAMP application's
Preferences Panel:
Also please note this https://www.mamp.info/en/documentation/#q8
Will MAMP work if the MAMP folder is not located in the Applications
directory?
No. In order to work properly the MAMP folder has to be located in the
Applications folder.

View php webpage offline

How can I see a webpage with extension php without uploading it to the server?
I want to be able to see php files offline in order to preview a page before uploading it to the server.
My searches revealed that I need to have php installed. My OS is Ubuntu, and I did install php5 and apache2, but I can't figure out how to setup the server in order to see my files which are in /home/user/WWW
Is it possible to have a clear explanation how to setup a server properly and how to make it "see" my webpages? I'm not very advanced in web designing. I just want to design a simple webpage displaying my research. I found that writing in php makes things like header, footer easier to include in every page. On the other side, I really want to preview the files before uploading them...
Change the directory DocumentRoot in httpd.conf and restart your Apache server
#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/home/user/WWW"
If you just want to test your PHP without serving a Web page you can run php at a shell prompt with
$ php myScript.php
(see also How can I run a php without a web server?)
As suggested by Ologho Cyril Paul in its comment, XAMPP does the trick. It is easy to install, and its visual launcher has a config button which lets you change the DocumentRoot to your preferred folder. Once the server is active, typing localhost/your_site in your browser leads you to the webpages.
After changing all .html files into .php I found out that it is possible to make php code work in html. Too bad everyone says "it is not possible"... Just make a file called .htaccess in the folder containing your html files and add to it the following line:
AddHandler application/x-httpd-php .html
Now you can write .php code in html. (this was taken from other questions like this)

How to set up Apache to tell two domains apart?

I am just starting to look at PHP and Apache servers (at the moment use Ruby on Rails). I am looking to get two simple index.php files rendering in the browser, but they will be two separate sites. I have installed everything I need to I believe.
So if I go to localhost I get the Apache2 Ubuntu Default Page. This might be such a simple question but where do I store my files and directories? I have been looking in /var/www/.
I would like to create 2 sample sites as previously said. Could anyone point out where I should be looking and how I differentiate the two sites?
/var/www/ is your root folder for apache so your localhost is pointing to www. To create 2 different website you will require to create 2 new folder in www folder e.g web1 and web2 then localhost/web1 will point to /var/www/web1 same will goest for web2.
You can also set virtual host to make your web url like web1.com and web2.com check here on how to set virtual host in ubnuntu https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts
First, I would like to welcome you in this beautiful world of PHP :)
Now look into this file : /etc/apache2/httpd.conf and locate for this config DocumentRoot "THIS_IS_YOUR_DOC_ROOT_RICHLEWIS".
You can change it to your favorite document root an d restart Apache, or simply put your files here(php, html, images...

PHP sample project with wamp

I installed wamp stack and then installed netbeans ide. The port number for apache is 100.
Created one PHP project at
C:\Users\aaa\Documents\NetBeansProjects\PhpProject2
and project URL http://localhost:100/PhpProject2/
When I click on run, I see the message "http://localhost:100/PhpProject2/index.php URL not found on the server".
What else I need to do to connect http://localhost:100/PhpProject2/index.php to C:\Users\aaa\Documents\NetBeansProjects\PhpProject2?
Please help.
You need to configure Apache's webroot to be C:\Users\aaa\Documents\NetBeansProjects (search for DocumentRoot in the file httpd.conf).
Or you can move/copy your files to the existing webroot, which may be something like c:\wwwroot.
Apache doesn't just magically know where you put your website files, and setting the URL inside NetBeans doesn't actually configure the webserver (I think it's just so that auto-generated links are right).
If you go to http://localhost:100/, what do you see? What is your web root? The folder needs to be in your web root, and I would be surprised if it is C:\Users\aaa\Documents\
I did a Google search for "wamp stack" and found a product by Bitnami... if this is the one you are using, the default web root is C:\Program Files\BitNami WAMP Stack\apache2\htdocs\. If that is indeed the case, then you'd need to move the NetBeansProjects folder to there. (source: http://bitnami.org/files/stacks/wampstack/5.3.6-0/wampstack.pdf page 7)
You need to look into aliasing. That will let you more or less assign directories in the url path to arbitrary directories on your file system.
You have to move your files to your root folder of the Apache installation (htdocs). You should refer to your WAMP installation for where that is located. Personally, I like to use XXAMP for installation.
Netbeans is just an IDE, it doesn't serve the files.

Categories