1

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...

user2314737
  • 27,088
  • 20
  • 102
  • 114
Beni Bogosel
  • 572
  • 1
  • 6
  • 22
  • There are plenty of tutorials online for configuring Apache+PHP for a local LAMP test server. It's easier to find one of those than have someone walk you through all the hops here. Here you go, this one is thorough enough and for Ubuntu: https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-14-04 – Markus AO Jun 27 '15 at 17:12
  • A little googling could solve your problem, checkout https://blog.udemy.com/xampp-tutorial/ – Ologho Cyril Paul Jun 27 '15 at 17:17
  • If this is only about publishing some pages, then why bother implementing something at all? Do yourself a favor and use some web toolkit where you can concentrate on the content instead of programming. Something like jimdo.com or similar. – arkascha Jun 27 '15 at 17:20
  • @arkascha: I tried looking for templates, or ready made sites, but they all look too flashy (jimdo included). I need something simple and clear. The visitor does not need to see other things than the information I want to provide. At the beginning I used WISIWYG approaches, but after spending large amounts of time to try and format things, I realized that straight coding is much clearer and error free... – Beni Bogosel Jun 30 '15 at 09:31
  • @OloghoCyrilPaul: a lot of googling did not help. All setups were complicated and many things I tried did not work. I did not find a tutorial which shows how to do things from start to end... Thanks for your suggestion of XAMPP. This did the trick – Beni Bogosel Jun 30 '15 at 09:33

2 Answers2

3

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?)

Community
  • 1
  • 1
user2314737
  • 27,088
  • 20
  • 102
  • 114
1

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)

Beni Bogosel
  • 572
  • 1
  • 6
  • 22