I want to start learning php, I install apache 2.2 and I want to run my first.php file, I look for www folder in the installation folder of ApacheSoftwareFoundation but I couldn't find it.
here's the files in the apache
I tried to put my php file in htdocs but it doesn't work , can some one help ?
Edit
Doesn't work means when I make http:localhost/first.php , returns Unable to connect
Now the apache is running, when I open htt'://localhost/
returns "it works"
but when I open any php file, it opens as-is ?!
You'll need to check a couple of things...
Make sure the Web Server is running ,either the service
or the program, is running and that you have the correctly configured the Virtual Directories.
If the web server just outputs the
content of the .php file, it could
mean that you don't have mod_php
installed. Meaning the server does
not have the Mime type registered so
it will just try to treat it as a
text file ...
And as your on windows you might consider using something like XAMPP. It gives you a Full Working AMP (Apache Mysql Php) Stack with one install and a easy control manager to start/stop the servers. Other wise do a couple of Google searches on how to install the php module for your Web Server on Windows
Update
To start the server try executing the executable bin/httpd.exe .
Now the apache is running, when I open
http://localhost/ returns "it works"
but when I open any php file, it opens
as-is ?!
A default installation of Apache on windows does not include the necessary modules to run PHP. After installing Apache, you must either:
Install PHP separately and follow the instructions described here to configure Apache to use the installed version of PHP to serve .php files. I've been through this and took me hours to get every thing to work.
Recommended for you: uninstall Apache; install WAMP instead.
if you look in your httpd.conf file you will find the default root directory, it doesnt have to be called www. It is the htdocs by default.
error 500 covers a whole host of things. from compile error, to permissions.
Have you put a simple file of
<?php
echo "test";
?>
As your test php page to rule out other issues?
You need to:
Construct your URI correctly: http://localhost/first.php (with the //)
Ensure that Apache is running
all files in htdocs can be referenced from outside
Just put a basic file named index.php
and visit site http://localhost/
In general type in http://localhost/filename
You say that you get a connection error when you try to go to your webpage. Since it looks like you're using Windows Vista or 7, make sure you're running Apache as an administrator; it can't bind to port 80 otherwise. Also check that other programs like Skype aren't binding to port 80. If you still can't find the problem, check the error log. (logs/error.log by default I think)
The problem is that Apache was installed but not started
If you are using xampp start it and then start apache through control panel
for others look for similar instruction
Related
My computer is a Windows 10 64 bit.
I tried to run my PHP code, steps:
Downloaded php.net.
Set the environment variables path as instructed. Ran the command line like this: https://imgur.com/a/Q9zs9mL
Microsoft Windows [Version 10.0.17134.345]
(c) 2018 Microsoft Corporation. All rights reserved.
C:\Users\Mai Do>php -S localhost:4000
PHP 7.2.10 Development Server started at Mon Oct 22 21:04:32 2018
Listening on http://localhost:4000
Document root is C:\Users\Mai Do
Press Ctrl+C to quit.
Created a PHP file, first with NetBeans
Saved the file in the root directory folder named "php1" (try to be different from my root name)
Typed in browser: localhost:4000/php1/input.php
Object not found 404 page.
Tried multiple times with different php file. same thing.
Switch to Atom. Same thing.
Moved the file to htdocs folder. Same thing
Download Xampp. Turn on the Apache and MySQL. XAMP ver 3.2.2 control panel shows up. Both Button turn to Green. Still not found.
This SO page PHP not working in XAMPP says:
If you're trying to connect via your IP then your router must be
stopping it so you have to sort the settings out. I don't know your
router make/model you better off asking their support forums.
I am thinking there might be a server config problem. Like this one has a similar issue: Apache2 not working with routes PHP
which leads to this:
https://docs.bolt.cm/3.0/howto/making-sure-htaccess-works
"Editing the apache2.conf and setting 'AllowOverride All' on , finally
works." ???
I am not sure if that is the right problem either. Can someone walk me through it? Bless you.
To set up a test environment on your personal computer, follow the steps below:
Remove any installed PHP (Windows: uninstall via "Add/Remove Programs")
Install XAMPP (in your case, it's better to re-install the software suite)
XAMPP is a software suite that contains PHP + MariaDB (a fork from MySQL) + Apache Web Server + Perl. In your case, you are going to use PHP & Apache only.
Configure the DocumentRoot in Apache config file; you should put your website files in this DocumentRoot, thus I recommend you to set the path value to your development path. Read the manual if you're unsure how to do so.
Start/Restart Apache. If everything goes smooth, Apache should be up and running at port 80 (by default).
Launch your favorite browser and navigate to http://localhost
You should see your website written in PHP
If you have any further questions, please ask in the comment box below.
Note:
NetBeans is an IDE, not related to your testing environment
You can actually write your PHP scripts using any text editor
So I want to use Xampp to control my servers. I already installed Apache2 and now it orverrides localhost.
Whenever i put localhost/xampp/index.php it says OBJECT NOT FOUND.
How would I delete this Apache program, and strictly use Xampp on localhost?
I already tried to change the .conf file to Listen 8000 and when to http://localhost:8000/xampp/index.php
Steps:
Open "XAMPP controll panel and run Apache and MySQL"
create folder www inside xampp\htdocs, if you are on win propably C:\xampp\htdocs, so now you have C:\xampp\htdocs\www\
Create test.php inside C:\xampp\htdocs\www\, now you have C:\xampp\htdocs\www\test.php
Put inside test this: <?php echo 'php works fine.'; ?>
Run this script in browser on link "http://localhost/www/test.php" you will see "php works fine.".
DONE.
Have you started apache by opening up Xampp control panel? If you didn't then it won't work. So open up Xampp control panel from the start menu and click on start where it says apache and then run http://localhost to see whether it works.
Have a look at the :
\xampp\apache\logs\error.log
This might give you an idea, why the XAMPP splash screen cannot be found.
Also, make sure you do not have any IIS or similar programs running, as they might have a conflict with the XAMPP.
You can also check if the port is open or not using the instructions given here..
Cheers.
I might be wrong, but it seems to me that everything on localhost is coming from htdocs, but you don't call it from htdocs in the URL.
I need to use Chrome to run a local PHP file. I believe I've done all that is required to do this (acc. to multiple web sites, inc. php.net), however, all I get is a blank web page. The things I've done to enable this capability are:
Install MS Visual C++ 2010 x64 Redictributable 10.0.40219
Enable IIS on my Windows 7 Home Premium PC by following instructions at http://php.net/manual/en/install.windows.iis7.php, including executing at the cmd line their "Examples" 2, 3, 4, 5, 6, 9, and the one enabling 64 bit operation
download php-5.4.31-nts-Win32-VC9-x86.zip, then follow instruction re: changing the php.ini file at http://php.net/manual/en/install.windows.manual.php (e.g., copy the php.ini-production into php.ini)
Put my php script into the folder C:\Users\Wade\AppData\Local\Google\Chrome\User Data\Default\User Scripts the script is simple:
<?php $row = "1.jpg";
echo $row;
?>
In Chrome, entered the url http:/localhost/<script-file-name.php>
Please help!
If you want to run PHP on IIS server then you can go with Microsoft Web Platform Installer.It automatically configures IIS server with PHP for you.
I'm not used to chrome, but i doubt this folder is made to run local php script.
Do you have some reason for choosing IIS ?
If not, and if you just want to run php file locally, you'll probably find a lot easier to use some programs such as Xampp to install & configure a little Apache web server for you.
If you choose to go this way, you need to :
disable or uninstall IIS , to prevent conflicts.
download xampp installer for windows : https://www.apachefriends.org/fr/index.html (some other alternatives exists, easyphp, etc.. )
install like any other program, the default settings are probably good enough.
delete all the files in the newly created c:\xampp\htdocs\ folder.
launch c:\xampp\xampp-control.exe (that may not be the exact name, but it's easy to spot in the folder) , and check that the Apache module is marked as started ( if you installed it as a service - which i think is the default - it will launch on windows start )
put your php files in c:\xampp\htdocs\
navigate to http:/localhost/
Hope this helps.
I have Joomla installed in my computer, but recently have been writing php files that aren't related to the Joomla-managed site. For some reason, when I try to open those php files in the web browser using xampp (note: Joomla also is using xampp), the browser doesn't process the code w/in the tags as php code.
For example, after opening a basic page (a page with title "test", no content except in the body tags) in the web browser and going to the source code, the following is shows up in the source code:
<body>
<?php echo "hello"; ?>
</body>
instead of the HTML conversion. (i.e. just "hello")
Does anyone have an idea about what's going on here?
Thanks.
It's probably because PHP module isn't loaded in your apache. Be sure it is enabled
PHP is interpreted in the server, not the browser. Whatever's going wrong, you need to look at the SERVER side to resolve it.
My first guess: maybe you didn't suffix the file ".php" (so the server doesn't recognize it as a PHP file?)
Second guess: is the directory containing your PHP files configured to parse PHP?
If you have Joomla, you probably have PHP. You probably also have Apache.
So check your Apache configuration, and check your file naming conventions.
Is the file extension .php? The server doesn't magically know when you're serving php files, this is a good way to ensure it knows what you're doing.
Apache is looking into your localhost's defined root directory for files it can parse. In this case htdocs. This is the default for XAMPP. As far as Apache is concerned, it will not interpret any files outside of that folder.
if the problem in php module it better to re install php5 in to the system and it will work fine. probably the problem is in php module you should try re installing php in your system.
Just restart httpd service. It will work fine.
sudo systemctl restart httpd.service
if it has not worked please reinstall PHP once again.
I've just installed LAMP on my Ubuntu 9.10 machine, and everything works fine except when I copy my PHP files from another computer.
The LAMP guides I've followed also made me create a phpinfo() test file, which works, but when I try to type in e.g. index.php absolutely nothing happens - just a blank page in FireFox. :(
The files are in the exact same directory.
I'm thinking it's probably something with permissions and so on, but since I'm new to both PHP and Ubuntu, I'm kind of lost. It's like I can't create a PHP file with my file browser, but only by using the terminal - like when I created the testing.php from the LAMP guide.
Whaddayaknow... I made an error, tried to:
echo "Hello" world
which, even though I'm a PHP noob, I clearly know is wrong.
I think I'll have to figure out how to enable some sort of error reporting, a blank page is clearly not good enough.
You mean you have a index.php (copied from another computer) and a test.php (edited by hand, with a call to phpinfo()) in the same apache directory, the second works from your browser and the first doesnt ?
That can be a permission issue, or some compilation error in your php.
About permissions, for files should be readable from the apache server (more precisely, form the user that runs the apache server). You can type chmod a+r index.php.
YOu can also check your apache error logs (location dependent on installation). In any case it's vital to know where the error logs are if your are developing a web site.