How to include php files using MAMP - mamp

I am trying to include a php file using a MAMP localised server:
$path = "../function/function.php";
include_once($path);
This path just doesn't seem to work. What paths do I need to use in order to include php files into other php files using MAMP locally?
The path that works when I type in the browser is:
http://localhost:8888/function/function.php

If this is in root, then you would include relative to root:
$path = "function/function.php";
include_once($path);

Related

zend framework install issue with include_path

I am trying to install Zend Framework for the first time, I am running WAMP. I downloaded the file and unzipped it and moved it into C:\wamp\bin\php\
I added the path to the library into the environmental variables. Variable Name: path, Variable Value: C:\wamp\bin\php\zend_framework\library
I verified the php.ini file in use through the php_info(). I opened it and set the path to the zend library.
include_path = ".;C:\wamp\bin\php\zend_framework\library;C:\wamp\bin\php\PEAR-1.9.4;"
When I open a cmd line and type zf, I get this:
************** ZF ERROR *****************
In order to run the zf command, you need to ensure that Zend Framework
is inside your include_path. There are a variety of ways that you can
ensure that this zf command line tool knows where the Zend Framework
library is on your system, but not all of them can be described here.
The easiest way to get the zf command running is to give it the include
path via an environment variable ZEND_TOOL_INCLUDE_PATH or
ZEND_TOOL_INCLUDE_PATH_PREPEND with the proper include path to use,
then run the command "zf --setup". This command is designed to create
a storage location for your user, as well as create the zf.ini file
that the zf command will consult in order to run properly on your
system.
Example you would run:
$ ZEND_TOOL_INCLUDE_PATH=/path/to/library zf --setup
Your are encourged to read more in the link that follows.
Zend_Tool & CLI Setup Information
(available via the command line "zf --info")
* Home directory found in environment variable HOMEPATH with value \Users\TOS
H
* Storage directory assumed in home directory at location \Users\TOSH/.zf/
* Storage directory does not exist at \Users\TOSH/.zf/
* Config file assumed in home directory at location \Users\TOSH/.zf.ini
* Config file does not exist at \Users\TOSH/.zf.ini
To change the setup of this tool, run: "zf --setup"
php -i works from the cmd line.
OS: Windows 7 64bit
PHP v. 5.3.9
Apache 2.2.21
Any ideas?
php.ini for CLI is different from the one you open using wamp which is for webserver (apache)
C:\wamp\bin\apache\Apache2.2.21\bin\php.ini
you should add include_path in following ini aswell
C:\wamp\bin\php\php5.3.10\php.ini
Note
depending upon your versions of php , apache path could be little different.

Add Zend folder to bash_profile

I want to not have to copy the Zend folder into all of my sites, so how can I add it to the bash_profile? And where would I put the Zend folder on my system?
I am running OS X Lion
Thanks
To do what you want to do, you don't actually do anything with the bash files, instead you need to add to PHP's include_path, so scripts will find the Zend files automatically when it needs them.
As an example, I put ZF files in a directory /usr/share/Zend/Framework and then add the appropriate directory to PHP's include_path.
So I have a directory structure like this:
- /usr/share/Zend/Framework/
| - bin/
| -- zf.sh
| -- zf.php
| - library/
| -- Zend/
| All the Zend Framework files are here...
Then in php.ini set the include path so it contains the library folder.
include_path = ".:/usr/share/Zend/Framework/library"
Depending on how many of your sites use Zend, you want the Zend files to be as high up in the include path as possible so they are found quickly.
By doing this, all of your sites will simply be able to include and use files from Zend Framework without having to do anything to the include path before hand. By simply saying require_once Zend/Mail.php PHP will know to look in /usr/share/Zend/Framework/library for Zend/Mail.php if it isn't first found in the current directory.
If you want each user to be able to use zf.sh from their shells without having to specify the full path, then you can add something like the following to each user's .bashrc file at the end:
PATH="${PATH}":/usr/share/Zend/Framework/bin
export PATH
In all cases, replace /usr/share/Zend/Framework with the actual path that you place the Zend Framework library and bin folder.
Also note, the bin folder is optional, you can place just the library folder in the path and add library to your include_path.

Where is the web server root directory in WAMP?

