Apache configuration for a simple test page - php

I'm trying to get a handle on Apache configuration files. One of the things I want to do is move some webpages away from the /var/www directory. I have a working configuration in my own pc (name is pc01). There is a webpage I use for tests in /var/www/compile/ and inside there is a single page file: compile.php.
I moved the compile folder to /home/web/compile. And I created this configuration file:
<VirtualHost *:80>
ServerName ctest
DocumentRoot /home/web/compile/
<Directory />
Order Allow,Deny
Options FollowSymLinks
AllowOverride None
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/compile.log combined
</VirtualHost>
As I understand the tutorials I have used if I point my browser to pc01/ctest/compile.php I should see the webpage. However All I get is:
Forbidden
You don't have permission to access /ctest/compile.php on this server.
What am I doing wrong?

You need to set file owner to apache user (user running web server).
Default user for web server is www-data. Try this command in terminal:
chown www-data:www-data /home/web/compile -R

Found it!! The key was to modify the apache2.conf file (/etc/apache2/apache2.conf in Debian) to add another document root other than /var/www. Then it started working. Thanks for the help!

Related

Need some assistance with my apache2 site config file

I'm trying to get apache2 to point to a PHP based application (word press in this case but the config needs to be generic enough to work for any php application).
and it either displays some basic HTML file access page or errors with "You don't have permission". I don't really know apache and I don't know PHP at all. Here's my current site_config file as it stands(with retractions replaced with ):
<VirtualHost *:80>
ServerAdmin <app_user>#localhost
ServerName amazonaws.com/<app_name>
ServerAlias *.amazonaws.com/<app_name>
DocumentRoot /home/<app_user>/<app_location>/staging/current
<Directory /home/<app_user>/<app_location>/staging/current >
AllowOverride All
Options -Indexes
Order allow,deny
Allow from all
</Directory>
LogLevel error
ErrorLog ${APACHE_LOG_DIR}/error.log
</VirtualHost>
I would also like to make it so you can have multiple websites on the same box but I'm not sure how to change the VirtualHost arg *:80 to account for that, I just get loads of ignoring errors.
I also have the following line in my apache2.conf:
DirectoryIndex index.php index.html
Folder permissions are set to 0755 for all files & folders in the project directory
output of apache2 -v:
Server version: Apache/2.4.7 (Ubuntu)
P.s. I know nothing about PHP and very little about apache2 so for this, speak to me as a total noob.
To solve The first problem I had to change the following lines:
Order allow,deny
Allow from all
to:
Require all granted
this finally allowed apache to allow users access to the folders, the second thing was to add an alias:
Alias /<app_name> "/home/<app_user>/<app_location>/staging/current"
and it started working as expected so now my site config looks like:
Alias /<app_name>"/home/<app_user>/<app_name>/<app_environment>/current"
<Directory "/<app_name>"/home/<app_user>/<app_name>/<app_environment>/current">
AllowOverride All
Options -Indexes
Require all granted
</Directory>
<VirtualHost *:80>
DocumentRoot "/<app_name>"/home/<app_user>/<app_name>/<app_environment>/current"
ErrorLog "/var/log/apache2/<app_name>.error_log"
CustomLog "/var/log/apache2/<app_name>.access_log" combined
</VirtualHost>

apache virtual host with laravel 5 "Internal error 500"

I want to learn laravel, and recently installed a fresh copy laravel on an amazon ec2 instance through composer composer create-project laravel/laravel laravel-app with apache2, and php installed. I configure the conf.d file to change the document root to laravel-folder/public, when i try to go to the public ip address it show a server 500 error.
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#elastic IP address
ServerName 42.66.33.52
ServerAdmin webmaster#localhost
DocumentRoot laravel-app/public
<Directory laravel-app/public>
DirectoryIndex index.php
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
I've tried chmod 777 to the entire laravel folder and changed the url in app.php to 42.66.33.52, and it still showing the same error. I'm new to laravel, and I hope someone can point me to the right direction. I've host other PHP website from this server without using laravel framework and it is function normally.
You should chmod -R 775 on /storage folder and all files in it.
as #Alexey Mezenin said, you should change the chmod of storage and all files inside by -R, and also don't forget to do the same with the bootstrap/cache folder. Check that on "Directory Permissions" in the official laravel documentation installation :
https://laravel.com/docs/5.3/installation
hope that help ;) Regards.

How to setup Apache for Phalcon PHP INVO demo application?

I would like to run INVO https://github.com/phalcon/invo but I can't figure out how to setup Apache to serve its content. After cloning github repo, I got 2 .htaccess files, one in project's root and other in public subdirectory.
This is my Apache config (/etc/apache2/sites-available/010-invo.conf)
<VirtualHost *:80>
ServerName invo.l
ServerAlias www.invo.l
ServerAdmin webmaster#localhost
DocumentRoot /workspace/invo
<Directory /workspace/invo>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog /workspace/invo/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /workspace/invo/access.log combined
</VirtualHost>
With this configuration I can't get HTML links to work properly - all CSS and JS files are not loaded (they have paths begining with invo) but app is served from the root of local domain (http://invo.l).
What is wrong with my config?
Ok, I just nested cloned github project into another directory (invo). Now it's /workspace/invo/invo - and it is working
In the default invo installation the basePath is /invo/ so when you installed that second invo in a subdirectory you just got lucky.
The trick is to find out why you got lucky.
Can you open up config/config.php and see if you can explain that for yourself. Does that contain a reference to invo?
Also check the .htaccess in /public does that contain a reference to invo?

