I'm trying to follow a tutorial for my first php project in netbeans. I select new php application name it and then simply type echo("anything") in the php portion of index.php and when I run it I always get the error Oops! Google Chrome could not connect to localhost. I don't understand why because I also have a Java web application(selection from netbeans) and when I put stuff in the html I can get things to run just fine. How can I get rid of this issue?
Make sure that PHP is running on your machine (XAMP or WAMP) and it should be echo "anything";
PHP requires that the PHP parser is running on a server. The error comes from a lack of this. HTML requires no parser so it can be sent as is. The java web application may have a module to enable PHP, and you likely need to either enable it or tell it where a PHP binary is; if not both.
Alternatively, you can use XAMPP/MAMPP to host the server; just make sure it is not running on the same port as your java host.
You can get XAMPP/MAMPP here:
www.apachefriends.org
Related
I am currently developing a web application using AWS services and it's written in PHP. Previously, I used XAMPP to do the work, but now I use EC2 and RDS (MySQL) of AWS. And I also hosted the web on domain using Route 53 and it is secure with Certificate Manager (HTTPS enabled).
This is how I do my job. Sublime Text to write code, then copy paste the file from local to server using WinSCP. If nothing wrong, the code will instantly reflect in my webpage. However, unlike XAMPP, the ERROR will reflect exactly which line is going wrong. The approach I am using will only show HTTP 500 (Request cannot be handled) within the webpage.
For now, I have to test code by code to find the ERROR and it's a waste of time. So, if I want to view which part is going wrong like XAMPP, how can I do so?
Thank you.
In a production environment, it is recommended to switch off detailed errors so that your implementation details are not exposed. Sounds like this is the problem you're facing with the new setup. You need to enable this in your php.ini file, and you might want to look into your .htaccess as well.
Check out the answer here for a more detailed explanation - How can I make PHP display the error instead of giving me 500 Internal Server Error
Here's a guide on implementing the changes you need - https://stackify.com/display-php-errors/
By default, the Errors logs are stored at /var/log/apache2/error.log. So you can do something like the below to see the apache logs in real-time:
tail -f /var/log/apache2/error.log
I'm new to web development. I'm trying to execute a shell script using PHP's shell_exec(). Inside the script, I'm trying to invoke a GUI application(Qt). When I executed the PHP script from a terminal the application started as expected. But when I opened it from browser an empty blank page appeared.
I'm using Ubuntu with apache2 server running as service. When I searched in google, the similar problem is solved in the Windows environment by allowing apache service to interact with the desktop.
PHP Script:
<?php
$log = shell_exec('sh testcmd.sh');
?>
testcmd.sh:
./Program1
Any help provided will be highly appreciated.
It is somewhat unclear what you're asking.
If you wish that browsing to a certain web site will run a PHP script that will open a GUI app for the client to interact with, the answer is "you can't". The reason is that the way the setup works is that the server and the client run on different machines, and your PHP runs on the server machine. As such, the client never gets to see the running program.
The above is true also for Windows. The answer you quote in your question does not apply to a server running on a different machine than the client.
If, for whatever reason, you want something that works only when the server and client run on the same machine (or there is someone watching the server's display), then you need to do the equivalent of the Windows answer.
The graphics display on Linux (assuming you're not running wayland) is using a protocol called X11. In order for the display to appear, your GUI program needs two things. The first is to know which display it needs to use. This is supplied with an environment variable called DISPLAY. The second is an authorization to actually use that display.
So in order for your PHP script to run a GUI app that will show its GUI, you will need to first do the following steps:
Set the DISPLAY variable to the correct value (copy from your desktop environment).
Run xauth add something, where you can get what something is by running xauth list on your desktop environment.
If you do these two things (in this order), your GUI should show up.
I am studying on YouTube HTML5 forms with PHP files; the videos either start with a web page containing the form and link to a PHP file or they put everything in php files; I copy the instructors exact files; but they do not work: nothing is posted after filling the form and hitting the submit button.
I have had the files on a USB flash drive then tried them actually on the computer: nothing.
My question is then: "Do I need to have an actual server on my computer in order for PHP files to function?"
Yes. PHP requires a web server to run on.
You can run it on your own computer; the web server doesn't have to be connected to the internet while you are creating and testing your PHP scripts off your local machine. You can read more about this on the official PHP What do I need page
You can download one of the following local servers:
Windows: WAMP
OSX: MAMP
Linux: LAMP
XAMPP is also an option, it's cross-platform (as referenced by ATechGuy)
Here is a good explanation of Why a web server is required to run PHP. Basically it is because PHP is a dynamic server-side scripting language.
However if you just want to run simple PHP scripts, with no web pages. This is possible without a web server running. See this question: How can I run a php without a web server?
Yes, PHP will need to run on a server in order to execute. If you have a Mac, it should be equipped to run an Apache server. I found this article to be really helpful when developing with PHP - https://jason.pureconcepts.net/2015/10/install-apache-php-mysql-mac-os-x-el-capitan/
Yes. PHP files contain code that must be handled by an interpreter, that is, a program that reads the PHP code and outputs accordingly. This can be done without a webserver (using command line php) but PHP is most commonly used with a web server.
You want to setup some sort of stack with a web server and php. A lot of beginners use apache as a web server, and since you are comfortable using youtube for learning, a simple search for "apache php" and your operating system.
I have two html forms and two php scripts. The first one is a form which is supposed to submit a users email to a .txt file, and the other is a Stripe payment form which uses php code to charge the customer.
Now my problem is that there are some issues with the two php scripts, that I can't figure out how to fix, because I am not really sure how to test the scripts. Normally when testing the html scripts I would just open the html files in my browser, but that doesn't work on my php scripts as the site just shows what is written in the scripts when called/submitted.
So my question is how do I test my scripts, without having to use a hosting account and can I even test it like this?
You need to run a web server on your local computer to test it out. I would suggest looking into something called Vagrant, which allows you to fairly easily create virtual machines on your computer in which you can install anything you like without fear of messing up anything else. If you go here you can even find a "box" to create a virtual machine that already has apache and php installed.
Depending on your version of PHP there's a webserver builtin right into PHP:
http://php.net/manual/en/features.commandline.webserver.php
You probably have to install a web server locally with php enabled. Since php is a server side language it needs a server to run on, in order to send you back the html, after execution. If you need to see the result on a browser.
http://en.wikipedia.org/wiki/LAMP_%28software_bundle%29.
Or run your script from terminal (you must have php installed) if you don't need to see the result in the browser and just want to run your script.
$ php myscript.php
Hi I got a strange problem with my LAMP installation
I'm using an Ubuntu Server with PHP5 Apache and mySQL, all runs great when accessing via http.
But the thing is, I also want to trigger some scripts using bash, basically so I can trigger them at will and prevent them being used via Apache/HTTP
The scripts themselves run when called with php5, all includes are found.
But for some unknown reason mySQL does not seem to initiate the Database the way it does via Apache. I just get a message back saying no database is connected.
Is there some special setup for bash related php calls?
Figured it out. There are no special DB settings for PHP run from Bash, However because I work on several Servers I was using the $_SERVER['HTTP_HOST'] variable to determin which login credentials should be used. Therefore it only worked on the server where the default credentials were correct.
For now I just put in an extra option in the code that uses credentials based on the value of the dirname(__FILE__) variable. Works great.