I'm working with an existing PHP web application. It's running fine on the remote Linux server but I can't run it on WAMP server, Windows 7 on my local computer. The problem is the previous developer's used absolute path all over the code. for example one of them is:
require '/disk2/html/src/web_tool/db_connect.php';
my localhost folder is F:\wamp\www and I have the same structure:
F:\wamp\www\myProject\disk2\html\src\web_tool\db_connect.php
But it can't find the db_connect.php. I can't change the path because it's a big project and if I want to, I have to find and change more than 400 line of code. I'm not sure what the problem is and how to make it work. Any suggestion is highly appreciated.
EDIT: I ran a simple test on my WAMP Server. I created this file structure:
F:\wamp\www\test\myfolder\index.php with this code:
require '/myinc.php';
and F:\wamp\www\test\myinc.php with this code:
echo 'It works!';
I get this warning:
Warning: require(/myinc.php): failed to open stream: No such file or directory in F:\wamp\www\test\myfolder\index.php on line 2
and this error:
Fatal error: require(): Failed opening required '/myinc.php' (include_path='.;C:\php\pear') in F:\wamp\www\test\myfolder\index.php on line 2
I don't have such a folder as C:\php\pear on my disk.
The WAMP server is just installed, haven't touched anything in the php.ini or other config files. the version is:
WAMP SERVER 64bit version 2.5 including:
Apache : 2.4.9 MySQL : 5.6.17 PHP : 5.5.12 PHPMyAdmin : 4.1.14 SqlBuddy : 1.3.3 XDebug : 2.2.5
I think your best solution would be to move the site source and create a Virtual Host, then the absolute paths would work and you can address the site properly as well.
First move the disk2 folder and all its subfolders to the root of your F: drive.
F:\disk2.....
Then create a Virtual Host to describe its new location.
Edit \wamp\bin\apache\apache2.x.y\conf\extra\httpd-vhosts.conf
If this is your first Virtual Host definition, remove the existing contents of this file.
I have assumed that F:\disk2\html is the correct folder to become your DocumentRoot.
Add this to the file
<IfDefine !APACHE24>
NameVirtualHost *:80
</IfDefine>
## so the the wamp menu page loads
<VirtualHost *:80>
DocumentRoot "F:/wamp/www"
ServerName localhost
ServerAlias localhost
<Directory "F:/wamp/www">
AllowOverride All
<IfDefine APACHE24>
Require local
</IfDefine>
<IfDefine !APACHE24>
Order Deny,Allow
Deny from all
Allow from 127.0.0.1 localhost ::1
</IfDefine>
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "F:/disk2/html"
ServerName example.dev
ServerAlias www.example.dev
<Directory "F:/disk2/html">
AllowOverride All
<IfDefine APACHE24>
Require local
</IfDefine>
<IfDefine !APACHE24>
Order Deny,Allow
Deny from all
Allow from 127.0.0.1 localhost ::1
</IfDefine>
</Directory>
</VirtualHost>
Save this file.
Edit httpd.conf and remove the comment from this line
#Include conf/extra/httpd-vhosts.conf
remove the # in col 1 and save that file.
Now edit the hosts file C:\windows\system32\drivers\etc\hosts and add these lines.
127.0.0.1 example.dev
::1 example.dev
This is a windows protected file so you will have to open your editor using the "Run as Administrator" or you wont be allowed to save your changes.
Now start a command windows also using the "Run as Administrator" and execute these 2 statements to refresh the DNS cache with your changes to the hosts file.
net stop dnscache
net start dnscache
Now restart Apache so that it picks up your configuration changes, and you should be able to use this address in the browsers address bar.
example.dev
The DocumentRoot should be as it was on the live server and the absolute paths used in the PHP code should also now work as they do on the live server.
Change example.dev to whatever makes sense as related to your live sites domain name.
If you have the same folder strcture a simple set_include_path() should solve the problem in the root directory.
I gues in F:\wamp\www\myProject there should be an index file, just add there:
set_include_path('');
But if you can't find the file you're looking for, I guess that it is missing / you did not copy over everything you needed (something like that). Than the problem is not really the relative path.
This isn't much of a technical answer and it's five years later, but FWIW I had the same issue after upgrading my WAMP version after a couple of years that some of by requires were no longer working on the localhost while they were working just fine when published on the active webapp.
For me, I found a setting called 'allow_url_include' and activating that setting and restarting services everything appears to be in working order now. Hope this helps somebody.
Related
I am pretty new in PHP and moreover in Laravel and I am pretty desperate trying to deploy a Laravel 5.4 application that works fine on my local environment on my Linux remote server.
So I think that it is something related to virtual host configuration or something like this (maybe also something related to the .htaccess file)
In my local environment (I am using XAMPP on Windows) I have setted this virtual host into the C:\xampp\apache\conf\extra\httpd-vhosts.conf file:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/HotelRegistration/public"
ServerName laravel.dev
</VirtualHost>
So opening the laravel.dev URL I obtain the standard Laravel homepage (I have yet not replaced it with a landing page).
Then if I open this URL: http://laravel.dev/registration
I obtain the user registration page developed by me, this because I have this route into my web.php file into my project:
Route::resource('/registration', 'RegistrationController');
Then into my RegistrationController.php there is this method showing the resources/views/registration/index.blade.php view
public function index(){
return view('/registration/index');
}
All works fine.
Now I have uploaded this Laravel website into my remote Linux server, into this folder: /var/www/html/HotelRegistration
But now my problem is that in this remote environment I have not virtual host (correct me if I am doing wrong assertion: from what I have understand the virtual host is used on the local environment to simulate a domain that Laravel need to point to the public folder, is it this reasoning correct?)
Anyway, this is the URL of the public folder of my deployed web site on my remote server:
http://89.36.211.48/HotelRegistration/public/
As you can see opening it the Laravel landing page is correctly shown, the problem is that I can access to the previous registration page, the only way that I have found is to open this URL:
http://89.36.211.48/HotelRegistration/public/index.php/registration
but it is pretty horrible and above all when the registration form is submitted it is generated a POST request toward this URL http://89.36.211.48/registration that end into a 404 Not Found error.
So I think that it depend by the fact that in this remote server I can't use a virtual host that simulate a domain (as I have on my local environment), but I am not sure about it.
What can I do to solve the situation? Do you think that using a effective domain (something like: www.myregistration.com) that points to this directory of my remote server http://89.36.211.48/HotelRegistration/public/ I can solve this problem?
You need to configure your domain in your server and need to reconfigure the apache. I'm considering you are having apache2 server so here you can do:
Step 1 Go to the apache2 folder cd /etc/apache2
Step 2 You can see sites-available folder go inside it cd sites-available
Step 3 Make a new file name it laravel.dev.conf
Step 4 Write down the following sudo nano laravel.dev.conf
Step 5 Write down the following option:
<VirtualHost *:80>
ServerAdmin webmaster#laravel.dev
ServerName laravel.dev
ServerAlias www.laravel.dev
DocumentRoot /var/www/html/laravel.dev/public/
ErrorLog /var/www/html/laravel.dev/logs/error.log
CustomLog /var/www/html/laravel.dev/logs/access.log combined
<Directory /var/www/html/laravel.dev/public/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
Step 6 Now go to this folder/create a new one cd /var/www/html/laravel.dev
Step 7 Copy/Install your laravel application here.
Step 8 Now you can enable your site by typing sudo a2ensite laravel.dev.conf
Step 9 Now restart the apache2 sudo service apache2 restart
Now you can have proper access to your domain. Hope this helps.
Since you are using XAMPP
Add the following into your VirtualHost Directive:
<Directory "LINUX PATH TO /HotelRegistration/public">
AllowOverride All
</Directory>
Your final VirtualHost Directive should look like:
<VirtualHost *:80>
DocumentRoot "LINUX PATH TO /HotelRegistration/public"
ServerName 89.36.211.48
<Directory "LINUX PATH TO /HotelRegistration/public">
AllowOverride All
</Directory>
</VirtualHost>
After the configuration changes, restart Apache then you are good to go.
I am using XAMPP 3.2.1 and creating new virtual host in http-vhosts.conf file in Apache the code below
<VirtualHost *:8080>
DocumentRoot "C:/xampp/htdocs/support/srinet"
ServerName supportcenter.sevplcorp.com
Alias /mrpdf "E:/temp"
<Directory "C:/xampp/htdocs/support/srinet">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Deny,Allow
Allow from all
Require all granted
</Directory>
When I open supportcenter.sevplcorp.com in browser windows it shows like below
You have to edit your host file located at : %WINDIR%\system32\drivers\etc\hosts.
Add a newline 127.0.0.1 supportcenter.sevplcorp.com
Probably you haven't altered your hosts file to map the host domain to server's IP address. Assuming that you're running XAMPP on your own PC, open your editor as Administrator (notepad is sufficient), then open this file:
c:\Windows\System32\Drivers\etc\hosts
...and add this line to the bottom:
127.0.0.1 supportcenter.sevplcorp.com
Save the file and, after that, visiting supportcenter.sevplcorp.com should work. Basically, by altering the hosts file you're telling the browser (and everything else that might want to access supportcenter.sevplcorp.com) that it's actually your PC.
I'm trying to install Bonfire for Codeigniter and I'm having some issues. I first tried downloading the zip, unziping it and placing it in MAMP and navigating to it through localhost. The welcome page came up but when I clicked on the "install" button, it displayed a "URL Not Found" page. Quite annoying since I'm under the gun.
I saw on youtube, that the dev team shows the install by cloning the repo on Github so I tried that next. Now when I load that in my localhost, I get a welcome page without an install button, an error saying my "htaccess" should be renamed ".htaccess" (although when I looked at the file it looked fine to me) but more worryingly is the next error:
"Oops!
Your Web Root should be set to the public folder,but it's not. It's pointing to the Bonfire Root folder.
See below how your site should be set up on Apache:
<VirtualHost *:80>
DocumentRoot "[...]/htdocs/Bonfire_Root/public"
ServerName Bonfire.Root
ServerAlias Bonfire.Root.local
</VirtualHost>"
I'm a really junior programmer and I'm just trying to get this sorted out quickly because of a project I'm on that I need to turn around quickly. I'm sure this is probably something simple so does anyone know what I can do to fix this so it will work and I can begin developing with Bonfire? Thanks in advance!
EDIT:
When I followed the instructions about adding my project name to the URL, I moved on to a blank page, Chrome initiated a download of a textfile called install which contains this:
J
5.5.34B:;Z1&hZˇ˜Äj*/Knh#G"o/9mysql_native_password!ˇÑ#08S01Got packets out of order
I'm not sure what to do with this. Any ideas?
I've tried:
http://localhost/Bonfire_Root/public/
http://localhost/Bonfire_Root/public/index.php
http://192.1xx.xxx.xxx/Bonfire_Root/public/index.php
Each time it just downloads the textfile with the same text in it. :/
here's my work around (I'm on linux btw):
1) make sure mod_rewrite is enable on your apache setup.
2) add <VirtualHost *:80>
DocumentRoot "/path/to/your/htdocs/bonfire/public"
ServerName bonfire.dev
ServerAlias bonfire.dev
<Directory "/path/to/your/htdocs/bonfire/public/">
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
3) edit your /etc/hosts file, add this line 127.0.0.1 Bonfire.Root
4) restart your apache
5) access bonfire on http://bonfire.dev, instead of http://localhost/Bonfire_Root/public
hope it helps
I would suggest no need to use htaccess if you are working on local environment.about your error when you click on install button after that in your url put your project folder name like 'host:port/yourprojectname/public/index.php' . would redirect to you next page to get installation process done.
I had same problem but in windows yes working on mac and windows quite similar. When i clicked on install it goes to http//localhost/public which is not correct url so i have change by adding my project name after localhost http//localhost/project/public/index.php.
Major difference between mac and window while using PHP is s you have to use ip address in place of localhost.
Assuming you are installing bonfire in windows D:\ drive and path of you index.php is "D:/xampp/htdocs/bonfire" please follow below steps:
1. Edit your `D:/xampp/htdocs/bonfire/index.php` file
<VirtualHost 127.0.0.1:80>
DocumentRoot "D:/xampp/htdocs/bonfire"
ServerName 127.0.0.1
ServerAlias bonfire.dev
</VirtualHost>
Open your httpd.conf file (in case of xampp path will be D:\xampp\apache\conf\httpd.conf) and add this in the end of your file.
NameVirtualHost localhost
<VirtualHost localhost>
DocumentRoot D:/xampp/htdocs/bonfire
ServerName localhost
<VirtualHost>
#####
## myproject.dev
## DOMAIN of myproject
#####
NameVirtualHost bonfire.dev
<VirtualHost bonfire.dev>
DocumentRoot D:/xampp/htdocs/bonfire/public
ServerName bonfire.dev
</VirtualHost>
note that bonfire.dev is a naming convention i have given to my website and mentioned it inside my C:\Windows\System32\drivers\etc\hosts file so as convenient to you, choose any name suitable to you
Edit C:\Windows\System32\drivers\etc\hosts file.
Add below lines in hosts file.
127.0.0.1 localhost
::1 localhost
127.0.0.1 bonfire.dev
4. Restart Apache and now open your web page `http://bonfire.dev/`
This solution works 100%, I have been fighting up with same issue and now finally its fixed. Just try it and get back to me in case of any issue.
launches the PHP server into the directory of your project exempel
www / (project) / public / php -S localhost: (port)
In order for me to be able to run a Zend Framework project on my local development machine, I made changes to Apache's \etc\apache2\httpd.conf and the openSUSE system's \etc\hosts files. I set up a test3.local alias for an individual Zend project, and things seem to "work".
Before I started fiddling with things, I could access phpMyAdmin simply by entering http://localhost/phpMyAdmin/ in my browser. And if I take away my changes, that once again works.
Using this answer as a basis, I tried to set up an additional virtual host specifically for phpMyAdmin, hoping to "solve" this problem. But right now if key in the virtual host name, admin.local, that I intend to take me to phpMyAdmin, I get a 403 error like this:
(source: willmatheson.com)
Here is my present httpd.conf:
### Virtual server configuration ############################################
IncludeOptional /etc/apache2/vhosts.d/*.conf
<VirtualHost *:80>
ServerName test3.local
DocumentRoot /home/william/public_html/ZendTest3/public
SetEnv APPLICATION_ENV "development"
<Directory /home/william/public_html/ZendTest3/public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName admin.local
DocumentRoot /var/lib/mysql/phpMyAdmin
# This gives permission to serve the directory
<Directory /var/lib/mysql/phpMyAdmin>
DirectoryIndex index.php
Options None
AllowOverride All
# This allows eveyone to access phpmyadmin, which you may not want
Order Allow,Deny
Allow from all
</Directory>
</VirtualHost>
and hosts:
127.0.0.1 localhost
127.0.0.1 local
127.0.0.1 test3.local
127.0.0.1 admin.local
Ideally I'd like to not have to specify a virtual host for phpMyAdmin at all, because I'm sure to muck it up, and just somehow have the settings to make the Zend project work but to also have phpMyAdmin work like it did before.
I know this question was already answered, but I thought I'd share what I did to overcome a similar problem, in case it helps anyone else.
My problem was:
I started to get localhost/phpmyadmin 404 error after changing the DocumentRoot folder in httpd.conf. The change I made was to change the DocumentRoot
from:
DocumentRoot "C:\Program Files (x86)\Zend\Apache2/htdocs"
to:
DocumentRoot "C:\Program Files (x86)\Zend\Apache2/htdocs/a/deeper/folder"
I fixed it by changing a line in zend.conf
from:
Alias /phpMyAdmin "C:\Program Files (x86)\Zend\phpMyAdmin"
to:
Alias /phpMyAdmin "C:\Program Files (x86)\Zend\ZendServer\data\apps\http\__default__\0\phpMyAdmin\4.0.5.4_41"
Hope this helps somebody else!
Well, there's a good reason I was getting a 403 - I was digging in the wrong place. My installation of phpMyAdmin was actually in /srv/www/htdocs/phpMyAdmin. Changed that, restarted Apache (sudo systemctl restart apache2.service) and things seem to work.
If you're interested in how the heck to find files and folders on openSUSE, the following steps worked for me:
sudo zypper install findutils-locate
su
updatedb (go check your e-mail)
locate phpMyAdmin (like that, not 'phpmyadmin')
I'm new to using XAMPP so this may be simple to some people.
I have a few php projects that I would like to be able to debug locally and view in the browser (not concurrently, but without having to change config files/copy project folders each time I want to work on a different project).
On IIS, you could set up multiple sites to serve from your machine, and I'm looking for something similar in XAMPP. When using IIS, I added multiple records to the Windows hosts file so I could access the locally hosted sites by typing friendly web-style addresses (like http://myproject1.dev)
Thanks.
Greg, you're almost there--you need (like Moses said) to setup virtual hosts.
So if your Windows hosts file has
127.0.0.1 localhost
127.0.0.1 mysite-dev.com
127.0.0.1 anothersite-dev.com
Your virtual hosts file (httpd-vhosts.conf) might look like:
<VirtualHost *:80>
DocumentRoot C:/xampp/htdocs/
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
ServerName mysite-dev.com
DocumentRoot "C:/sites/mysite-dev"
<Directory "C:/sites/mysite-dev">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName anothersite-dev.com
DocumentRoot "C:/sites/anothersite-dev"
<Directory "C:/sites/anothersite-dev">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Don't forget to restart the web server after you make any changes.
I would like to make an additional in terms of up to date information.
XAMMP uses port 80 by default and we are able to publish 1 website. I also use IIS for .Net projects. In this respect, I set the port to XAMMP except the 80 port. So I avoid a conflict.
When we want to publish more than one website, we should do the following operations to httpd.conf (this is the current name).
1. Setting the ports
Find the #Listen expression in the httpd.conf file.
Change Listen 80 to Listen 8000 (or whatever else you want)
Listen 8000
If you need 3 different websites, type the others, including 1 definition on each line, as follows.
Listen 8001
Listen 8002
Listen 8003
2. Define the file paths of sites accessed through ports
Again, find in the httpd.conf file.
Identify the folders of each website as follows.
As you would see, I've created 3 directories called 8000, 8001, 8002 and 8003 under the htdocs directory within the XAMMP directory.
<VirtualHost *:8000>
DocumentRoot "C:\XAMPP\htdocs\8000"
ServerName localhost:8000
<\ VirtualHost>
<VirtualHost *:8001>
DocumentRoot "C:\XAMPP\htdocs\8001"
ServerName localhost:8001
<\ VirtualHost>
<VirtualHost *:8002>
DocumentRoot "C:\XAMPP\htdocs\8002"
ServerName localhost:8002
<\ VirtualHost>
<VirtualHost *:8003>
DocumentRoot "C:\XAMPP\htdocs\8003"
ServerName localhost:8003
<\ VirtualHost>
Restart your Apahche server on XAMMP.
You can now view your 3rd site, such as http://localhost:8003 or http://192.168.1.1:8003/.
Hope to be useful.
This question was asked almost ten years ago, and the answers above are a bit dated. Note that XAMPP has a "How-To" for virtual hosts avilable off the dashboard, when you install it.
From the "Welcome to XAMPP for Windows" page (localhost/dashboard, the default when you first load localhost) click on the "HOW-TO" Guides in the top menu bar. From there, look for the link "Configure Virtual Hosts" which will lead you to the localhost page "http://localhost/dashboard/docs/configure-vhosts.html"
In a nutshell, the process involves editing the "httpd-vhosts.conf" file (typically in C:\XAMPP\apache\conf\extra) and replacing the contents of that file with something like this:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/"
ServerName localhost
</VirtualHost>
# vhosts - note sample entry from XAMPP how-to throws an error, so try this:
<VirtualHost *:80>
DocumentRoot "C:/Users/jdoe/Documents/dev.mysite.com/htdocs"
ServerName mysite.local
<Directory "C:/Users/jdoe/Documents/dev.mysite.com/htdocs">
Require all granted
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Additional vhosts (including SSL hosts) can be had by cloning the entry, and modifying DocumentRoot and ServerName directives and port numbers (e.g. 443 for TLS (SSL)). You can find tutorials on the web for creating and signing your own certificate, if you want to go that route.
The final step is to get your Windows machine to point your browser to the Apache host for your virtual domain (e.g. above, http://mysite.local). Using a text editor (Notebook will do) as administrator append the following entry onto your hosts file, which lives here:
C:\Windows\System32\drivers\etc\hosts
Append this entry to the hosts file:
127.0.0.1 mysite.local
IMPORTANT - you must restart your Windows machine or the new host will not respond. Some documentations will tell you just to restart the browser and Apache server, but I've found that's not sufficient.
IME, the hosts system and Apache directives can be particular, so be patient. You may need to rebuild configs, restart Apache, and restart your machine more than once.