Error web debug toolbar

I have recently upgraded the Ubuntu OS (10.04 -> 12.04) in my development workstation, and know I'm getting trouble in running the project I'm working on. I think it's some permission related problem. The fact is that I already have it running with no problems in a production server.
Is there any tool I can check project's folder permissions for errors, more or less like "symfony project:permissions" in Symfony 1 ?
I'm getting a css troubled first page in my dev frontend and a JS alert that reads:
An error occurred while loading the web debug toolbar (404: Not Found). Do you want to open the profiler?
The web folder .htacess is the same from the working production environment and I have an apache configuration equal to production only with ssl disabled.
Edit:
Virtual Host configuration:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
#<Directory />
# Options FollowSymLinks
# AllowOverride None
#</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
AcceptPathInfo On
Order allow,deny
allow from all
</Directory>
Alias /myproject /home/nelson/des/php/myproject/Symfony/web
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel debug
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
The "AcceptPathInfo On" was included in an attempt to solve. I already tried with and without it.
Any help apreciated
It seems that you haven't published your assets (css, js, images...)
Try the following from command line in the root folder of Symfony :
php app/console assets:install web/ --symlink
Also, check that the rewrite mod is enabled : a2enmod rewrite
EDIT: Given your VirtualHost config file, it seems that you gave the wrong folder to Apache. You configuration must point to the web folder of Symfony2. For example :
<VirtualHost *:80>
DocumentRoot /home/myuser/www/Symfony/web
<Directory /home/myuser/www/Symfony/web>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
#......
</VirtualHost>

Symfony 2.3 production mode urls not resolving

I have just gone through the Symblog tutorials on http://tutorial.symblog.co.uk/docs/customising-the-view-more-with-twig.html
In prod mode, if i access the url like so:
http://local.mysite.co.uk
I get the home page with links to all the blog posts.
However if i click one of the blog posts then I get a 404, in fact any of the links (to the about or contact) all return a 404, eg:
http://local.mysite.co.uk/12/a-day-with-symfony2
If I then access the prod mode via the app_dev.php all the links work again, ie:
http://local.mysite.co.uk/app.php/12/a-day-with-symfony2
I have run to ensure the mod rewrites should be working and restarted apache but no joy.
sudo a2enmod actions
Does anyone know why this might be happening?
Thanks,
John
PS: This is the current vhost file for the dev site i am learning with (Ubuntu lts, apache 2.4, php 5.4ish)
<virtualhost *:80>
# Admin email, Server Name (domain name) and any aliases
ServerAdmin webmaster#domain.com
ServerName mysite.co.uk
ServerAlias www.mysite.co.uk
ServerAlias local.mysite.co.uk
# Index file and Document Root (where the public files are located)
DirectoryIndex app.php
DocumentRoot /var/webroot/www/vhosts/mysite.co.uk/htdocs/Symfony/web/
# Custom log file locations
LogLevel warn
ErrorLog /var/webroot/www/vhosts/mysite.co.uk/log/error.log
CustomLog /var/webroot/www/vhosts/mysite.co.uk/log/access.log combined
</virtualhost>
When I add an AllowOverride All to the vhost file and restart apache I get the follwoing error:
* Starting web server apache2
*
* The apache2 configtest failed.
Output of config test was:
AH00526: Syntax error on line 15 of /etc/apache2/sites-enabled/mysite.co.uk.conf:
AllowOverride not allowed here
Action 'configtest' failed.
The Apache error log may have more information.
Altering the vhost worked (thanks to https://stackoverflow.com/users/308825/maerlyn).
Placing a directory tag with the Allowoverride All fixed the issue. Seems that the rewrites are specific to each vhost.
Here is my config for the symfony tutorial which is now functioning in prod mode:
<directory /var/webroot/www/vhosts/mysite.co.uk/htdocs/Symfony/web/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</directory>
<virtualhost *:80>
# Admin email, Server Name (domain name) and any aliases
ServerAdmin webmaster#domain.com
ServerName mysite.co.uk
ServerAlias www.mysite.co.uk
ServerAlias local.mysite.co.uk
# Index file and Document Root (where the public files are located)
DirectoryIndex app.php
DocumentRoot /var/webroot/www/vhosts/mysite.co.uk/htdocs/Symfony/web/
# Custom log file locations
LogLevel warn
ErrorLog /var/webroot/www/vhosts/mysite.co.uk/log/error.log
CustomLog /var/webroot/www/vhosts/mysite.co.uk/log/access.log combined
</virtualhost>

Categories