Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

How to setup apache to make the tutorial sample work

I downloaded the sample code "tutorial-master".

I am using debian 7. I have enabled mod_rewrite for apache. Then I edit file /etc/apache2/sites-available/default to setup a virtual directory pointing to"tutorial-master/public" folder like following:

<VirtualHost *:80>
    ServerAdmin [email protected]

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

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride All
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    Alias /tutorial/ /home/xyz/Documents/Projects/tutorial-master/public/
    <Directory "/home/xyz/Documents/Projects/tutorial-master/public">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Then I go to http://localhost/tutorial/, it shows:

Hello!
Sign Up Here!

When I click link "Sign Up Here!", I get the 404 error:

Not Found

The requested URL /home/xyz/Documents/Projects/tutorial-master/public/index.php was not found on this server.

Because the source code is downloaded from Phalcon, it should not have problem. I think it's something wrong with my apache configuration. Please advise. Thanks.



1.4k
edited May '14

I think u do not enable the .htaccess in ur apache properly. U can test it if u take an error in ur htaccess and than u get an 500 Internal Server Error :)

Check this too in ur httpd.conf:

# use .htaccess files for overriding,
AccessFileName .htaccess
# and never show them
<Files ~ "^\.ht">
    Order allow,deny
    Deny from all
</Files>
edited May '14

Thanks, Ak-Army,

I have checked apache2.conf, which is the main apache configure file on Debian 7. The AccessFileName .htaccess and related <Files> directives are there. And I added some garbage in the .htaccess files, I did get 500 error. This means the .htaccess files are working. It looks like I have to change the rewrite rules inside the .htaccess files. Since I am new to LAMP, I have no idea how to change these files. I paste the content of these files as following:

tutorial-master/.htaccess:

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

tutorial-master/public/.htaccess:

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

Do you or anyone have an idea how to setup these files so that the "Sign Up Here" link of tutorial project can work?

edited May '14

Well,

Finally, I make it works although it is not working as I expected. To who may be interested, I put the solution below.

I changed my apache configure file "/etc/apache2/sites-available/default" to use tutorial-master/public as website root as following:

<VirtualHost *:80>
    ServerAdmin [email protected]

    DocumentRoot /home/xyz/Documents/Projects/tutorial-master/public

    <Directory "/home/xyz/Documents/Projects/tutorial-master">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

    <Directory "/home/xyz/Documents/Projects/tutorial-master/public">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Now, I can see the signup page at http://localhost/signup. But what I expected to do is setup a virtual difrectory to access the tutorial project signup page by access http://localhost/tutorial/signup. It still needs more work (on rewrite rule I guess).



2.1k
Accepted
answer

Finally, I figured out how to setup.

1). Move tutorial-master folder to /var/www/tutorial

2). Change /etc/apache2/sites-available/default to:

<VirtualHost *:80>
    ServerAdmin [email protected]

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

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride All
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

3). Add following lines to tutorial/public/index.php:

    //Setup a base URI so that all generated URIs include the "tutorial" folder
    $di->set('url', function(){
        $url = new \Phalcon\Mvc\Url();
        $url->setBaseUri('/tutorial/');
        return $url;
    });

4). Now, you can input http://localhost/tutorial in browser to access the tutoial project. When you click "Sign Up Here!", you will be direct to http://localhost/tutoial/signup as expected.

This solution adds a base url to generated url rather than changes the .htaccess file in the project. Maybe changing rewrite rules can get the same result. But this solution is more comprehensible and works perfect for me.