i want to make an image gallery for my website that pulls jpg files from a directory, so i don't have to individually write <img> tags for all 100+ images. a php gallery seems to be the only way to go (though i'm open to other suggestions that might involve pure jquery/ajax, if that's possible!)
i have a very preliminary understanding of php. i've installed php 7 and apache 2.4, they're currently in the root directory of my computer. i was able to create a very basic 'hello world' index.html with a generated php image, which is also saved in the root directory at C:/Apache24/htdocs and hosted at http://localhost:
<!DOCTYPE html>
<html>
<body>
<?php
echo "<h1>Hello, PHP!</h1>\n";
?>
<img src="myimage.php" alt="Image created by a PHP script" width="200"
height="80">
</body>
</html>
however, all of my website files are located in C:/Documents/Github/xxxx/xxxx, which is where i usually push all of my commits from. i use jekyll as a server to test my site offline but there's no liquid code involved (it's a one pager written all in HTML and is hosted at http://localhost:4000)
this is how it looks when i copy the code from the 'hello world' index.html to my website index.html:
so i am wondering how to execute php on my website, which is hosted on github. i have a basic understanding of how it works locally at my root directory, but i'm not sure how to execute it in my local/remote github repos.
do i need to move the php folder? edit the .ini or httpd.conf files? install a plugin?
thanks!
EDIT: so i was able to get the php script to execute locally, but when i pushed my changes to github, the script wasn't executed?
LOCAL WEBSITE
REMOTE WEBSITE
okay, i may have figured this out.
i deleted the individual php and apache folders, and instead used wamp as my server instead of jekyll.
i then relocated my github repository to the wamp/www directory, and the php script is now executable on the local index.html file. i think a php interpreter is what might have been missing.
i am still having issues with getting the script to work on the live website.
Related
I'm a complete noob with wordpress and i'm trying to install it on my server.
I'm following the instructions on this site but when I get to step 5 and I go to the http://example.com/direct-admin/install.php I get this error:
Not Found
The requested URL /wp-admin/install.php was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
In my folder 'example.com', located in the 'domains' folder, I started with only stats and logs folders. The first time I added the Wordpress files in the 'example.com' folder.
I tried adding a public_html folder and putting the Wordpress files in the public_html folder but that didn't work either.
How can I install wordpress on my website?
What server are you using? There are several ways of installing WordPress, I would strongly recommend using the WordPress CLI to install WordPress. All you have to do is follow these steps:
Download the WordPress CLI using these five steps.
Use now the CLI to download WordPress:
$ wp core download
Create the wp-config.php file
$ wp core config --dbname="your_db_name" --dbuser="your_db_user" --dbpass="your_db_password"
And then you can put your website URL in your browser and continue following the wizard, WordPress will ask you what site name, username and password do you want to use.
If you're having trouble setting up a wordpress installation and you're getting 404 errors or "apache is function normally" then it's possible that your DNS/server settings aren't correct, this was my error.
First try creating a .html file with a simple text editor by copying the html markup below into a new file and then save it as index.html
<!DOCTYPE html>
<html>
<body>
<h1>My First Heading<h1/>
<p>My first paragraph.</p>
</body>
</html>
</code></pre>
And upload that to your server.
If you're still having errors you know it's not the wordpress installation that causes these but it's your server settings.
You should:
check if you are putting it in the right folder (like f.e. public_html)
make sure that your DNS configuration is correct
Check this answer for more information on how to setup your server to view a simple .html file.
I'm currently beginning with PHP and I wanted to get started with a mini-project for some hands-on experience. Here's the code that I began with:
<html>
<header>
<title>Test</title>
</header>
<body>
<h3>Some example title</h3>
<?php
$randomNumber = rand(1000,9000);
print "Here's a random number: {$randomNumber}.";
?>
<p>Some more text.</p>
</body>
</html>
However, when I saved it as index.php and previewed it on Google Chrome, the PHP part doesn't show up. Can anyone help me realize what I'm doing wrong?
Thanks!
To run PHP code (server side) you need a server, or a 'server-emulator' some of the most commonly used are:
XAMPP
WAMP
Unlike the html in your .php files, the php code must be processed by a server and returned to the browser. I've tested your code with a server and it works like a charm.
After installing one of the above "emulators" you need to (this is a simplified tutorial, check a real tutorial):
place your .php files in the public_html or htdocs folders that are
created in the emulator's folder in your computer.
Turn on your server
go to localhost/your-file-path/index.php
If you only need to test soft code (like what's on yout example) and not develop whole projects use IDONE
PHP is used in the server side, so, you need to install an environment (Apache, PHP) to interpret the PHP. If you use Mac or Windows, you can install Mamp. For unix, you need to install some packages, i'll invite you to see this tutorial: Lamp tutorial.
I know a bit of HTML but I'm trying to learn PHP right now. Say I have a simple .php file like this:
<?php
?>
<!DOCTYPE html>
<html>
<body>
<h1>Title</h1>
</body>
</html>
If I'm on a mac, how do I get my browser to display the webpage represented by the HTML in this file? When I try open the PHP file it shows the actual HTML code, not the header. Apologies for the noobie question, I'm going through a PHP tutorial right now and the instructor did not elaborate on how to actually display the HTML inside the .php file so I'm a bit confused. He's running it through his localhost it seems.
So the deal with php, is that your browser can't run php code, that is done by the server. You'll need to get a local server to run it then. Since you're on a mac this should be alright:
https://www.mamp.info/en/
Once you've got that running, you'll need to put your php file into the 'htdocs' folder of the MAMP stack install. After that you can access it by navigating to localhost/filename.php
You need a local host to run your php script like MAMP for your mac. simply you can use free web hosting service from different online free host web server like Hostinger
You can't run a php file directly on your web browser that your are using.You need to have a local server host in-order to run your php file. Try downloading an using wamp server,Apache etc.
http://www.wampserver.com/
I have a problem with an Aws Amazon-EC2 SuSe instance, installed apache2, php5, mysql and everything needed to run a web application, we're able to see simple .html or .php pages, but when we try to view more "elaborated" pages with "incredibly complicated code" (excuse the sarcasm) like this
<link href="css/XXXX.css" rel="stylesheet" type="text/css">
or
<div style="background-image:url(img/XXXXX.png);>
or
<?php include('inc/XXXX.php'); ?>
or
<script type="text/javascript" src="js/XXXXX.js"></script>
or any other code (html, php, js, whatever) that points to a subdirectory (css,js,inc,img and so on) doesn't work (all response it's a nice blank page without any error messages like 404 or 403), if i move any necessary file to the root directory seems to work fine, and of course I'm not going to maintain a site with more than 3000 files at root.
Not sure if I'm missing any configuration at SuSe, Apache or PHP .conf files but already googled this question but i can't find anything (maybe I'm a little stressed with this and do not see the answer) to solve this to be able to maintain a "normal" directory structure, somebody can help me? thnxs a lot in advance.
Probably you have a .htaccess file in the root of the vhost and that is causing this problem!
I have a quick question that I can't figure out. I've tried searching Google and following examples, but I can't find anything.
I have an HTML form that I'm trying to process with a PHP file, but when I submit the form, it merely prints the source of the PHP file, it doesn't execute it. If I run the PHP file by itself (not indirectly through the HTML button), it works fine.
HTML form header:
<form id="registrationform" name="registrationform" method="post" action="processregistration.php">
Submit button:
<button type="submit" value="Submit" >Create</button>
The PHP form is just <?php print "Hello"; /?
Again, it runs fine if I just run the PHP file, but prints the PHP file (doesn't run) when it gets called through the HTML form.
Any help is appreciated.
edit-Running locally through Coda
edit-Here is the output that I'm getting:
Output when the PHP is called through an HTML action:
</php
print "Hello";
?>
Output when I run the PHP directly through Coda:
Hello
I had the same problem and just fixed it on my coda version 1.7.4
I installed MAMP on my mac and set up the apache path under MAMP preferences to the folder where my sites are located;
/Users/yourUserName/Sites
this points MAMP's 'http://localhost:8888' address to your sites folder, if you paste that on your browser you'll now see your sites folder's content in the browser.
then, all you do is point the local site's connection settings to the site you are testing;
I was going to post an image, but I'm new to the site and wasn't allowed.
Under my site's preferences i set up the addresses as follows;
Root URL : 'http://localhost:8888/yourSiteRootFolder/'
Local URL : 'http://localhost:8888/yourSiteRootFolder/'
Remote Root : /yourSiteRootFolder/
Local Root : /Users/amartinez/Sites/yourSiteRootFolder/
I hope this is related to the problem you're having and helps you fix it.
Line #19 from Coda 1.6 Release notes:
Coda no longer tries to locally
preview a remote PHP file while
editing/previewing
Listed under "Improvement" - doubt they brought it back for the 1.7 release.
I'm running Apache2/PHP5 10.5.8 OS X (no problem reproducing your issue with Coda)
Even when running my form.html and post.php files from /Library/WebServer/Documents folder.
My sample files work fine in the Apache env....I just needed to run them through Coda to "break" them. :-)
Are you sure the html file and the php script are on a server with php support enabled?
I've never used Coda, but you need to be running it through a server (e.g. Apache + PHP). You cannot just open the file itself within Windows.
Try looking at xampp as a quick server for testing.
If it works properly, you should be viewing the PHP file on something like http://localhost/test.php instead of file:///something/test.php.
This may be because you don't have PHP installed on your server. I would check to make sure that your hosting package included PHP, pre installed.
Here are some resources to get you started with that, if not installed:
http://www.thesitewizard.com/php/install-php-5-apache-windows.shtml
http://www.php.net/manual/en/install.php
http://www.w3schools.com/PHP/php_install.asp
Edit: actually, I think I may have found it.
If you look at the starting PHP tag, you have a slash instead of a ?. If that's in your script, just change that to <?php. But it may not be, it could be that's just question format-ing.