开发者

Testing PHP enabled websites locally

I'm currently developing a website that will make use of PHP scripts and I'd like to be able to test them on my local machine before pushing them out to the server, however I'm having problems doing that. Typically, I keep all my development projects in a folder call ~/Projects/projectName, but that doesn't seem to be an option with web scripting. I've read that I need to install Apache (which I've done) and PHP (also done) and then move my project into the web server's root directory located at /var/www (I'm on Linux) which I haven't done since that's a system directory and I won't be able to edit my files in there.

I've looked around and there doesn't seem to be any way of invoking a PHP script from a webpage anywhere but this one directory. I've tried soft-linking my ~/Projects/projectName directory into /var/www, but since it's a subdirectory of the web server's root, that's causing permission开发者_如何学Go errors when I try to access the file at /var/www/projectName/index.html.

Is there any way to house my files in my Projects folder and still be able to run them locally without too much hassle?


You need to create a new Apache Virtual Host configuration to point to your ~/Projects/projectName folder as it's webroot.

Here is a very basic configuration for that type of setup

<VirtualHost *:80>
  ServerAdmin yourname@whatever.com
  ServerName www.mysite.com
  DocumentRoot /home/john/Projects/projectName
</VirtualHost>

But it also sounds like you might not have root or sudo access since you can't write to /var/www as well... Adjusting your Apache config requires similar privileges.


if you are using an advanced linux distribution like opensuse, you'll be able to modify the root_dir with YaST2 easely, otherwise you'll have to modify httpd.conf configuration to define the web root directory (location depends, some times you can find it in /etc/apache2/conf.d)

or simply, login as root (command line : su) and chmod your webroot directory (command line : chmod 777 /var/www)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