I am just starting to work with CakePHP3.0 and while following the 'Quick Start Guide' I came across a step that has me stuck.
The section labeled DATABASE CONFIGURATION has me create some MySQL tables (I copy pasted from the site) and then run the commands: bin/cake bake all bookmarks, bin/cake bake all users, and bin/cake bake all tags.
After running those three commands several files have been generated; the Models and Controllers associated with the tables I just created. However, the Views have not been created...By the way I am using Ubuntu 12.04
As suggested by the tutorial I checked my apache2/mods-enabled directory for the rewrite.load and it is there.
Has any else experienced this issue?
It is likely that I am making a simple mistake
This is the output when I ran bin/cake bake all bookmarks the first time:
As the tutorial suggested, if I receive a 404 page not found error I should make sure that mod_rewrite is enabled for apache2, also I noticed that it says to use http://localhost:8765/bookmarks since my web server is configured on port 80 I have been ignoring the port # suggested by the tutorial.
Here is a screenshot of my apache2/mods_enabled/: (rewrite.load is present)
Lastly, here is the data source that I have configured in /config/App.php:
It is beginning to appear that the problem is with my Apache configuration and the rewrite rules. I will investigate into this further.
Turns out that I was initially confused about what CakePHP3 was supposed to create and realize now that it was running as expected (see question above for output). One the proper DocumentRoot is set, if rewrite is not set up properly navigating to you page may begin a download of the file you mean to view instead.
The real problem was with my Apache configuration. These are the steps I followed to configure Apache 2.4 (after reinstalling Apache):
Add the new DocumentRoot in /etc/apache2/sites-available/000-default.conf and in /etc/apache2/sites-enabled/000-default.conf
Enable mod_rewrite: a2enmod rewrite
Restart Apache: service apache2 restart
After enabling rewrite your /etc/apache2/mods-enabled/ may look like this(notice rewrite highlighted):
Problem has been resolved. Thanks to this post!
#user1843159 - Thanks for pointing me toward the direction of Apache Configuration.
Related
I am trying to create a Rest API in PHP, and I would like to use a framework. I have followed several tutorials on the subject. Despite my efforts, I am unable to get any of them to work, for either cakephp or codeigniter. The sites that contain these tutorials have numerous comments attached from people giving compliments to the writer. So I believe somebody got them to work.
Here is one example of what I have done: I built the Rest application according to this tutorial http://www.bravo-kernel.com/2015/04/how-to-build-a-cakephp-3-rest-api-in-minutes/ using composer to install my plugins and extensions. I did all of this under the directory path /var/www/html/cakephp/cake3api_app/. I built the cocktails table in my database, and I reconfigured config/app.php to have access to it. I opened up my FireFox web browser, and accessed the index page. Among other things, it had this output:
Please be aware that this page will not be shown if you turn off debug mode unless you replace src/Template/Pages/home.ctp with your own version.
URL rewriting is not properly configured on your server.
1) Help me configure it
2) I don't / can't use URL rewriting
Environment
Your version of PHP is 5.5.9 or higher (detected 5.6.20-0+deb8u1).
Your version of PHP has the mbstring extension loaded.
Your version of PHP has the openssl extension loaded.
Your version of PHP has the intl extension loaded.
Filesystem
Your tmp directory is writable.
Your logs directory is writable.
The FileEngine is being used for core caching. To change the config edit config/app.php
Database
CakePHP is able to connect to the database.
DebugKit
DebugKit is loaded.
I go to my Rest client and enter a local host URL that I can't post due to lack of reputation (localhost "slash" cakephp "slash" cake3api_app "slash" cocktails), and this is what it gave me:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /cakephp/cake3api_app/cocktails was not found on this server.</p>
<hr>
<address>Apache/2.4.10 (Debian) Server at localhost Port 80</address>
</body></html>
I assume (perhaps incorrectly) this is because I need to configure my URL rewriting on Apache. I followed the URL given by the aforementioned CakePHP debug page (lack of reputation prevents me from posting the link), and it is all Greek to me. It seems I need to write what the page is talking about to an .htaccess file, but I am unsure which one, and also where in the .htaccess file I need to write it. There are several .htaccess files that come with CakePHP and the zipped tutorial code from GitHub has several of its own.
So my question is this: What do I need to do in order to make the code in question work in such a way that I can type a URL into my browser and it gives me JSON data in return?
The source code to the tutorial can be found here: https://github.com/bravo-kernel/application-examples/tree/master/blog-how-to-build-a-cakephp3-rest-api
Edit:
I changed the lines in /etc/apache2/apache2.conf that read "AllowOverride None" to read "AllowOverride All", but this had no effect.
Adding "LoadModule rewrite_module libexec/apache2/mod_rewrite.so" to /etc/apache2/apache2.conf broke apache, but adding it to the .htaccess at the CakePHP application root has no effect.
The file /etc/apache2/sites-available/default did not exist on my machine, but creating it and adding the code listed on the CakePHP book page had no effect.
There was not an app/ directory in the CakePHP application, but creating one and adding an .htaccess file to it with the contents specified in the CakePHP book had no effect.
Adding the line "RewriteBase /var/www/html/cakephp/cake3api_app/" to the .htaccess file in the webroot directory had no effect.
I restarted Apache after each of these changes.
URL rewriting is necessary to make the CakePHP framework work. This is how I solved the problem for myself. Please note that this solution worked for me on Debian Jessie running Apache version 2.4. It may not work for other versions of Linux and definitely won't work for Windows.
First, I edited /etc/apache2/apache2.conf at about line 164 and changed the <Directory /var/www/> rule to read:
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Second, and this is important, shut down the computer and restart it. The reason why this is needed instead of restarting Apache is because Apache on Debian relies on a specific script Debian runs on start up to set environment variables, and using the binary Apache command to restart Apache will not set these variables. Rebooting the computer was good enough for me on a development machine.
After taking these two steps, I was able to get the Rest API to work, and the CakePHP index page displayed background colors behind each section of messages.
So I am trying to get Symfony working on my server by following these install instructions.
http://symfony.com/doc/current/book/installation.html#book-installation-permissions
I got to the part where I ran this command in console in the directory where I wanted the framework to be installed.
symfony new my_project_name
I then followed these instructions to set my web root directory to /web as I believe I'm supposed to do?
It installed all the files correctly since I can see them in the folder. I made sure to restart apache and I'm positive document root is in the correct location.
http://tecadmin.net/how-to-change-document-root-of-primary-domain-in-cpanel/#
Once I did this I was supposed to be able to test the installation, but nothing seems to happen except that 406 error?
This is the exact error I get.
An appropriate representation of the requested resource /app.php could not be found on this server.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
I'm not sure what else to do.
Please note, that since I'm using CPANEL I can't change the virtual host configurations of apache if that is the issue, so I'm looking for a CPanel specific answer. Thank you!
Okay so I finally figured out what to do, I had 2 problems. Because I installed as the 'root' user I had to run the following command on the symfony installation.
chown -R devdistribution:devdistribution .
In my case, my username is devdistribution but you would just put your own. Make sure to do this on the top level not just the /web folder.
I knew this was one of the errors because the apache log said something along these lines
Mismatch between target UID (520) and UID (501) of file "/home/devdistribution/public_html/distribution_tech/web/app.php"
This fixed the 500 error, but not the 406. To fix the 406 error you need to login into WHM and type modsecurity to find it in the search field.
go to the configuration option for it, you will see this.
Rules Engine SecRuleEngine
This setting controls the behavior of the rules engine.
Process the rules.
Do not process the rules.
Process the rules in verbose mode, but do not execute disruptive actions.
Select 'Do not process the rules'. Then save at the bottom. This fixed the issue for me and I was able to see the opening symfony screen!
However, this I'm sure leaves security vulnerabilities now...so I still need help on the proper way to handle mod security with symfony in this case if anyone knows? I'll make a separate question for this.
Step 1:
Login to your cPanel account and start searching for the file manager icon under the files section.
Step 2:
As always, you need to make sure, you see the public_html directory. Depending on the web hosting you have, you may also see the home directory after opening the file manager.
Step 3:
Find the .htaccess file and right-click to edit.
Step 4:
After choosing an edit option, you see a popup asking to disable encoding if you wish. You have to click on the Edit button to continue.
Step 5:
On a new tab, you can see many rewritten rules. You have to add the code to the .htaccess file.
<IfModule mod_security.c>
SecFilterEngineOff
SecFilterScanPOSTOff
</IfModule>
Currently trying to setup my localhost and install php as well with the new osx yosemite
i've been following the following instructions: http://coolestguidesontheplanet.com/get-apache-mysql-php-phpmyadmin-working-osx-10-10-yosemite/
I've uncommented everything they said for apache and php and restarted apache afterwords
FYI. SO won't let me type localhost so where I write lh means that
I'm successfully able to get to
lh/
but... if I try to go to any other pages it says the site can't be found.
There is a index.html in the Sites folder which I have tried to access lh/~myusername/index.html
and I have the same file in /Library/WebServer/Documents which I have tried to access lh/index.html
Can someone tell me the step that I am missing that needs to get all of this to work correctly?
Apache has a DocumentRoot which is the default page for localhost. That guide tries to enable a virtualhost for a directory in your local user but it is not possible to know why yours is not working as it is not clear which part you have gone wrong.
However it is better to use normal virtualhost configuration to define any folder you want for Apache as it is pretty much the same as Apache under Linux. Follow this guide for a basic understanding of creating virtualhosts for Apache. Let me know if you have any issues.
I had the same exact problem.
Followed all the steps, retraced them but still got the error.
First, check for a syntax error in your httpd.conf by typing in terminal:
sudo apachectl configtest
If you get a Syntax OK, then most likely its one of the settings in your httpd.conf file that isn't set right
You can check out this post and try what some other people did:
Apache localhost/~username/ not working
My error was that I didn't actually include "~" in the username (thought it was just there to define the var 'username' - took me almost 2 god damn hours to figure that out -__-)
After I got that far
localhost/~username
worked but I didn't have permissions to view it.
Had to do an extra step here to add permissions for my user:
http://coolestguidesontheplanet.com/forbidden-403-you-dont-have-permission-to-access-username-on-this-server/
I want to start learning php, I install apache 2.2 and I want to run my first.php file, I look for www folder in the installation folder of ApacheSoftwareFoundation but I couldn't find it.
here's the files in the apache
I tried to put my php file in htdocs but it doesn't work , can some one help ?
Edit
Doesn't work means when I make http:localhost/first.php , returns Unable to connect
Now the apache is running, when I open htt'://localhost/
returns "it works"
but when I open any php file, it opens as-is ?!
You'll need to check a couple of things...
Make sure the Web Server is running ,either the service
or the program, is running and that you have the correctly configured the Virtual Directories.
If the web server just outputs the
content of the .php file, it could
mean that you don't have mod_php
installed. Meaning the server does
not have the Mime type registered so
it will just try to treat it as a
text file ...
And as your on windows you might consider using something like XAMPP. It gives you a Full Working AMP (Apache Mysql Php) Stack with one install and a easy control manager to start/stop the servers. Other wise do a couple of Google searches on how to install the php module for your Web Server on Windows
Update
To start the server try executing the executable bin/httpd.exe .
Now the apache is running, when I open
http://localhost/ returns "it works"
but when I open any php file, it opens
as-is ?!
A default installation of Apache on windows does not include the necessary modules to run PHP. After installing Apache, you must either:
Install PHP separately and follow the instructions described here to configure Apache to use the installed version of PHP to serve .php files. I've been through this and took me hours to get every thing to work.
Recommended for you: uninstall Apache; install WAMP instead.
if you look in your httpd.conf file you will find the default root directory, it doesnt have to be called www. It is the htdocs by default.
error 500 covers a whole host of things. from compile error, to permissions.
Have you put a simple file of
<?php
echo "test";
?>
As your test php page to rule out other issues?
You need to:
Construct your URI correctly: http://localhost/first.php (with the //)
Ensure that Apache is running
all files in htdocs can be referenced from outside
Just put a basic file named index.php
and visit site http://localhost/
In general type in http://localhost/filename
You say that you get a connection error when you try to go to your webpage. Since it looks like you're using Windows Vista or 7, make sure you're running Apache as an administrator; it can't bind to port 80 otherwise. Also check that other programs like Skype aren't binding to port 80. If you still can't find the problem, check the error log. (logs/error.log by default I think)
The problem is that Apache was installed but not started
If you are using xampp start it and then start apache through control panel
for others look for similar instruction
For a bit of history - this is the first time I attempted to setup a test symfony project, just to have a play with it.
The symfony project was setup in the following location:
~/symfony_projects/myproject/
Now, with cpanel, the httpd.conf is automatically generated (but I'm sure you knew that), and it uses ~/public_html/ as the web root and splits it up by domain name (virtual hosts) - so for this example, lets say it's ~/public_html/example.com/.
So the symfony project is all setup now, the next problem was trying to figure out how to setup the server so it points to the /web part of the project - this is where I found it tricky.
I tried doing the following:
ln -sf ~/public_html/libs/Symfony/data/web/sf ~/symfony_projects/myproject/web/sf
ln -sf ~/symfony_projects/myproject/web/* ~/public_html/example.com
That unfortunately didn't work though. When trying to go to http://www.example.com it just gave me a 500 error.
Any other options here? Taking into consideration that I cannot modify the httpd.conf. And even if I could, it's auto-generated and would rather not (in cpanel).
* Update *
I just tried what was suggested by #Dan, but with the same issue - getting HTTP Error 500 (Internal Server Error). So, it looks like something else is the issue.
I checked my error_logs but didn't see anything useful there. Is there any other way I can check to see what the problem is?
* Another Update *
Just tried http://example.com/frontend_dev.php and it works perfectly - gives no errors at all, which makes it kind of hard to debug the production controller.
So the Development controller works flawlessly and the production is spitting out the 500 error - any ideas? :/
I just copy everything out of web/ (including css/, js/, etc. subfolders) one level higher, then edit the index.php/yourapp_dev.php files' require statements to reflect the change in path. Add some rewrite rules to forbid direct access to the rest of the directories and you're all set on servers where you can't change the document root.
If you look at the http.conf virtual host entry for the symfony project the last line in generally a commented out include statement. If you uncomment that line you add any extra virtual host configs you need into that file. Then just restart apache. Anything in the file will then be appended in place of the include statement.