Wednesday, September 26, 2012

Setting up Apache To Work with PHP and Zend Framework in Fedora for Development

To get started the first thing we need to do is install Apache and PHP.
yum install httpd php
You can setup Apache to run in any users public_html directory but I am the only one using my computer and I like to name my websites directory whatever I want so we have to create the folder and give Apache permissions to it:
mkdir ~/websites
chmod 711 /home/accessrichard
chmod 755 /home/accessrichard/websites
After that we have to set Apache to redirect our localhost traffic to the above website directory. Create your own Apache config file in /etc/httpd/conf.d
touch /etc/httpd/conf.d/accessrichard.conf
Add something similar to the following in the file we just created replacing your home directory name and your website folder name as appropriate. In the below example I am setting up 2 different websites, demo.dev and demo2.dev.
NameVirtualHost *:80
<VirtualHost *:80>
     ServerName demo.dev
     DocumentRoot /home/accessrichard/websites/demo/public

     SetEnv APPLICATION_ENV "development"

     <Directory /home/accessrichard/websites/demo/public>
         DirectoryIndex index.php
         AllowOverride All
         Order allow,deny
         Allow from all
     </Directory>
</VirtualHost>
<VirtualHost *:80>
     ServerName demo2.dev
     DocumentRoot /home/accessrichard/websites/demo2/public

     SetEnv APPLICATION_ENV "development"

     <Directory /home/accessrichard/websites/demo2/public>
         DirectoryIndex index.php
         AllowOverride All
         Order allow,deny
         Allow from all
     </Directory>
</VirtualHost> 
We also have to modify our etc/hosts file in order to redirect website traffic from demo.dev and demo2.dev to localhost as follows:
127.0.0.1               localhost.localdomain localhost demo.dev demo2.dev
::1             localhost6.localdomain6 localhost6
And finally within our website directory we will have our php .htaccess file redirect all traffic to our router index.php. In our public direcotry create the file .htaccess with the following:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

No comments:

Post a Comment