Deploy Symfony 2.7 on shared hosting without SSH - php

Good day friends,
I know that similar questions exist for deploying a Symfony 2.7 application on shared hosting with CPanel. But in my case I do not have access to SSH. Therefore installing via Composer is out of question.
To work around it I have copied the entire sources into a sub folder in "public_html" folder. When I try to configure Symfony using "web/config.php" it gives some pre-requisites issues. To resolve this I have copied custom "php.ini" in my sub folder and also added the ".htaccess" file to root of "home/user" with following content
SetEnv PHPRC /home/user/public_html/subfolder/php.ini
But still the setting is not taking affect. Do i need to ask the hosting provider to restart the web server ? this wont be easy since it is shared hosting.
Please suggest any alternative way

Your custom .htaccess is not used by the application.
Try to add the SetEnv in the public_html/web/.htaccess that is used to browse your application.
If this has no effect, a working way is to add the following in the VirtualHost of your application:
<VirtualHost *:80>
PHPINIDir /home/user/public_html/subfolder/php.ini
</VirtualHost>
But that involves to restart apache once.
EDIT
If PHP run as CGI:
Create a wrapper script called phpini.cgi to export the directory that contains the php.ini file as PHPRC.
#!/bin/sh
export PHPRC=/home/user/public_html/subfolder
exec /path/to/cgi-bin/php5.cgi
In your /home/user/public_html/web/.htaccess add the following lines:
AddHandler php-cgi .php
Action php-cgi /cgi-bin/phpini.cgi
If php run as CGI with wrapper (for FASTCGI):
You should already have the following wrapper script:
#!/bin/sh
export PHP_FCGI_CHILDREN=3
exec /path/to/cgi-bin/php5.cgi
Change it to:
#!/bin/sh
export PHP_FCGI_CHILDREN=3
exec /path/to/cgi-bin/php.cgi -c /home/user/public_html/subfolder/php.ini
More informations and alternatives in the source.
I hope this solves your problem, it should if you are sure you are php run as cgi/fast-cgi.

Related

Shifting from App Services to a Docker container due to file persistence?

While connected to my App Service (vanilla PHP 7.4 App Service) through SSH, I can see:
Note: Any data outside '/home' is not persisted
If my php.ini and apache2.conf reside outside of /home, I'll never be able to have changes to these files persisted correct? IIRC, I can't modify apache2.conf to set another location for php.ini within /home, the Apache configuration change will never persist the Apache restart.
This only means that I need to build a docker container to have full control of my settings? Am I understanding this correctly?
Thank you #CSharpRocks posting your suggestion as an answer to help other community members for similar issue.
Based on the MS DOC:
To Customize PHP_INI_SYSTEM directives we can't use the _.htaccess_ approach. App Service provides a separate mechanism using the PHP_INI_SCAN_DIR app setting. First, run the
following command in the Cloud Shell to add an app setting called
PHP_INI_SCAN_DIR .
az webapp config appsettings set --name <app-name> --resource-group <resource-group-name> --settings PHP_INI_SCAN_DIR="/usr/local/etc/php/conf.d:/home/site/ini"
For example if want to change the value of expose_php run
the following commands:
cd /home/site
mkdir ini
echo "expose_php = Off" >> ini/setting.ini
For more information please refer this SO THREAD

Heroku Apache, Parse HTML also as 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.

Laravel setup on HostGator shared plan

