I am experimenting with using AWS. To be specific, I am following the tutorial at this link:
https://aws.amazon.com/getting-started/hands-on/build-web-app-s3-lambda-api-gateway-dynamodb/module-three/?e=gs2020&p=build-a-web-app-two
I have tried to add empty PHP tags to the start of the file and renamed the file to index.php instead of the index.HTML of the tutorial. I did a full sequence of refreshing the web app resources and deploying the app on the Amplify console. It did not work. I tried only using the HTML code on index.php and it still did not work. I put back the PHP code, added an echo statement echo "<h1>PHP Code Ran</h1>"; but renamed the file to index.html and it did render. Granted, there was an error in the text output. It also wrote the ending semi-colon and ending quotation, but it worked.
Is there any way for me to use a file named index.php as the home page of a web app using AWS amplify?
A PHP file isn't just an HTML file with a different name: you need to have a server somewhere that's running PHP which will look at the PHP code and run it.
If you're just uploading files to S3, that's not going to happen, the file is just going to be sent straight to the browser, regardless of what you call it and what you put in it.
Putting <?php echo "<h1>PHP Code Ran</h1>"; ?> into a file "worked" only in the sense that when you opened the page in the browser, you saw your browser's best attempt to interpret that as HTML. If you go to "View Source", you'll see that the file is exactly what you uploaded to S3, no PHP has run at all.
If you want to write a PHP application, you need to understand how to run PHP - most likely on an EC2 server, but it could also be in a Fargate container, or something even fancier like bref which lets you run PHP in a Lambda function.
Related
I am having issues while running the live preview of some php files on LOCALHOST. Like I am working on Wordpress theme and while I am able to set the correct base URL and open the file on the browser through index.php, but I am not able to edit and view the other php files.
For example, I have to open index.php which is in http://localhost/test but suppose I want to edit the header.php file. I click on the header.php file and it opens a new page in Browser with URL, http://localhost/test/header.php, which returns a 404 error through wordpress(OOPS PAGE NOT FOUND!)
I have very little work with index.php and mostly with header, footer, functions and everything else. Although this isn't really a big issue, I can go with the traditional way but I really wanted to utilize this Brackets Feature. Hope there's something to get past this :)
This is not an issue this will never open in browser like single file, if you want to check this then header.php and footer.php files are also included into the index.php , you will check from that no need to run them to browser.
I'm a frontend developer and I'm facing with a problem.
Whenever I'm building a website, I'm using PHP to include the template files, so I get a redundant code.
But when I want to generate this file into an HTML file I open up the PHP file in the browser to copy/paste the code to an HTML file.
How can I make this process to be way much faster, or how could I avoid to do these things manually? Maybe there is a program to do this or something?
You can use a recursive wget.
Say your webserver runs on your localhost, you can run:
wget -r -k localhost
Be careful: wgetdoes not perform a search on which pages are available, it simply looks at links (the <a> tags) and will capture these as well. As long as everything is reachable from the index page (not necessarily on the index page), it will be downloaded.
wget is a linux program, but I guess there is a Windows application with the same name/options as well... As #rkbvkleef points out, it's part of the MinGW package.
Basically your php file (which runs on server, could be local server) contains or generates your HTML code to present on browser. You can simply write HTML code out of tags in a php file and it will work. Or if you want to generate some HTML based on some conditions you are checking inside php or using some variables in php then you can use echo function. It will display whatever string you echo on your webpage.
<?php
$name = "Murtaza";
echo("<h1>Hello ".$name."</h1>");
?>
So I've created a php webpage with a head section that links to some bootstrap css files and my custom css file. This webpage also has a foot division that links to the necessary jQuery and bootstrap JavaScript files. That's all fine and dandy: I know it works because when I launch this .php in firefox, I can see that Bootstrap has taken control and stylized the text. The problem occurs when I try to break this webpage up into components...
I've created a separate head.html and foot.html which include the same content as before they were broken up, and on the .php page I use the following include statements:
<?php include '../components/head.html'; ?>
<?php include '../components/foot.html'; ?>
Now when I launch the php from my browser, the links clearly haven't worked because the text is not styled. Upon choosing to "view source" of the .php, I see that it has not included the markup from head.html or foot.html, and instead I still see the literal <?php include '';> statements. What have I done wrong? I know the relative filepaths are correct, so perhaps it has something to do with the fact I'm trying to launch the php page locally? Perhaps the components should be .php instead of .html? I really don't know.
Additional info: Win7, tried using notepad++ because Dreamweaver keeps giving me FTP errors every time I ask to "preview in browser"
First you should have a webserver installed along with PHP. You may use xampp or wampp. If you simply open a php file in your browser then it will not execute the PHP statements instead will display the code as it is.
Except for not having a web server along with PHP installed in your system you have done nothing wrong as I see.
The head.html and foot.html can be html files and not .php files that would not be an issue till the file containing the include statment is .php file.
I went to edit this PHP file - it's supposed to generate those captcha security images on contact forms - the images werent working, so I was going to see if there was a broken path or something i could fix simply.
But when I opened the file it looked like this:
http://mydomainsample.com/explosion/screenshots/Screen%20Shot%202012-05-17%20at%209.34.14%20AM.png
complete gibberish.
Is it possible this happened somehow while downloading the file from the server? I did not have ftp access to the site originally - we got control of the domain and transferred it from one host to another.
I used site sucker to backup the site before transferring, but it downloads php files as html files. you end up with filename.php.html.
in the past this has never turned the php into incomprehensible gibberish, so i dont understand why it did now.
The problem is, you cannot use programs like "site sucker" to get PHP files. This is because when you get a PHP file from a URL, the file is executed, and you're getting the output of the script. That's why you get .php.html.
It doesn't "turn the php into incomprehensible gibberish", the server runs the script and you're getting the output. Most of the time the output is HTML, which you can open as text. In this case, the script's output is a PNG file, thus why you see "gibberish". Rename the file to .png, then you'll see the image.
You need to get FTP access in order to get the PHP source.
That's a PNG image, not PHP source code.
The file actually looks like a PNG image, maybe you just downloaded output the PHP script has generated?
I have a weird unexplainable phenomenon going on.
I downloaded some source code from a website, a basic PHP script. It came with an SQL to reference numbers as part of the script.
I uploaded the file called post.php and SQL file to my server and ran it - but - instead of executing the code in the PHP file, it loads the content of the webpage of the author of the source code. and stays on my server URL.
The code in the file has nothing to do with the author's site, or graphics or links or redirects or anything.
EVEN IF I delete the entire contents of the post.php file, run the empty file and it STILL LOADS CONTENT from the author's website, where I downloaded it from.
Refreshed browser, restarted, reloaded, you name it. How is this physically possible?
-----UPDATE
In addition when I try renaming PHP files on my server, they become permanently broken "oops broken link" error.
It would be very helpful if you could post some more specific details about what the script was, etc. But, here is my guess. Firstly, make sure that your web server is not doing any caching. If the problem persists, try getting rid of the post.php file itself. Then, I would check to see if the PHP script has created any HTML/PHP files on its own. If all else fails, try going into the code that you downloaded and see what its doing.