Can't route to CakePHP Controllers with Apache - php

I have my own digitalocean droplet setup and followed this tutorial to a T to get Cakephp working
Setup CakePHP with LAMP Stack
Everything works exactly as written in that tutorial besides for 'Step 6' - Creating the Article user interface. (Books in my case)
After using the bake all command and navigating to `/books' I get a 404 not found
As you can see CakePHP is setup and working at the top level URL, however when trying to move past that to a Controller that definitely exists it can't find it.

After some more digging, I found the issue. Apparently mod_rewrite is turned off by default on Ubuntu
`sudo a2enmod rewrite
systemctl reload apache`
is the solution here

Make sure your rewrite mod is On
If you are using Linux goto /etc/apache2/sites-enabled -> open 000-default.conf file
<VirtualHost *:80>
....
// add these lines
<Directory /var/www/html>
#Options FollowSymLinks
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order deny,allow
Allow from all
</Directory>
....
<</VirtualHost>
Save it.
restart your server: sudo service apache2 restart
give your project permissions by giving this command:
sudo chown -R user_name:www-data project_name/
sudo chmod -R 755 project_name/
cd project_name
chown -R www-data tmp
chown -R www-data logs
chmod -R 777 tmp
chmod -R 777 logs

Related

Apache + PHP (multi version) + multi sites (with different PHP versions) + user access setup

I was searching the internet looking for solution, unfortunately none of those was helpful.
I am trying to achive the following:
On Linux Ubuntu 20.04 setup several sites. Each site may have different PHP version. Also users of each site must not be able to read/write files on other sites. Each site should have own group/user.
I see the solution this way (and was trying this way):
to create different folders with different group/users (site1/site1, site2/site2)
install Apache, PHP as FCGI
enable MPM module to be able to run script on behalf of different user on each site
What I could do so far. I could install Apache + PHP (+FCGI) with different versions. So far it was ok, no problem.
Then I need to separate users I enabled MPM modules of Apache. The best result I could get is to run PHP script as if on behalf of different users. But when PHP script is trying to create a file in the same folder I can see the owner/group as www-data. So security issues are not resolved.
I not not sure that enabling MPM is working as it should.
Since there is a lot of work done, I didn't want to show all long list of commands here. I hope someone could advise the correct guide I could look at.
If not helpful I'll show all here
UPD 1: (I coudn't find a proper way to show code in reply comment, so I do this way)
sudo apt-get install apache2
sudo apt-get install php7.4
sudo apt-get install libapache2-mpm-itk
sudo useradd -m --shell /bin/bash --home /home/u-site1 u-site1
sudo passwd u-site1
sudo vi /etc/apache2/sites-available/site1.local.conf
-- start of content
<VirtualHost *:80>
ServerName site1.local
ServerAdmin info#site1.local
DocumentRoot /home/u-site1/site1.local/html
CustomLog ${APACHE_LOG_DIR}/site1.local.log combined
ErrorLog ${APACHE_LOG_DIR}/site1.local-error.log
<IfModule itk.c>
AssignUserID u-site1 u-site1
</IfModule>
<Directory "/home/u-site1/site1.local/html">
Options All -Indexes
AllowOverride All
Require all granted
Order allow,deny
allow from all
</Directory>
</VirtualHost>
-- end of content
sudo mkdir -p /home/u-site1/site1.local/html
sudo a2ensite site1.local.conf
sudo vi /home/u-site1/site1.local/html/index.php
-- start of content
site1.local
<?php
$sFilePath = __DIR__ . "/new.file";
$bRes = file_put_contents($sFilePath, "TEST");
if($bRes === false)
echo "<pre>", var_export(error_get_last(), 1), "</pre>";
phpinfo();
-- end of content
sudo chown -R u-site1:u-site1 /home/u-site1/site1.local
sudo chmod 755 /home/u-site1/site1.local
sudo systemctl restart apache2

Virtual hosts not working properly in ubuntu LAMP stack

I have created virtual hosts in the following ways:
Created laravel.test.conf as
- cd /etc/apache2/sites-available
- sudo nano laravel.test.conf
And then updated laravel.test.conf as
<VirtualHost *:80>
ServerName laravel.test
ServerAlias www.laravel.test
ServerAdmin admin#laravel.test
DocumentRoot /var/www/laravel/public
<Directory /var/www/laravel/public/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Run command: sudo a2ensite laravel.test
Permission provided:
sudo chown -R www-data: /var/www/laravel
sudo chown -R $USER:$USER /var/www/laravel
sudo chmod -R 755 /var/www
Added sitename on etc/hosts
127.0.0.1 laravel.test www.laravel.test
Reloaded apache sudo systemctl reload apache2
Run configtest sudo apachectl configtest and received Syntax Ok
Restarted apache server sudo systemctl restart apache2
Now, when I hit larave.test it loads the site successfully, but when ever I tried to hit any other route then it returns 404 error as shown in image.
This app is the freshly installed laravel one with laravel breeze so I am pretty much confident that there is a valide route. On top of that, if it was laravel, error, it would have been log it on app level and there would be different UI for 404 pages.
I have checked error log on laravel/storage/logs as well as apache2 logs on var/log/apache2/error.log but both of these logs file are empty.
Make sure your rewrite mod is enabled.
or simply run this in terminal
$ sudo a2enmod rewrite
$ sudo systemctl reload apache2

Host Laravel on apache tomcat, routes not working properly

I want to host my laravel 5.2 project on apache tomcat server.
I have tried to host my laravel application on tomcat, but my routes are not working, getting 404 not found.
Please follow following steps:
Copy your Laravel Project's root folder to /var/www/html, or clone your
project on this path
Run composer install (You must have composer installed already)
Copy .env file from local environment to you server on project's root directory
Run php artisan key:generate
run chmod -R /var/www/html/{project_dir}/storage
run chmod -R /var/www/html/{project_dir}/bootstrap
run cd /etc/apache2/sites-available
Here you will find nano 000-default.conf file. Open it & change DocumentRoot options like DocumentRoot /var/www/html/{project_dir}/public and save it
Next, Find the apache2.conf located in /etc/apache2
Search for following lines in <Directory />:
Options Indexes FollowSymLinks
AllowOverride All
Require all denied
Change it to this:
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
run sudo a2enmod rewrite
run sudo service apache2 restart

How can I enable moodle?

I've installed postgres for moodle and I got the following instructions:
Apache/mod_php setup
Give full access to the project directory to the process running
apache. You might also have to set the x-flag on all .php files.
$ chmod -R a+rw * Create a 'moodle.vhost.conf' from moodle.vhost.conf.example in project directory. * Create a symlink
from /usr/local/var/moodle to the project directory.
$ cd /usr/local/var; ln -s moodle * Also symlink the new virtual host into apache config dir.
$ cd /private/etc/apache2/other
$ sudo ln -s /moodle.vhost.conf moodle.conf
$ sudo apachectl restart * Create your own custom /etc/vcmoodle/config_local.php file for things local to your
environment by copying, and modifying if required, the example file.
$ sudo mkdir -p /etc/vcmoodle
$ sudo cp /config_local.php.example /etc/vcmoodle/config_local.php
Still it won't work. When I look at my apache root then it comes just the standard apache page and no moodle. I've this sites-available
:/etc/apache2/sites-available$ ls
000-default.conf default-ssl.conf moodle.conf
and the file moodle.conf contents
<VirtualHost *:80>
DocumentRoot "/usr/local/var/moodle"
ServerName moodle.localdev.kth.se
ErrorLog /usr/local/var/moodle/error_log
LogLevel debug
<Directory "/usr/local/var/moodle">
AllowOverride all
Order allow,deny
Allow from 127.0.0.1
</Directory>
</VirtualHost>
But I don't get a moodle page at my web server. What am I doing wrong?
if youre running Ubuntu (judging by the tag), you need to put your project directory inside /var/www. Apache cant access project folders inside your specified directory unless you change the users/groups etc.
what youve tried is the normal apache default location for web folders, but Ubuntu like to change things.

Setup laravel app on digitalocen

I an trying to get my Laravel site running on Digital Ocean. My laravel app is static so no SQL is used and I developed it locally with Homestead.
I can get the site showing the home page on IPaddress /public. It won't link to any pages though. I am guessing it is some rewrite problem I am having. I want to get rid of the /public and get it linking to other pages. Then worry about making it work on a domain
I followed PHPAcademys Cloud Server Set-up tutorial https://www.youtube.com/watch?v=1-ok9d_6xrc
The only difference is I used UBUNTU 14.04 x64. While following the tutorial I found I had a html folder inside /var/www. I needed to put my app within the html folder.
Code setup
sudo apt-get update
sudo apt-get install apache 2
sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt
I didnt use mysql because i dont need it for this app. Its a static site with laravel.
It said mcrypt was needed so I used
sudo php5enmod mcrypt
sudo service apache2 restart
Then I was getting an exception handler error, so i fixed that with
chgrp -R www-data /var/www/html
chmod -R 775 /var/www/html/app/storage
You need to setup an apache2 virtual host
cd /etc/apache2/sites-available
sudo nano myapp.conf
<VirtualHost *:80>
ServerName myapp.com
ServerAlias www.myapp.com
DocumentRoot "/var/www/html/myapp/public"
<Directory "/var/www/html/myapp/public/">
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
exit nano
sudo a2ensite myapp.conf
sudo service apache2 restart
First go to your virtual host file which can be found on
/etc/apache2/sites-available/default.conf
I am not very sure about the path because I have been using nginx for so long. Anyways locate the conf file and change your root directory to something like
/var/www/html/public
rest all looks fine to me if that doesn't work chmod 777 app/storage

Categories