Heroku Apache, Parse HTML also as PHP - php

How can I modify .htaccess and httpd.conf in Heroku? I connected it with a repository on Github.
In Github I've tried multiple things, those all don't work. Putting httpd.conf in a folder called /conf/httpd/default.conf didn't work, not sure not even in the repo root it worked, when I tried to put httpd.conf and .htaccess in there, nothing ever happens and I'm not sure why.
I am using the apache2 buildpack from Heroku that is inside a Procfile heroku-php-apache2
I am trying to tell the httpd.conf to parse .html also with php, so I can include things in it.
There is that thing on Github https://github.com/heroku/heroku-buildpack-php not sure if that can help.
Update:
Apperantly when using -c httpd.conf to tell where the httpd.conf is, it started recognising it and using it, what I get now is this:
no listening sockets available, shutting down
Update:
I used -C httpd.conf and it included it now, the problem is
The changes I want to make do not really apply. I'm trying to parse HTML also as PHP.

I just ended up using PHP.
You could try it with a custom buildpack but I don't know how to make one so it can actually use it's own httpd.conf and not the one from the heroku php buildpack.

Related

.htaccess file is not read in linux

I have a .htaccess file in a php project, I have the apache2 server downloaded and running, but it ignores my project's .htaccess.
When I test the project on Windows or put it on my hosting it works normally.
I already tried to edit the apache2.conf file, among several other methods that I found to solve, and nothing worked, the project worked correctly on the computer of my friends who have linux.
I start the project with the command php -S localhost: 1990 inside the folder that has my files, I tried other ways and nothing worked.
Can someone help me? I've been looking for a long time and nothing has resolved.
I apologize for my English, I'm Brazilian and I still can't speak English very well.
I start the project with the command php -S localhost: 1990
This uses the webserver built-in to PHP, not Apache. Consequently, this does not use a .htaccess file (or apache2.conf).
You need to call your PHP files through Apache - which you say is already "running". (?)
(Aside: There should be no space between localhost: and 1990.)
Reference:
https://www.php.net/manual/en/features.commandline.webserver.php

PhP Cake app in Apache2 in Ubunutu not working but working find in window's wamp

