cakephp URL get rid of /app/webroot - cakephp

I have a application and I want to integrated it into my CakePhp website. I put it into webroot folder. I tried to open it in browser via
http//mywebsite.com/appname
but it failed. Instead, I need to reach it via
http//mywebsite.com/app/webroot/appname.
And will be redirect to
http//mywebsite.com/app/webroot/appname/index.
Anyone know how to get rid of the /app/webroot string in my url? I do check the cake routing documentation but feels like didn't found a solution there.

Your Apache virtual host is not configured right.
Your Document Root needs to point to the webroot dir:
<VirtualHost *:80>
DocumentRoot /mydir/somthing/cake/app/webroot
ServerName mywebsite.com
</VirtualHost>
Then this will work:
http//mywebsite.com/appname

Related

How does one change nagios default url to custom url?

I am running Nagios Core 4.0.8 in my environment and I am looking to find a way to change the default url from https://example.com/nagios to https://example.com. Is there a way one can do that?
You will need to edit the cgi.cfg file for Nagios.
vim /usr/local/nagios/etc/cgi.cfg
Change url_html_path=/nagios to url_html_path=/
Edit nagios.conf:
Change ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin" to
ScriptAlias /cgi-bin "/usr/local/nagios/sbin"
Comment out the line Alias /nagios "/usr/local/nagios/share" and then add below
DocumentRoot /usr/local/nagios/share
Add the following at top of the configuration:
<VirtualHost *:80>
ServerName status.example.com
and add </VirtualHost> at the bottom.
Edit your /usr/local/nagios/share/config.inc.php file:
Change $cfg['cgi_base_url']='/nagios/cgi-bin'; to $cfg['cgi_base_url']='/cgi-bin';
Restart Apache and Nagios
If you are using Apache to serve your Nagios page you can do different things. Apache configuration files are usually located in /etc/apache2/.
Probably your DocumentRoot is set to /var/www, so you can create a file named "index.html" and place this code inside it to redirect to /nagios URL:
<META HTTP-EQUIV="Refresh" Content="0; URL=/nagios">
You can also edit your nagios apache config (probably /etc/nagios/apache2.conf...) or apache config /etc/apache2/*.conf and add:
RedirectMatch ^/$ /nagios
If you don't like these methods there are more, just think of it as using Apache to redirect, not like a Nagios thing.

Apache localhost authentication

I am trying to setup up basic authentication to a folder on my localhost running apache. Currently the app runs fine without authentication. I have setup a virtual host so I can access my application through dev.myapp.com
The code I add to my .htaccess file to force authentication is:
<Directory "/Users/myusername/Sites/dev.myapp.com">
AuthType Basic
AuthName Test
AuthBasicProvider file
AuthUserFile /etc/apache_users
Require valid-user
</Directory>
I have created a user.
When I type dev.myapp.com into the browser I get an internal server error. I am fairly new to apache. A point in the right direction would be appreciated.
Thanks.
First off, using .htaccess is a bit slower and requires that you have set the AllowOverride directive accordingly. It is recommended that you instead use httpd.conf to establish basic authentication. The Apache documentation explains all of this so check out this link http://httpd.apache.org/docs/2.2/howto/auth.html.
Regardless, I think I see the error. Your <Directory> tag looks a little odd. I understand the name of your site is dev.my.app.com but is that the actual name of the folder where the site dev.myapp.com points to on your server? Your httpd.conf file should have an entry like this:
<VirtualHost *>
DocumentRoot "document/root/path"
Other directives here
</VirtualHost>
The DocumentRoot is where Apache directs all incoming web traffic. If you are trying to establish authentication for your entire site, the value of DocumentRoot is most likely what you would want in your Directory tag ... making it <Directory /document/root/path>.
To locate httpd.conf look in in /etc/apache2/. Make sure to restart your server after you change the file (sudo /etc/init.d/apache2 restart). Hope that helps, please update if you haven't already resolved the problem.

Local domain simulation with Apache2 and Yii

I'm trying to convert http://localhost/website to http://website.loc, but I'm not able to do that. Here's what I could do:
I edited /etc/hosts (I'm on Ubuntu) by changing 127.0.0.1 localhost to 127.0.0.1 localhost website.loc and saved changes
I created a new file named website inside /etc/apache2/sites-available with this content:
<virtualhost website.loc>
ServerName website.loc
DocumentRoot /home/myuser/projects/website/
<directory /home/myuser/projects/website/>
AllowOverride all
Options Indexes FollowSymLinks MultiViews
Order allow,deny
allow from all
</directory>
</virtualhost>
And I created a softlink to sites-enabled to enable this. After that, I restarted Apache.
By the way, I am using the Yii framework with any request to / redirected to /index.php, so index.php is not needed in the query.
So, when I write website.loc/ into chrome, it moves me to http://website.loc/site/login (the login index page, that's almost expected even if I was logged in as localhost, because the site url "changed" to website.loc, so the cookies are not shared), but the content is:
Not Found
The requested URL /website/index.php was not found on this server.
Apache/2.2.16 (Ubuntu) Server at website.loc Port 80
Am I doing something wrong? Thanks in advance, mates
Edit: It was all about the .htaccess inside /home/myuser/projects/website. It's RewriteBase was pointing to /website. Changing this to / and it worked like charm. Thanks #Chux for reminding me to check the .htaccess!
First, http://website.loc/index.php, check if that work. If that work, means that you need to create an .htaccess in your website root folder to enable that route format

cakephp - one framework, a few apps on localhost subdomain

How to prepare CakePHP framework to work for many apps in one CakePHP framework?
I want prepare structure folders like this:
app1/
app2/
app3/
cake/
vendors/
plugins/
index.php
I would like using http://app1.localhost/ do running app from app1/ folder?
It's possible?
Basically all you need to do is configure the app/webroot/index.php file of every individual app correctly to point to the correct ROOT/cake folder. The rest is Apache virtual host configuration to point the subdomains to the right app folder.
I'm running XAMPP but I'm assuming you're running something similar on your machine. Anyway, go into your apache\conf folder and open up the httpd.conf file. XAMPP has a file called apache\conf\extra\httpd-vhosts.conf that is better for adding Virtual Hosts.
So you'd want to enter the appropriate directives like so...
<VirtualHost *:80>
ServerAdmin postmaster#localhost
DocumentRoot "C:/path-to-your-app-webroot-folder-no-trailing-slash"
ServerName app.localhost
##ServerAlias www.dummy-host.localhost
ErrorLog "logs/app.localhost-error.log"
CustomLog "logs/app.localhost-access.log" combined
<Directory "C:/path-to-your-app-webroot-folder-no-trailing-slash">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Furthermore, if you're on Windows XP, you'll want to make an entry in your C:\Windows\system32\drivers\etc\hosts file of 127.0.0.1 app.localhost to resolve the sub-domain. That should get the job done.

How to install cakephp on localhost?

I wanna to know how to install cakephp on localhost?
Please explain me.
I usually make an apache and mysql installation on a linuxbox. I can use windows too, however I do not recommend it ;)
So, I usually make a new entry into the /etc/hosts file to make a sitename available to cakephp.
127.0.0.1 localhost caketest.local
next step to copy all cakephp files into a subdirectory inside /home/myusername/public_html/caketest
app
cake
index.php
plugins
README
vendors
.htaccess
then I set up the site to apache (not neccessary),
<VirtualHost *:80>
DocumentRoot "/home/myusername/public_html/caketest"
ServerName caketest.local
# This should be omitted in the production environment
SetEnv APPLICATION_ENV development
<Directory "/home/myusername/public_html/caketest">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
restart apache. you also need to edit the .htaccess files and place a RewriteBase directive with hte path to the actual directory, e.g.
RewriteBase /~myusername/caketest
create a database, set the db connection in cake config files and that's all.
you can point your browser to http://caketest.local
if you do not want a test site url you can skip hosts, and apache vhost creation, but the url to use should be http:/localhost/~myusername/caketest
another important thing is to enable userdir modul in apache, and also check if using php is enabled in userdirs too.
If you're on windows, get WAMP. Install it, then download CakePHP in C:\wamp\www\. Extract CakePHP in that folder so you have a folder kind of like this: C:\wamp\www\cakephp\. Now you can access the installation by going to localhost/cakephp/.
An old article of mine but still quite relevant:
Installing CakePHP
Assuming you have a *AMP setup (Apache+MySQL+PHP), just copy the files to your htdocs folder. On Ubuntu, it's /var/www, so you would create /var/www/myApp and copy the whole Cake structure into there, ending up with something like:
/var/www/myApp/app/
/var/www/myApp/cake/
/var/www/myApp/vendors/
/var/www/myApp/index.php
/var/www/myApp/.htaccess
Then you can access your app by the url: http://localhost/myApp

Resources