We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Phalcon project in Alias Directory (Apache)

Hello there.

First of all, am absolutely new in Phalcon, so I'm gonna tell the long story, if you want to go directly to the question, scroll down until you find ¡¡¡QUESTION!!!

I must say, It's been a headache to be able to install correctly phalcon in my linux distro. I'm using elementary OS Luna (based on Ubuntu 12.04), and well, I even had to do a fresh OS install to get rid of two differents php installations and some mysql issues when installing xampp.

Now, on fresh install, I installed separatedly apache + mysql + php + phpmyadmin (NO XAMPP) and everything seems to be working like a charm. Then I installed phalcon, and eventhough I had some difficulties, I could make it work, since I saw the phalcon extension in php.info() and the phalcon commands in terminal.

Now, when creating the demo https://docs.phalcon.io/en/latest/reference/tutorial.html I did

$ cd /var/www/
$ phalcon project test

and I get the correct output

Phalcon DevTools (1.3.0)

  Success: Controller "index" was successfully created.  

  Success: Project 'test' was successfully created.  

But when going into https://localhost/test I saw this:

Mod-Rewrite is not enabled

Please enable rewrite module on your web server to continue

So I googled, and found that I needed to edit "/etc/apache2/sites-available/default", I did and in the section "<Directory /var/www/>" I had to set "AllowOverride All", so that section was modified to be like this:

DocumentRoot /var/www
<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>
<Directory /var/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>

Then, I tried again https://localhost/test but this time I saw:

Volt directory can't be written.

So again, I googled and I found that was an issue with permissions of "cache" and "views" directories of the project. As I said, I'm quite newbie at phalcon, so I just found "views" folder, and I changed permissions to 777, It did nothing. So I decided to change permissions recursively to all project folder like this:

$cd /var/www/
$chmod -R 777 test

And after that, FINALLY I saw:

Congratulations!

You're now flying with Phalcon. Great things are about to happen!

So NOW, I'm ready to really start reading documentation and programming with phalcon. Now after that long and boring story, it's time for the question.


¡¡¡QUESTION!!!

I've read how to make an Alias for Apache www folder, to be able to work comfortably from a dir like "/home/my-name/web-docs/" where there are no issues for permissions and no deals with chmod every single change in a file. I did that adding this code to "/etc/apache2/sites-available/default":

Alias /web/ "/home/julian/web-docs/"
<Directory "/home/julian/web-docs/">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>

And now, I'm able to go to https://localhost/web/ and see the index.html I have in "/home/julian/web-docs/index.html", quite easy, but when making an example phalcon project in that dir, not everything works that smooth. I did:

$cd /home/julian/web-docs
$phalcon project blog

    Phalcon DevTools (1.3.0)

      Success: Controller "index" was successfully created.  

      Success: Project 'test' was successfully created.  

But when going to https://localhost/web/blog I got the surprising message:

Not Found

The requested URL /home/julian/web-docs/blog/public/ was not found on this server.

Apache/2.2.22 (Ubuntu) Server at localhost Port 80

I've checked, and the dir described exists, and permisions shouldn't be a problem there, am I right? I've googled and I haven't find a solution this time. Any help is appreciated. And again, sorry for all the long details.



98.9k

Hello Julian, try making public the "public" directory instead of the project root:

Alias /web/ "/home/julian/web-docs/public"
<Directory "/home/julian/web-docs/public">
    Options All
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>

Thanks, I'll try that tonight and I'll let you know :)

edited Mar '14

I just tried, no luck.

I have right now all possible directories like this:

Alias /web/ "/home/julian/web-docs/"
<Directory "/home/julian/web-docs/">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>

Alias /blog/ "/home/julian/web-docs/blog/"
<Directory "/home/julian/web-docs/blog/">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>

Alias /blog-public/ /home/julian/web-docs/blog/public/
<Directory /home/julian/web-docs/blog/public/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>

Alias /blog-public2/ /home/julian/web-docs/blog/public
<Directory /home/julian/web-docs/blog/public>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>

Notice the difference between /blog-public/ and /blog-public2/, the last "/" after public in the dir.

When going to https://localhost/web/ I see the index.html test I have placed in ~/web-docs/index.html

When going to https://localhost/blog/ I see this:

Not Found

The requested URL /home/julian/web-docs/blog/public/ was not found on this server.

Apache/2.2.22 (Ubuntu) Server at localhost Port 80

When going to https://localhost/blog-public/ I see this:

Volt directory can't be written

When going to https://localhost/blog-public2/ I see this:

Index of /blog-public2

[ICO]   Name    Last modified   Size    Description
[DIR]   Parent Directory         -   
[DIR]   css/    18-Mar-2014 19:37    -   
[DIR]   files/  18-Mar-2014 19:37    -   
[DIR]   img/    18-Mar-2014 19:37    -   
[   ]   index.php   18-Mar-2014 19:37   530  
[DIR]   js/ 18-Mar-2014 19:37    -   
[DIR]   temp/   18-Mar-2014 19:37    -   
Apache/2.2.22 (Ubuntu) Server at localhost Port 80

And when I click in the index.php, it says:

Not Found

The requested URL /home/julian/web-docs/blog/public/publicindex.php was not found on this server.

Apache/2.2.22 (Ubuntu) Server at localhost Port 80

Any Other Ideas?

EDIT

I just tried to set all blog folder -R permisions to 777, It worked, not in the /blog/ but in the /blog-public/

Shouldn't be working from /blog/? just as /var/www/blog/, no need of /var/www/blog/public/ ?

Hi, It's been a while since this question was asked but for those coming from google (as I did in the first time) I'll post what did work in my development setup hoping that it helps somebody in the future. My setup:

  • Apache server 2.4.9 with mod_rewrite.c (64 bits)
  • PHP 5.5.12 (64 bits VC11TS)
  • php_phalcon.dll 1.3.2 (64 bits, VC11 TS)
  • Windows 8.1 (64 bits)

Here follows the configuration needed for an Alias named myalias located at e:\alias\root\ and a project named myphalconproject. Tested with the security sample app vokuro:

Alias Configuring

File myalias.conf (located at your alias directory)


Alias /myalias/ "e:/alias/root/" 
<Directory "e:/alias/root/">
    Options Indexes FollowSymLinks MultiViews
    Require all granted
</Directory>

File e:/alias/root/.htaccess


<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /myalias/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

File e:/alias/root/myphalconproject/.htaccess


Options +FollowSymLinks -MultiViews -Indexes

DirectoryIndex index.html index.php

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /myalias/myphalconproject/
    RewriteRule  ^$ public/    [L]
    RewriteRule  (.*) public/$1 [L]
</IfModule>

File e:/alias/root/myphalconproject/public/.htaccess


AddDefaultCharset UTF-8

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /myalias/myphalconproject/
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>

Besides that, in order to the URL component work properly I did a small edit at the file app/config/services.php (in version 1.3.2, line 33) to change the BaseURI to the alias directory


/**
 * The URL component is used to generate all kind of urls in the application
 */
$di->set('url', function () use ($config) {
    $url = new UrlResolver();
    // $url->setBaseUri($config->application->baseUri);
    $url->setBaseUri('/myalias/myphalconproject/');
    return $url;
}, true);

I hope it helps!