I'm trying to setup Laravel on a HostGator shared plan. I've followed these instructions:
http://laravel.io/forum/02-13-2014-how-to-install-laravel-on-a-hostgator-shared-server
I created and uploaded the .bashrc and .bash_profile files as instructed, then I run:
source ~/.bashrc
in the terminal, but then when I run php -v I get
No such file or directoryphp
I also tried uploading an htaccess file with AddHandler application/x-httpd-php55 .php to the root directory. When I run phpinfo() now, it shows php version 5.5.10, but php -v (before I run the source command) still shows version 5.2.17.
Any idea what I'm doing wrong?
STEP 1 Copy your files
Copy your app in a non-public folder, example:
/home/foo/myapp
Move your public folder to a public folder, example:
/home/foo/public_html/public
Open your public/index.php file and change paths to reference your laravel non-public code, example:
require __DIR__.'/../../../myapp/bootstrap/autoload.php';
$app = require_once __DIR__.'/../../../myapp/bootstrap/app.php';
STEP 2 Change php version in Cpanel
For laravel 5.2 you need at least php 5.5
https://laravel.com/docs/5.2/installation#server-requirements
this will add some lines in your .htaccess, for example, this will enable php7:
# Use PHP70 as default
AddHandler application/x-httpd-php70 .php
<IfModule mod_suphp.c>
suPHP_ConfigPath /opt/php70/lib
</IfModule>
STEP 3 Make artisan work
php command line may not work, run this command to check php version:
php -v
if it doesn't give you the correct version you may run your commands directly with php 5.6 binary, like this:
/opt/php56/bin/php artisan
STEP 4 clear caches
Sometimes you need to clear your cache, there's two ways:
With artisan:
/opt/php56/bin/php artisan optimize
Manually:
Delete this two files
bootstrap/cache/compiled.php
bootstrap/cache/services.json
How to use SSL
Hostgator shared servers have a shared SSL certificate
To use the shared SSL certificate you must access your public folder by the root of your server and your username like this:
https://gator1234.hostgator.com/~username
So for example, if you put your application in a folder called myapp it will become:
https://gator1234.hostgator.com/~username/myapp
this will mess the routes file, so you have to add this lines to your .htaccess
RewriteEngine On
RewriteBase /~username/myapp
I recently wrote an article on how I was able to host my laravel 5.5 on a shared host. (Hostgator)
https://www.5balloons.info/hosting-laravel-5-5-project-on-shared-hosting-hostgator/
So there is one simple step that seems to get overlooked with most of the issues of setting up a subdomain to host a Laravel App using HostGator's Shared Hosting plan.
HostGator Shared Server Hosting Plan
Scenario:
Domain: https://yardpenalty.com is pointing to the home/username/public_html folder which has a WordPress installation.
Subdomain: https://games.yardpenalty.com is pointing to the home/username/games/public folder which has a Laravel App installation.
Problem:
We want the Laravel App to be accessed at the Subdomain's root level...
URI at https://games.yardpenalty.com
NOT at https://games.yardpenalty.com/public.
Solution:
Step 1:
Under our HostGator Shared Server Hosting Plan we can access the tools we need using cPanel.
Step 2:
In our cPanel we go-to Domains->Subdomains and we enter a name for our Subdomain (in this instance its called games).
Step 3:
Then we select a Domain from the dropdown list and in this scenario it is yardpenalty.com which is pointing to my public_html folder.
Step 4:
Finally, under the Document Root / (a.k.a. home/user) we point it to the /games/public folder!
It should look something like the second listing from your cPanel:
I was finally able to get Laravel installed with some help from this:
http://shincoding.com/laravel/installing-configuring-laravel-shared-hosting/

PHP Apache Config on linux

I'm using Apache 2 in Linux mint and I don't know where to store my files and projects. if I store it in var/www it is not accessible for me, I have to use command as super user. Are there any way to solve my problem?
- If I want to store in my home folder, what should I type in the address bar if I want to run my file?
- Are there any other good solution than these? (such as change the accessible to folder /var, or change the Root_Url of apache ...)
The easiest way to solve this provlem is by typing the following line in terminal:
sudo chmod -R 777 /var/www
and then enter your password. And now you are done. You can store all the PHP files in /var/www
You have to do a chmod, you can have more information in your terminal with comand man chmod to set the rights to write in that folder or else point the web-server elsewhere (the setting is in the https.conf file)
There is different solutions:
create a symlink from /var/www/link to your projet and set your project
create a virtualhost with the DocumentRoot to point to your project: http://httpd.apache.org/docs/2.2/vhosts/examples.html
in both cases your project must have gives permissions to the apache user (www-data?) to read/execute you project
You need to active the user_dir mod of apache and then run the content from your home folder.
To run a file in your hole directory you should go to localhost/~youruser/script.php of course after enabling user_dir
Everything depends on the use.
If you are looking for a configuration for a development server that is accessible only from limited host (such as localhost):
You can configure Apache (/etc/apache2/apache2.conf) to run with your user/group.
User myuser
Group mygroup
Store all your project in your user_dir (/home/myuser/projects/...)
Create a virtual host for any of your projects
All files generated by your server will be accessible to you and vice versa
One way to accomplish this is to edit the default virtualhost supplied with Apache 2. In Linux Mint 14 its configuration file is located at:
/etc/apache2/sites-enabled/
This directory should hold symlinks for all active sites, for me the default is named 000-default.
Change the lines with "DocumentRoot" and "Directory" to point wherever you like. The server should have read only privileges by default. If you are working on file manipulation then it will need permission to read and write files.
Once this is set, restart the server ("sudo service apache2 restart") and type localhost in your browser to access the directory you've set above.
For more advanced configs have a look at:
http://community.linuxmint.com/tutorial/view/853
http://community.linuxmint.com/tutorial/view/527

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

Categories