Also is the web server root directory the place where you put your site files and later acces them with localhost/file_name in the browser?
If you installed WAMP to c:\wamp then I believe your webserver root directory would be c:\wamp\www, however this might vary depending on version.
Yes, this is where you would put your site files to access them through a browser.
In WAMP the files are served by the Apache component (the A in WAMP).
In Apache, by default the files served are located in the subdirectory htdocs of the installation directory. But this can be changed, and is actually changed when WAMP installs Apache.
The location from where the files are served is named the DocumentRoot, and is defined using a variable in Apache configuration file. The default value is the subdirectory htdocs relative to what is named the ServerRoot directory.
By default the ServerRoot is the installation directory of Apache. However this can also be redefined into the configuration file, or using the -d option of the command httpd which is used to launch Apache. The value in the configuration file overrides the -d option.
The configuration file is by default conf/httpd.conf relative to ServerRoot. But this can be changed using the -f option of command httpd.
When WAMP installs itself, it modify the default configuration file with DocumentRoot c:/wamp/www/. The files to be served need to be located here and not in the htdocs default directory.
You may change this location set by WAMP, either by modifying DocumentRoot in the default configuration file, or by using one of the two command line options -f or -d which point explicitly or implicity to a new configuration file which may hold a different value for DocumentRoot (in that case the new file needs to contain this definition, but also the rest of the configuration found in the default configuration file).
Everything suggested by user "mins" is correct, and excellent information.
WAMP 2.5 provides a default Server Configuration display when you enter localhost into your browser. This maps to c:\wamp\www, as described in previous posts. Creating subdirectories under www will cause Projects to appear on this display. A click and you're in your project.
I have various projects under different directory structures, sometimes on shared drives which makes this centralized location of files inconvenient. Luckily, there is a second feature of WAMP 2.5, an Alias, which makes specifying the location of one (or more) disparate web directories quite easy. No editing of configuration files. Using the WAMP menu, choose Apache > Alias directories > Add an Alias.
WAMP has evolved nicely to provide support for a variety of developer preferences.
If you use Bitnami installer for wampstack, go to:
c:/Bitnami/wampstack-5.6.24-0/apache/conf (of course your version number may be different)
Open the file:
httpd.conf in a text editor like Visual Studio code or Notepad ++
Do a search for "DocumentRoot". See image.
You will be able to change the directory in this file.
To check what is your root directory go to httpd.conf file of apache and search for "DocumentRoot".The location following it is your root directory
this is the path to the web root directory c:\wamp\www
you can create different projects by adding different folders to this directory and call them like:
localhost/project1 from browser
this will run the index.html or index.php, lying inside project1
Here's how I get there using Version 3.0.6 on Windows

Zf Tool cannot find Zend Framework

Just started working with the Zend Framework Zf Tool and I've already come across a problem I've spent hours trying to figure out.
For some reason when I run the Zf show version command I get a ZF ERROR indicating it cant find the Zend Framework a to add it to my php.ini include_directory.
Here is my setup. I'm currently have WAMP installed on my local machine.
c:\wamp
I copied the zf.bat and zf.php files into the servers php directory. The path to the php directory has been added to the path environment variable. I'm pretty sure it works because I run the zf show version command in the console and get a ZF ERROR.
I keep my copy of the Zend Framework inside
c:\wamp\includes
So I added this to the php.ini include_path. include_path = ".;c:\wamp\includes"
I checked that this setting was set correctly by checking phpinfo() function. Which shows
include_path .;c:\wamp\includes .;c:\wamp\includes
So I think I have everything setup correctly. I can't work out what I'm missing.
I also tried setting the ZEND_TOOL_INCLUDE_PATH with no success.
Any help would be appreciated. PS I did check other posts here but none of the suggested
I have worked it out! Finally. The way I have my local wamp setup there is 2 php.ini files I have to edit.
The one that made the different is the php.ini inside the Apache2 directory.
Thanks everyone for their help. I appreciate it.
Well im not sure how you downloaded installed the framework but my guess is that you dont have enough of you include path based on the way Zend release packages are constructed. The Zend folder contained in the Zend Framework installation needs its parent folder to be on the include path so typically you would add something like:
c:\wamp\includes\ZF_BASE_DIR\library
This is because the zf package structure looks like:
ZendFramework-VERSION/
README.txt
INSTALL.txt
LICENSE.txt
bin/
library/
If you extracted ZF from the archive you will get a Zend-some_version folder, but the actual ZF is in
"include_path\Zend-some_version\library\Zend", so your include path should point include_path\Zend-some_version\library\
Just to add to what Tjorriemorrie said and to explain in detail how I got my installation on win 7 to work as simply as possible:
Download your preferred Zend package from "http://framework.zend.com/downloads/latest" to "C:\wamp\www\"
unzip your zip file so that you have the extracted Zend folder (with version name) under "C:\wamp\www\".
Rename your folder by removing the version so that you end up with "C:\wamp\www\ZendFramework"
Run a simple php file with phpinfo() in your browser. Note the entries for: "_SERVER["PATH"]" under PHP Variables
"Path" under Environment
"Loaded Configuration File" at the top
"include_path" under Core and
"extension_dir" under Core as well.
"_SERVER["PATH"]" and "Path" must be identical (no brainer)
There should be only one listing for your apache server and that should be the listing under "Loaded Configuration File" but without the "php.ini". So, if your "Loaded Configuration File" is "C:\wamp\bin\apache\apache2.2.22\bin\php.ini" you must have "C:\wamp\bin\apache\apache2.2.22\bin" in your path and that must be the ONLY reference to an apache server. If you have multiple references to apache servers Windows may pick the wrong one depending on your PATH order and use the wrong php.ini file.
Your "extension_dir" will tell you the version and location of php you are using. It is common to have different php folders lying around such as "C:\php", "C:\wamp\bin\php\php5.4.3", "C:\wamp\bin\php\php5.3....", etc. The extension directory will tell you which one of these php folders ZF will "reference" when it is looking for its library. For example, if your extension directory says "c:/wamp/bin/php/php5.4.3/ext/", you want to focus on "c:/wamp/bin/php/php5.4.3"
Go back to your PATH and a) add the string for this php version and b) remove all the other references to the other php folders
Now that you know your running and primary php and apache folders, shutdown (do not restart), shut down your computer and boot back up (restart does not always let the PATH completely reset.
Go to BOTH php.ini files at a) "C:\wamp\bin\apache\apache2.x.y\bin" and "C:\wamp\bin\php\php5.4.3" and find the include_path variable for Windows
Replace the default line, which looks like:
;include_path = ".;c:\php\includes;"
with
include_path = ".;c:\php\includes;C:\wamp\www\ZendFramework\library"
ON BOTH FILES just as Tjorriemorrie notes.
Restart All Services by clicking the wamp icon and selecting said option
At this point my zf tool was working. But, just to be safe, shut down and bootup
Smile and grab a beer!

