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

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

Related

Symfony command php bin/console can't read Apache SetEnv?

With Symfony 5.2, when I execute this command
APP_ENV=prod php bin/console d:m:m
I have this message :
WARNING! You are about to execute a migration in database "db_name" that could ...
However, in my Apache environment variables, I customized the database name :
SetEnv DATABASE_URL "mysql://website:password#localhost:3306/website_prod"
I am sure that this configuration works (when I access the site, I am in the prod environment while I left dev in the .env generated by Symfony).
Why is the wrong database displayed on the APP_ENV=prod php bin/console d:m:m command line? I think Apache variables are not taken into account in php bin / console ... command line and I need to create a specific .env.prod.local.
Can you confirme ? If yes, I don't see why Symfony mentions this in their documentation (https://symfony.com/doc/current/setup/web_server_configuration.html#apache-with-mod-php-php-cgi)
Console commands do not run under the web-server, hence they do not have access to whatever configuration you have for the Apache vhost or anything like that.
The best way to deal with this kind of configuration is storing this values in environment variable, .env files, or use Symfony's secret management features.
This way this configuration will be available both to the application when accessed via the webserver or through a command line script.

Deploy Symfony 2.7 on shared hosting without SSH

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.

Joomla 3.4.3 - configuration.php not writable

Using MariaDB, Apache, PHP 5.4.x, RHEL 7
How do I allow configuration.php to be written to?
Installed Joomla several times, always ending up with the configuration.php file not writable. I proceeded, copied the config content and created a new php file, placed it where Joomla lives, opened up the permissions, changed to apache:apache, still nothing. I've referenced several articles, notably this one:
Installing Joomla 3 Error: Your configuration file or directory is not writable
I have also tried creating an empty configuration.php file and placing it in the joomla root, opening up permissions - didnt work.
My current state of installation is configuration.php file in place, but unable to remove the installation directory via the web installer (assuming because I shoehorned the config file into place and still not being writable).
I've tried several permissions setups then attempting to remove the install directory without success. Manually removing the install directory via rm -r only yields a totally inaccessible site forcing me to wipe my joomla files, databases, and install again. Thanks in advance.
The first thing I would do is check what user php runs at on your server, and compare this with ownership of your site files.
Create user.php file at the root of your domain with
<?php echo exec('whoami'); ?>
then open that file with your broser. This will give you the name of the user that php runs as on your server. It may be apache but it may not.
Compare this user with the ownership of config.php and your site installation as a whole.
If you upload a new Joomla site via SFTP and follow the standard browser instal steps, permissions shouldn't be a problem. If you are say uploading a zip file and using a terminal connection and SSH, make sure your SSH connection is the same user as the php user on your server.
Good luck!
Working with my server guy - found out that several sebool settings were keeping Apache from doing what it needed to do. Going one step further, we identified that sebool commands needed to be ran to allow httpd_can_sendmail in order to use the Sendmail feature. Hope this helps someone out there.
The command that seemed to do the trick was sudo chcon -R -t httpd_sys_rw_content_t /var/www/html
In our case, problem was with CentOS permissions. So if Joomla is installed on CentOS powered server, you need to change config file (/etc/selinux/config) to look like this:
[root#host2a ~]# cat /etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - SELinux is fully disabled.
SELINUX=permissive
# SELINUXTYPE= type of policy in use. Possible values are:
# targeted - Only targeted network daemons are protected.
# strict - Full SELinux protection.
SELINUXTYPE=targeted
# SETLOCALDEFS= Check local definition changes
SETLOCALDEFS=0
Actually, you only set SELINUX to permissive.
Hope this helps.
p.s. Solution works for RedHat too.

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

reinitialize system wide environment variable in linux

I just want my apache to register some of my predefined environment so that i can retrieve it using getenv function in php. How can i do this? I tried adding /etc/profile.d/foo.sh with export FOO=/bar/baz using root and restarted apache.
Environment variables are inherited by processes in Unix. The files in /etc/profile.d are only executed (in the current shell, not in a subshell) when you log in. Just changing the value there and then restarting a process will not update the environment.
Possible Fixes:
log out/log in, then start apache
source the file: # . /etc/profile.d/foo.sh, then restart apache
source the file in the apache init script
You also need to make sure that /etc/profile.d/ is sourced when Apache is started by init rather than yourself.
The best fix might also depend on the distribution you are using, because they use different schemes for configuration.
You can use SetEnv in your config files (/etc/httpd/conf.d/*.conf, .htaccess ...). Additionally you should be able to define them in /etc/sysconfig/httpd (on RPM-based distribs) and export them (note: not tested).
Note: it wouldn't surprise me if some distributions tried quite hard to hide as much as possible, as far as system config is concerned, from a publically accessible service such as Apache. And if they don't, they might start doing this in a future version. Hence I advise you to do this explicitly. If you need to share such a setting between Apache and your shells, you could try sourcing /etc/profile.d/yourprofile.sh from /etc/sysconfig/httpd
Apache config files allow you to set environment variables on a per site basis.
So if your web server is serving pages from two logical sites you can have the same environment variable set differently for each site and thus get your PHP to react differently.
See the Apache mod_env for details:
If you need env vars for Apache only, what worked for me was editing the /etc/apache2/envvars and restart of Apache. I added these settings:
export LANG='en_US.UTF-8'
export LC_ALL='en_US.UTF-8'

Categories