I have a web application that is writen in php using cake framework. In windows environment i use wamp and it works find if i enbale apache read_write. Then I shift to use Linux environment Ubuntu 15. I have installed apache2 already and php too. it is all work. But when I put my app in /var/www in ubuntu and open the web page it said that the require_once function cannot file the location of the file.
I already change the owner of the www/* to www-data already, but it is still not work. mod_readwrite of apache is also enabled. So I want to know how could I enable read_write in Lamp like in wamp that I did on window? I met the same error in window if I don't enable it. So think it is the problem. Can anyone help me to solve this problem?
One thing you will want to check for is that you're using the proper directory separator in any paths you're using for your require statements (this can be done by using the DIRECTORY_SEPARATOR constant in place of hard coded slashes in your paths)
Another thing you will want to do is look at the apache configuration for each environment and ensure that they are the same. In particular check to ensure that your virtual hosts are defined correctly.

Getting Cakephp to work on a Debian server, but I'm having a missing controller error at the root

I've been trying to get a cakePHP app to run on a Debian Server. It works find on localhost, using WAMP. At first I had issues with the rewrite not working. So I attempted to fix that by changing the owner of some of the folders to www-data, from root, as I read in other places on the internet that that would help. I changed the root of the cakephp app to www-data, and everything under that to www-data (recursively). But this still did not fix it.
So I went to instructions for if you can't get url rewriting working, by doing the following...
So I found some other instructions that said to get rid of the ./htaccess, /app/.htaccess and /app/webroot/.htaccess files, which I did.
And I uncommented the following lines in my cakephp folder:
Configure::write('App.baseUrl', env('SCRIPT_NAME'));
Configure::write('App.fullBaseUrl', env('SCRIPT_NAME'));
Configure::write('App.imageBaseUrl', 'img/');
Configure::write('App.cssBaseUrl', 'css/');
Configure::write('App.jsBaseUrl', 'js/');
Now I'm getting this error:
Missing Controller
Error: CakeController could not be found.
Error: Create the class CakeController below in file: app/Controller/CakeController.php
<?php
class CakeController extends AppController {
}
Notice: If you want to customize this error message, create app/View/Errors/missing_controller.ctp
Stack Trace
APP/webroot/index.php line 108 → Dispatcher->dispatch(CakeRequest, CakeResponse)
ROOT/index.php line 41 → require(string)
I think I have to change the App.baseUrl or the App.fullBaseUrl, to something else, but I am not sure to what.
The root of the application is in / <root>/home/webdev/webroot/Cake, and the public domain is located in / <root>/home/webdev/webroot. I think that info may be relevant to solving the problem.
Any help would be much appreciated. Thankyou
You seem to be lacking basic knowledge of setting up the server which leads me to think that you might have mixed up lots of different "workarounds" in your way of trying to make it work, such that it might be too difficult to fix it now through this.
If you have root access to the debian server I assume you're talking about a VPS you own. Then you most probably can reset it to a fresh install and start over.
So first things first:
You're developing on windows and will be serving your app on unix (linux). Beware windows is case insensitive and unix is not, if you don't follow conventions you'll definitely end up with this issue at some point (i.e. webroot/Cake or webroot/cake are the same thing to windows but different on unix).
By default you can't have Apache serve files from from user home folders (/home/user/...) but from /var/www. If you want it the first way you need to set it up properly, which would mean to know how to create an apache site config file and/or messing with apache's main config file. I would leave that for later if I were you.
The folder/files in any folder that Apache must serve need to be accessible/readable by www-data user or group. Exception is the application's tmp folder that need to also be writable by the same user or group. If you put them on /var/www/app you can chown www-data:www-data /var/www/app -Rwhich will save you lots of time in your way to make things work at first.
By default Apache doesn't come with rewrite enabled. You need to a2enable rewrite && service apache2 restart. You will also need to check the directive AllowOverride" in /etc/apache2/sites-available/000-default.conf under directory /var/www/ to make sure it is set to AllowOverride All. If not amend and restart apache.
If you apply the above you should be able to properly access your app under http://server_name/app and follow on from there.

Apache webserver subdirectories not loading

I am trying to setup a basic apache 2 webserver just for testing purposes. I have apache 2 installed on Ubuntu 11.10. I can access the root directory on the webserver just fine by going to "localhost" in my browser. This is all located in the default directory: /var/www. However, the problem starts whenever I try to access the subdirectories of my webserver. So, for example if I goto "localhost/phpproject/", which has an index.php file listed in it (and I did test to make sure PHP was working correctly), all it seems to want to do in my browser is attempt to download a file when I type in the address instead of actually displaying anything.
I even tried to give full permissions on the subdirectory to make sure it wasn't just a permissions-related problem. Any ideas?
First of all, you shouldn't be keeping your development files in /var/www folder. Configure your apache to keep your web files within your home directory. In doing so, you don't have to have sudo privilege to edit files in /var/www. If you want to follow my setup, create a directory called www in your home folder /home/yourname/www. Look at my config of /etc/apache2/sites-enabled/000-default
http://pastebin.com/3gcE59Lh
It works good for me.
If you change your config like this, make sure to restart apache [sudo service apache2 restart]
Make sure that you installed PHP correctly and registered PHP in your Apache configuration.
This is the key here, it looks like it's sending you the index.php file, test a PHP file in the main folder behind this sub-directory and see if it tries to download it.
File Could just be:
<?php
phpinfo();
See if putting that in index.php in the parent folder gives you a phpinfo page or tries to download index.php.
If it tries to download it it's just that PHP is not configured in apache to handle files that end in .php
To configure it, add the following lines to your httpd.conf file
LoadModule php4_module modules/libphp4.so
#
# Cause the PHP interpreter handle files with a .php extension.
#
<Files *.php>
SetOutputFilter PHP
SetInputFilter PHP
LimitRequestBody 9524288
</Files>
AddType application/x-httpd-php .php
Make sure that you installed PHP correctly and registered PHP in your apache configuration.
The manual should explain the required installation steps in detail.
in Ubuntu you should install the LAMP option using tasksel at the CL. That will give you Apache, MySQL and PHP all working together. It sounds like you may have installed them separatley and have not configured PHP correctly. mime types determine the servers handling of specific file types.
apesa#ubunt$ sudo tasksel
Follow the prompts
EDIT:
We used to make all the config changes in httpd.conf. If you used package manager, like you did then you will have a distributed configuration environment. You will need to go to etc/apache2/mods enabled and look in the php.conf file. There are directions inside. It sounds like you need to make sure the web server understands the directories and FS locations. Look at #Chrispy example. You won't be using the first line as the php module in your env are loaded via php.load and the config is done in php.conf. That AddType directive is important and tells the server to exec your file instead of serving it. have a look. BTW, the Apache Project supports one of the best listservers out there at URL:http://httpd.apache.org/userslist.html

HTML recognizes my PHP code as comments

I want to create a Chrome app, but I have the same problem as this guy. When I add the .php extension and I run the app, it downloads the file.Should I do something more? I have installed PHP (if that means to download and extract the file in the same folder with my app, I'd be wrong). I'm a beginner... :(
EDIT
Some of you told me to install Apache or IIS. I said earlier that I want to create a Chrome app.
Do I need to install Apache? Where would I run it (I don't have a local host, Chrome extensions and apps use the "chrome-extension://" prefix, which means it is hosted on the browser). What about more information (you've all been helpful by now)?
EDIT 2
It turns out that Google Chrome doesn't allow developers toto run PHP inside Chrome apps.
Thanks for your help!
This means the server is either missing the PHP plugin (either CGI or otherwise) or the the server doesn't recognize that it must pass a file with the extension in to PHP for pre-processing.
If you're on a host out of your control (e.g. using GoDaddy) then make sure they allow PHP (some of the free hosts won't have PHP as they deam it an unnecessary security risk). If it's your own server, make sure you installed PHP and it's enabled.
If it DOES has PHP installed, but you're not getting it to parse, you'll need to bind the .php extension to the PHP handler using either an .htaccess file or the config.
For apache, your http.conf needs the following (assuming you already have PHP plugin):
AddType application/x-httpd-php .php
Or for something more broad, place an .htaccess file with the above code in your hosted directory.
EDIT
You mentioned you installed PHP. I'm going to assume you're using Apache, as IIS now has a Web Extensions installer that would (typically) take care of the "hard part" for you. So, having said that, open your http.conf (Usually located in C:\Program Files\Apache Software Foundation\Apache2.2\conf\ [using 2.2 as a demo version]). Within that file, at the bottom, add the following [replacing files paths to those that correlate to your own install]:
LoadModule php5_module "C:/php/php5apache2_2.dll"
AddType application/x-httpd-php .php
PHPIniDir "C:/php"
A better reference can be found by googling "install PHP [version] on [webserver]". Here's just one of the results I was able to locate.
Do you have a server installed on your machine? PHP is a server-side script & unlike Javascript you cannot run it without a server.
PHP files are server side code only. So you need to install a local server like APACHE to get the PHP script to execute.
PHP must be run on a web server, not your desktop. Install PHP on your webserver, then open the PHP file from a web browser via: http://localhost/yourfile.php
You need an Apache server on your computer. download xampp: http://www.apachefriends.org/en/xampp.html and put your files in the htdocs folder.
EDIT:
This will explain how to install a PHP environment: http://www.tanguay.info/web2008/tutorial.php?idCode=phpDevelopmentQuick

Categories