Installing Zend framework with WAMP server

I'm trying to install Zend framework on a WAMP server but it is not working properly.
I downloaded the Zend framework and created the folder in C:\wamp\library\Zend, and then in php.inc I have something like this:
; Windows: "\path1;\path2"
;include_path = ".;c:\php\includes:C:\wamp\library"
Now when I try to run the sample blogger.php it is giving me the following error:
Warning: require_once(Zend/Loader.php) [function.require-once]: failed to open stream: No such file or directory in C:\wamp\www\PHPSample\Blogger.php on line 37
Fatal error: require_once() [function.require]: Failed opening required 'Zend/Loader.php' (include_path='.;C:\php5\pear') in C:\wamp\www\PHPSample\Blogger.php on line 37
Can anyone help me please?
On Windows your php.ini should have a section like this:
;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;
; UNIX: "/path1:/path2"
; Windows: "\path1;\path2"
The key is to a) remove the semi-colon at the beginning of the line, and b) add what you need to the path. NOTE: on Windows, paths must be separated by semi-colons, whereas on UNIX they are separated by full colons; Also, Dot means "current directory", so only include it if you want to.
Make sure it looks like this:
;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;
include_path = ".;c:\php\includes;c:\wamp\library"
Zend Installation:- Download Zend Framework
Go to Wamp/bin/php/
Create a folder Namely:- Zend_Framework
Copy All the Files and Folder of Downloaded Zend Framework.
Go to php.ini and find include_path
Here you find:- include_path="c:\php\includes"
and replace the text between "" from your directory C:\wamp\bin\php\zend_framework\library
and Save File.
Now Go to Computer Property and Advanced System Setting and Advanced and Environment Variable and
select path from system variables and click on Edit and add ; and paste your directory path hare
C:\wamp\bin\php\zend_framework\bin
Open Command Prompt and go to the www directory inside wamp and then type zf create project Zendy
Now go to httpd.conf file and type there <virtualHost></virtualHost> Tags.
<virtualHost 127.0.0.1>
DocumentRoot "C:\www\Zendy\public"
ServerName Zendy
<Directory "C:\www\Zendy\public">
AllowOverride AuthConfig FileInfo Indexes Limit Options
order Deny,Allow
Allow from all
</Directory>
</virtualHost>
Save and Quit and go to windows -> System32 -> drivers-> etc-> hosts and Add here your project
127.0.0.1 localhost Zendy
Save and Quit and Restart Apache
Also set rewrite module via removing ; from php.ini file
i had made this cast explaining how to setup Many ZF Application with Wamp full functional
please check it out and let me know if you had any problem so i can help :
Getting Started with the Zend Framework and WAMP Server
that should work if:
you unpacked contents of the library folder in archive that contains Zend framework in
C:\wamp\library folder. othervise you need to do that ( put the contents of the library folder in archive in path you specified in php.ini