Introduction
If you are learning Zend Framework, and you are a newbie like me (or just a resistant developer
), that would like, either to “make it right”, or to prepare a system to follow the tutorials that appear on several websites, here are some steps that may help under the huge task of preparing a system and start to deploy and learn about Zend Project.
I’ve divided this into two main points. The first is related to your system configuration, the second, with new project setup. This may serve as guide so, you may follow the steps of the first part, and only repeat the steps on the second part wherever a new project comes to us.
I’m hoping this could be a valid walk-through for the next two years or so, but no longer than that, due to technological changes. It’s the price to pay for going into so much detail here.
Every system is different and, you may found some issues along the way. If that’s the case, just let me know.
System Configuration
On your command line, check for new versions of the repository:
sudo apt-get update
1) LAMP Server Installation:
sudo apt-get install lamp-server
Test: Once finished, the address:
http://localhost/ should work.
2) Apache Setup
2.1) Create a folder under your machine system account and called something meaningful (ie. public_html):
/home/username/public_html
2.2) Enable mod-rewrite:
sudo a2enmod rewrite
2.3) Restart Apache
sudo /etc/init.d/apache2 restart
[SIZE=“5”]
- Phpmyadmin installation:[/SIZE]
sudo apt-get install phpmyadmin
Test: The address: http://localhost/phpmyadmin should work.
4) Install and Setup MysqlWorkBench
4.1) Grab and install the Debian package from: [COLOR=“DarkGreen”]http://www.mysql.com/downloads/workbench/#downloads[/COLOR]
4.2) On program’s Home section create a new connection to your local mysql server and follow the instructions under:
New Connection
5) Download Zend-Framework
5.1) Download and extract the minimal version of the zend framework package from:
http://framework.zend.com/download/latest
6) Place Zend Library into php include path
6.1) Find where is the include path, on your command line do:
php -i | grep include_path
6.2) From the extracted Zend Framework file, copy the library folder, into your include_path:
sudo cp -R /home/user/Transfers/ZendFramework-1.11.4-minimal/library/* /usr/share/php/
7) Place Zend Tool under your local system
7.1) From your command line, find were your php binaries are by doing:
which php - if we retrieve /usr/bin/php it means that our binary is under /usr/bin/
7.2) From your earlier downloaded zend framework extracted folder:
navigate to bin folder, once there, type the following command:
sudo cp zf.sh zf.php /usr/bin – assuming /usr/bin is your php binaries location.
7.3) Shortening the command to zf by going to /home/user/ and type:
sudo gedit .bashrc at the very end add: alias zf=‘zf.sh’
Test: Anywhere from your command line type: zf show version – the framework version should appear. If not, try to carefully repeat steps 6 and 7.
8) Install and Configure Xdebug
8.1) If we don’t have php5 library installed, we must:
apt-get install php5-xdebug
8.2) Once installed, we have to find xdebug.so. In order to do so:
find / -name ‘xdebug.so’ 2> /dev/null
8.3) Let’s write out the path given, something like:
/usr/lib/php5/20090626+lfs/xdebug.so
8.4) Now let’s find php.ini:
Since we already have Zend Tool, let’s use it. From our command line do:
zf show phpinfo
You can also create your phpinfo(); page.
Another way is to type the following on our command line: php –i > phpinfo.php .
On each of those three ways, we must look for something like: /etc/php5/apache2/php.ini
8.5) We then do:
sudo gedit /etc/php5/apache2/php.ini
And we use the retrieved path to add, at the very end of this file, the following:
[xdebug] zend_extension=/usr/lib/php5/20090626+lfs/xdebug.so xdebug.remote_enable=on
Note: All other information like host, port, handler, will be already configured by default.
Just look into phpinfo() to confirm that.
9) Install and configure Git
9.1) Type:
apt-get install git-core – we can install more, but core will be enough since our IDE will take care of the rest.
9.2) Then configure:
git config --global user.name “Your Name”
git config --global user.email “youremail@mail.com”
git config --global core.editor gedit (or any other);
9.3) Create your system public key by doing:
ssh-keygen -t rsa -C “youremail@mail.com”
9.4) Place the following path:
/home/user/.ssh/yourkeyname.pub
9.5) If you don’t have one, create your account into:
[COLOR=“DarkGreen”]https://github.com/signup/free[/COLOR]
9.6) Go to:
“Account Settings” > “SSH Public Keys” > “Add another public key”
9.7) Go to /home/user/.ssh/yourkeyname.pub and copy the contents from your pub file into git hub page.
9.8) Then, on your command line type:
ssh git@github.com
9.9) Ignore the message and type: “yes”:
The authenticity of host ‘github.com (207.97.227.239)’ can’t be established. RSA key fingerprint is o-seu-finger-print . Are you sure you want to continue connecting (yes/no)?
The following message should appear:
PTY allocation request failed on channel 0 Hi gituser! You’ve successfully authenticated, but GitHub does not provide shell access. Connection to github.com closed.
9.10) Setup GitHub token – From Github website account, go to:
Account Settings > Account Admin
9.11) On your command line, type:
git config --global github.user username
git config --global github.token yourtokenfromgithub
- Install / Upgrade Netbeans IDE
10.1) Download the desired version:
http://dlc.sun.com.edgesuite.net/netbeans/7.0/beta2/start.html?platform=linux&lang=en&option=php
10.2) Let’s convert that file in order to be eXecutable:
chmod +x netbeans-7.0beta2-ml-php-linux.sh
10.3) Double click on it and choose: “run”;
Note: If we happen to have older versions of Netbeans, we go into his installation directory normally:
/home/user/netbeansX-X and we uninstalled by typing:
sudo ./uninstall.sh
11) Installing Capistrano
11.1) Install rvm dependencies (we will use that to install capistrano dependency - ruby):
sudo apt-get install build-essential curl
11.2) Install rvm:
bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
11.3) Setup terminal to run rvm each time we start a terminal session:
echo ‘[[ -s “$HOME/.rvm/scripts/rvm” ]] && source “$HOME/.rvm/scripts/rvm”’ >> ~/.bashrc
May be interesting:
Pogodan
11.4) Close all terminal windows, and open again.
11.5) Find what dependencies your system need by finding the following text after typing:
rvm notes “For Ruby (MRI & ree) you should install the following OS dependencies:”
11.6) Install all listed dependencies by doing:
sudo aptitude install … dependencies
Ex:
sudo aptitude install build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev
11.7) Install latest ruby version you may found:
rvm install 1.9.2
11.8) We mark that version to be used by default:
rvm --default use 1.9.2
11.9) With ruby installed and properly configured we can now:
gem install capistrano
11.10) Install capistrano extension to allow us to have a multi-stage environment. (It will be present on core code soon enough).
sudo gem install capistrano-ext
11.11) Finally, install railsless-deploy:
gem install railsless-deploy
You must follow this steps, ipsis verbis, with this same order. If you still miss it, you may consult the sources I’ve studied:
Blog of Ryan Bigg - Ubuntu, Ruby, RVM, Rails, and You
Deploying With Capistrano Without Rails
12) Install and Configure PhpDocumentor
12.1) In order to install or upgrade phpDocumentor you must install pear if we don’t have it:
sudo apt-get install php-pear
And then do:
sudo pear install --alldeps PhpDocumentor
Nothing more is needed because we will not generate information by web interface our cli, since we will use Netbeans IDE for that.
For upgrading to future versions, simple run: pear upgrade PhpDocumentor
12.2) Now go to Netbeans IDE and go to:
Tools > Options > PhpDoc
12.3) Write the following line:
/usr/bin/phpdoc -i library/,Zend -o HTML:frames:earthli
Please note the -i that allows us to ignore certain files our folders.
Note as well, the comma. Without the comma, we will not have our Zend folder ignored.
The -o means that we want to output the documentation on a certain format (HTML:frames) with a certain template (earthli).
System Configuration - Done. ![]()
Note: In order to update your system to work with a future framework version, you only need to:
1) Download and extract the new version :).
2) Copy library folder from the extracted content into the appropriate system folder:
sudo cp -r /home/user/Transfers/ZendFramework-new.version-minimal/library/* /usr/share/php/
3) Copy o Zend Tool into the appropriate system folder:
sudo cp /home/user/Transfers/ZendFramework-new.version-minimal/bin/zf.sh zf.php /usr/bin
New Zend Project Setup
Each time you have a new Zend project, those are the steps to follow. ![]()
1) Creating Virtual Hosts:
1.1) Let’s find our default apache v. hosts configuration files, that should be in:
/etc/apache2/sites-available
1.2) Let’s duplicate the default contents to a new host file:
sudo cp default yoursite.dev
1.3) Let’s edit that file:
sudo gedit yoursite.dev
1.4) And place inside, the following information:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName mysite.dev
DocumentRoot /home/user/public_html/yoursite.dev/public
<Directory /home/user/public_html/yoursite.dev/public>
DirectoryIndex index.php
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
1.5) Let’s enable the virtual host:
sudo a2ensite yoursite.dev
1.6) Restart Apache:
sudo /etc/init.d/apache2 restart – let’s ignore the warning telling us that the directory doesn’t exist.
1.7) Let’s edit our the hosts file:
sudo gedit /etc/hosts
1.8) And add there, our ServerName defined on step 1.4:
127.0.0.1 yoursite.dev
1.9) Restart Apache again:
sudo /etc/init.d/apache2 restart
2) Create a new Netbeans Project
2.1) We choose:
PHP - PHP Application
2.2) Project name:
yoursite.dev
2.3) Source Folder:
/home/meuutilizador/public_html/yoursite.dev
2.4) Default Encoding:
UTF-8
2.5) Note:
meta data is NOT on a different directory.
2.6) Run-as:
Local Web Site
2.7) Project URL:
http://yoursite.dev
2.8) Note:
“copy files from Sources Folder to another location” is NOT selected.
2.9) We then choose:
Zend PHP Web Framework
2.10) Click on:
“options”
2.11) We verify if the path of our zend tool, is according to our defined path during the stack configuration process:
/usr/bin/zf.sh
2.12) If this is our first project on this machine, we must click on:
Register Provider
2.13) We click:
Ok and then Finish
2.14) On our local machine, the Zend library is on our php include_path. However, on your shared host, that may not be the case. We must, then, copy the library version that we are using, into our project folder. (please note the –r to copy recursively all directories and files inside):
sudo cp -r ~/Transfers/ZendFramework-new.version-minimal/library/Zend/ ~/public_html/yoursite.dev/library/
2.15) Within Netbeans IDE, we then go to our project properties on:
PHPDoc we place: /home/user/public_html/yoursite.dev/docs
2.17) Initializing the Git repository by Right-click under our project name and do:
“Versioning > Initialize Git Repository”
3) Configuring the .htaccess file
3.1) Let’s go to:
cd /home/user/public_html/yoursite.dev/public
3.2) We edit the .htaccess there sudo gedit .htaccess remove all the information inside, and add the following instead:
#already active, still:
Options +FollowSymlinks
#With this definition, our application.ini will be set as development
#When going to production, we will change the .htaccess file automaticly by using Capistrano.
SetEnv APPLICATION_ENV development
#to allow redirection
RewriteEngine On
#avoid hotlinking
RewriteCond %{HTTP_REFERER} !^$ [OR]
RewriteCond %{HTTP_REFERER} !^https?://(www\\.)?yoursite\\.dev [NC,OR]
RewriteCond %{HTTP_REFERER} !^https?://(www\\.)?dev\\.yoursite\\.com [NC]
RewriteRule \\.(jpg|jpeg|png|gif)$ - [NC,F,L]
#if the request is a file or a directory or any other condition, do not redirect (first rule), otherwise, rewrite to index (second rule).
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
3.3) Let’s now create a production folder inside our project:
mkdir ~/public_html/yoursite.dev/production
3.4) Let’s copy the .htaccess file inside that folder:
cp ~/public_html/yoursite.dev/public/.htaccess ~/public_html/yoursite.dev/production/
3.5) We edit that file and we:
3.5.1) The hotlink path must reflect our production website address.
3.5.2) Let’s change our application environment variable to production:
SetEnv APPLICATION_ENV production
3.6) We must then go to:
http://yoursite.dev – we should see Zend Framework Project welcome page;
Nothing appears?
Are we calling http or https ? We should call http.
You can also try to explicitly stop and start your Apache service.
Note: http://yoursite.dev/phpmyadmin - should also work.
4) Database with Workbench and Netbeans.
4.1) Open MySQL Workbench and in Home create a new EER Model
Choose either:
Create EER Model
or
Create EER Model From SQL Script;
Note: Change MySQL Schema name to something that makes sense.
4.2) Change the default Collation to UTF-8_general_ci
Why? It’s faster then unicode and, on our case, we don’t need german specific chars, or french ones. If however, that’s not your case, choose Unicode instead.
Source: MySQL :: MySQL 5.0 Reference Manual :: 9.1.13.1 Unicode Character Sets
4.2) Save your database model into:
/home/user/public_html/yoursite.dev/docs
4.3) After saving your model, create a EER Diagram and associated it to the database connection created very earlier when we setup our stack.
Database>Forward Engineer (follow the instructions provided);
4.4) Under WorkBench we go to SQL Development and, by clicking under our connection, we should have our database visible as a new schema.
4.5) From Netbeans IDE we go to:
Services ;
4.6) Right-Click on “MySQL Server At Local Host” :
Start
4.7) Fill in - Basic Properties:
localhost
3306
yourusername
yourpassword
4.8) We then need to choose our database, and then click:
Connect
5) Configuring Remote Server (shared host) - Public-Key Authentication:
note: Your shared host must support ssh connection.
5.1) From our command line we copy our local pub key into our shared host:
scp ~/.ssh/mykey.pub mysharedhostuser@mysharedhostuser.mysharedhost.com:temp_mykey.pub
5.2) Connect to your shared host:
ssh sharedhostuser@sharedhostuser.mysharedhost.com (or username@sharedhost.com … obviously it depends on your shared host);
5.3) Once there, and if doesn’t exist, create a .ssh directory:
mkdir -p $HOME/.ssh
5.4) Copy the contents on our temporary pub key into and authorized_keys file:
cat ~/temp_mykey.pub >> ~/.ssh/authorized_keys
5.4.1) Remove the temporary key: rm temp_mykey.pub
5.4.2) Project keys directory: chmod 700 ~/.ssh
5.4.3) Protect keys file: chmod 600 ~/.ssh/authorized_keys
Note: Each programmer involved on the project should have their keys there.
5.5) We should now connect to our server, using the password created, when we generate our key/par:
ssh sharedhostuser@sharedhostuser.mysharedhost.com
Note – In order to clean up things here, we can type, on our command line:
ssh-add -l – this will give us the list of all configured keys on our system.
If they are keys that we may not need, we can well, remove them by doing:
ssh-add -d yourkeyname
5.6) Truth being told, we don’t want to enter our password, each time we interact with the server, so, let’s create a bash process for our ssh-agent:
ssh-agent bash
5.7) Let’s add our key during ssh-agent session:
ssh-add /home/user/.ssh/mykeywithoutextension
5.8) Connecting freely:
ssh sharedhostuser@sharedhostuser.mysharedhost.com
Note: Please note that, on some cases, the sharedhost is different from their site domain name. Make sure it’s all properly configured on this step because, this is how Capistrano will communicate with the server.
6) Configuring your shared host:
Please note that, those instructions on this point, don’t apply to all shared host environments. You should however, have in consideration two things.
A) Now is the time to configure your shared host, so, do it. :).
B) For that, take into consideration the points marked with *.
6.1) * Create a domain yoursite.com and a subdomain dev
6.1.1) On c.panel Domains / websites - Domains – Click on Add New: yoursite.com
6.1.2) On subdomains prefix – click Add New: dev
6.1.3) Again, and if does not exist - subdomains prefix - Add New - place: www
6.1.4) Finally click Create
6.2) Create a htdocs application
6.2.1) Domains / websites - Application - Add New
6.2.2) Place:
Name: htdocs
App Category: Static
App Type: Static/CGI/PHP
Create
6.3) Create a dev application
6.3.1) Domains / websites - Application - Add New
6.3.2) Place:
Name: dev
App Category: Static
App Type: Static/CGI/PHP
Create
6.4) * Create a symbolic link dev_current_public
6.4.1) Domains / websites - Application - Add New
6.4.2) Place:
Name: dev_current_public
App Category: Symbolic Link
App Type: Symbolic link to static/cgi/php
Extra Info: /home/yoursite/webapps/dev/current/public
Create
6.5) * Create a htdocs_current_public symbolic link application
6.5.1) Domains / websites - Application - Add New
6.5.2) Place:
Name: htdocs_current_public
App Category: Symbolic Link
App Type: Symbolic link to static/cgi/php
Extra Info: /home/yoursite/webapps/htdocs/current/public
Create
6.6) * Create a git application (not absolutely necessary but will be very important to allow :remote_cache on Capistrano – or on other words, to allow Capistrano to deploy ONLY your commited files, instead of uploading everything :))
6.6.1) Domains / websites - Application - Add New
6.6.2) Place:
Name: git
App Category: Git
App Type: Git 1.7.2 (or the newest you may have)
Extra Info: defaultUserPassw0rd
Create
6.7) Create a dev website yoursitedev
6.7.1) Domains / websites - Websites - Add New
6.7.2) Place:
Name: yoursitedev
Subdomains: dev.yoursite.com
Site Apps: * dev_current_public (pointed to your symbolic link)
URL path: /
Create
6.8) Create your main website yoursite
6.8.1) Domains / websites - Websites - Add New
6.8.2) Place:
Name: yoursitedev
Subdomains: www.yoursite.com yoursite.com
Site Apps: * htdocs_current_public (pointed to your symbolic link)
Create
6.9) * Install a statistic application like Awstats
6.9.1) Domains / websites - Application - Add New
6.9.2) Place:
Name: awstats
App Category: AWStats
App Type: AWStats 6.8 (ou sup.)
Extra Info: yoursite
Create
7) Create a Capfile and a Deploy.rb for your project:
7.1) On your project root, we create a file called Capfile (no extension) and we add:
require ‘rubygems’
require ‘railsless-deploy’
load ‘application/configs/deploy.rb’
7.2) From our project root, we navigate to application/configs/
and then gedit deploy.rb placing the following:
#############################################################
# General Settings
#############################################################
# What’s the name of your application?
set :application, "yoursite"
# Do we need sudo?
set :use_sudo, false
#If you’re using your own private keys for git you might want to tell Capistrano to use agent forwarding with this command. Agent forwarding can make key management much simpler as it uses your local keys instead of keys installed on the server:
ssh_options[:forward_agent] = true #use this option may prevent permission issues when you connect to your shared host.
# Deploy via :remote_cache that will allow Capistrano to deploy ONLY the last commits, instead of transferring all project files each time we deploy.
set :deploy_via, :remote_cache
#############################################################
# Stages
#############################################################
set :stages, %w(production development)
set :stage_dir, "application/configs/deploy"
set :default_stage, "development" #if we only do “cap deploy” this will be the stage used.
require 'capistrano/ext/multistage' #yes. First we set and then we require.
#############################################################
# Subversion
#############################################################
# What version control system will we use?
set :scm, :git
# Where will be located our master branch ?
set :repository, "git@github.com:gituser/projectnameongit.dev.git"
set :branch, 'master'
#############################################################
# Tasks
#############################################################
# Remove older realeases. By default, it will remove all older then the 5th.
after :deploy, 'deploy:cleanup'
7.3) Inside our project configs folder, we create a deploy folder:
mkdir ~/public_html/yoursite.dev/application/configs/deploy
7.4) We then create our developer stage file development.rb:
gedit ~/public_html/yoursite.dev/application/configs/deploy/development.rb
7.5) Then place and edit accordingly:
#############################################################
# Servers
#############################################################
# What is the user that will connect to your Development server?
set :user, "yoursharedhostusername"
# What is the domain name of your development server ?
role :web, "dev.yoursite.com"
# What is the directory path used to store your project on the remote server?
set :deploy_to, "/home/yoursite/webapps/dev/"
7.6) Similarly, we now create production.rb:
gedit ~/public_html/yoursite.dev/application/configs/deploy/production.rb
7.7) Then place and edit accordingly:
#############################################################
Servers
#############################################################
# What is the user that will connect to your Production server?
set :user, "myuser"
# What is the domain name of your production server ?
role :web, "yoursite.com"
# What is the directory path used to store your production project on the remote server?
set :deploy_to, "/home/yoursite/webapps/htdocs/"
#############################################################
# Tasks
#############################################################
# This will create a task (called create_symlinks) that will remove /public/.htaccess file coming from or dev environment : (that with the instruction: SetEnv APPLICATION_ENV development ) and, we replace by another, already configured on our production folder, that will have, instead: SetEnv APPLICATION_ENV production
task :create_symlinks, :roles => :web do
run "rm #{current_release}/public/.htaccess"
run "ln -s #{current_release}/production/.htaccess #{current_release}/public/.htaccess"
end
# After the deployment, we call the created task (create_symlinks):
after "deploy:finalize_update", :create_symlinks
7.8) From our project root, we can now type cap -T and see all available commands to us.
Note: cap -T will only show all the commands (more then 4), when we type it from the same location where our Capfile is.
8) Generating Zend Project Php Documentation
In order to generate the documention you can:
right-click under your project name and choose Generate PhpDoc.
However, this will force you to have the HUGE Zend Framework specific documentation as well, and we don’t want that.
8.1) From our netbeans IDE terminal window, we navigate to ~/public_html/ and then we do:
sudo ./generateDoc.sh yoursite.dev
This will execute our previously created bash process and will grab all information inside application, and place it organized inside yoursite.dev/docs/
8.2) In order to access this information locally go to your /docs/ location and open index.html file on your browser.
9) Push and Deploy
We are now ready to deploy our base project structure to our shared host.
9.1) From our project root we add a README file:
sudo touch README
Note: touch will place the time of our last change on our readme. If the readme doesn’t exist, it will create it.
9.2) From our project root, and after or repository has been initialized (init), we can add our files by using the IDE or our command line interface:
git add .
The . , tell git to recurservely add all directory contents to our local repository. We can then confirm by typing: git status
9.3) Let’s then commit what we have add:
git commit -m ‘first project commit’
9.4) Since we are using git hub as the central repository we should do (only once per project):
git remote add origin git@github.com:gituser/projectnameongit.git
All subsequent interactions under this same project will not require this step.
9.5) Let’s push our commits to our origin master branch:
git push -u origin master
In git > 1.7, you can ensure that the link is correctly set by using the –set-upstream option.
9.6) Let’s place on the server, the folders required for Capistrano to properly work:
cap deploy:setup (since development is our default stage, this is exactly the same as doing: cap development deploy:setup, if we what to deploy to our production server we should instead do: cap production deploy:setup)
9.7) Let’s check if all dependencies are in place :
cap deploy:check (or cap production deploy:check)
9.8) Let’s deploy our project files:
cap deploy (again, this is the same as: cap development deploy, and if we want to deploy to our production server we should cap production deploy)
9.9) If we can see our page under:
http://dev.yoursite.com
If all went well, I must congratulate you - your system is configured and you are ready to start your development.
FAQ
How to see apache log on Ubuntu ?
tail -f /var/log/apache2/error.log
Note: To quit do: Control + c
I’m seeing @todos that I don’t want to see under Netbeans Task Panel - @todos related to libraries that we use but that aren’t ours – how to remove those ?
Go to: Tools > Options > Miscellaneous > Tasks
Remove all possible finders except the @todo (this will avoid us to see some js library TODOS and possible others).
Then, go to: Project Properties > Ignored Folders > Add Folder…
Choose Zend library folder.
How do we start our terminal directly inside public_html directory ?
Add the following line to the end of your ~/.bashrc:
cd ~/public_html