I have made a Laravel command that I try to run with a cronjob every minute.
In the command there is some logic that does a soap call. When I run the command through a route that I created everything works fine.
like this:
Route::get('test-command', function() {
Artisan::call('updateRegisterLogs');
});
Now when I try to do the same thing in my command on the server like this:
php artisan updateRegisterLogs
I get the following error:
Class 'SoapClient' not found
Now I searched on the internet and in my php.ini I removed the ; before extension=php_soap.dll and before extension=php_openssl.dll and I've restarted my apache and unfortunately I get the same error.
I am now sure what is going wrong here since my code works but not when executed with artian.
Usually php has various php.ini configuration files, typically located on paths like, /etc/php/7.2/cli/php.ini or /etc/php/7.2/fpm/php.ini so from the problem you are having my guess is that you have uncommented the extension on one of those config files but not the cli path one.
If you have for example the application being served using nginx and phpfpm the php.ini file that will determine what modules are enabled when executing php for those requests will be the one located at /etc/php/7.2/fpm/php.ini. When you execute artisan commands the "selected" config file is the one at /etc/php/7.2/cli/php.init
Related
I have installed yii2 and I have tried to run using the PHP built in server using ./yii serve. When I open http://localhost:8080 I got the following permission error:
PHP Warning – yii\base\ErrorException session_start():
open(/var/lib/php/sessions/sess_t1462ivbhhq79igqjp6b4fekth, O_RDWR)
failed: Permission denied (13)
On other application on the same machine that it run on Apache, I fired up phpinfo() and I found that path /var/lib/php/sessions is set to session.save_path.
To work around the permission issue, I have tried to run sudo ./yii serve and it worked fine.
Now, I care about the security of my development system, where, occasionally, I expose it to the Internet to serve my clients visits to the currently developed apps. I don't know weather I keep running the app using sudo or is there a better way to change /var/lib/php/sessions permissions to allow php from the cli, php -S, to access it?
I have done the following to change the save session path to another accessible path by PHP cli:
From the terminal php --ini to get a list of configurations files and I meant by Loaded Configuration File entry to specify the path of the loaded php.ini file. In my case it is /etc/php/7.2/cli/php.ini.
Using any text editor that could be run as sudo, in my case I used kate, I opened the specified php.ini file and I search for: session.save_path entry of the php.ini and I uncommented it then change the path to a path in my home. In my case I set it to be /home/myuser/tmp/sessions. Save the file.
Now ./yii serve works fine without need to sudo and without need to change any settings of the php.ini for Apache.
I have created a cron job with Laravel. The problem is I am using file_get_contents in it and when I run the job, there is an error:
file_get_contents(): https:// wrapper is disabled in the server configuration by allow_url_fopen=0
I know that in the command I need to specify and the local php.ini file, where allow_url_open is enabled.
I am using shared hosting, where in global php.ini file this property is disabled, but in my local is enabled. When I run the job it uses global php.ini.
I am running the job in SSH: - php artisan my_command.
I need to run it and manually in the code, too, like:
Artisan::call('my_command');
I have created the command with:
php artisan make:command MyCommand
Then in handle method, I am using file_get_contents.
How to speecify the php.ini file when I run a Task with Laravel 5.8 ?
EDIT:
On the hosting, this option is enabled and I can use it in my code.
If I run phpinfo(), I see that is enabled, too, because, it is used local php.ini.
The solution wasto make an alias to my php.ini file.
This file is located in:
/home/<USERNAME>/php73-fcgi.ini
Global php.ini file location:
/opt/cpanel/ea-php73/root/usr/bin/php
The command that I have executed in SSH:
alias php='/opt/cpanel/ea-php73/root/usr/bin/php -c /opt/cpanel/ea-php73/root/usr/bin/php -c /home/<USERNAME>/php73-fcgi.ini'
73 is the version of PHP.
I am trying to install Symfony 2.7 as instructed by the manual.
When I open CMD (I am running it as an administrator in Windows 8.1) the default path is C:\Windows\System32. I have tried running the command specified in the documentation there (c:\> php -r "readfile('http://symfony.com/installer');" > symfony), as well as in the root directory, both give me the same error.
I am using WAMP, the appache rewrite module and php_xls are activated.
I've also added the following to the PATH in the environment variables: ;C:\wamp\bin\php\php5.2.5;C:\wamp\bin\mysql\mysql5.0.45\bin
After having added it, I rebooted the computer and still nothing worked. How can I install Symfony 2.7?
Here is the solution to your original problem:
You just have to make sure that the path to your php executable is correct when you add it to your PATH environment variable. This path is probably related to the version of PHP you have. You should be able to find this path by navigating inside your wamp installation and looking for the php folder and binary. In your case, this would be C:\wamp\bin\php\php5.5.12
However, for the new problem you have...
However, I get the error The directory name is invalid when I execute
the following command: c:>projects\ php symfony
You just have to make sure that your PATH is updated with the correct path for your php, and then do this from C:>
php projects\symfony
Note that php is the executable and projects\symfony is the path to the symfony file.
I have been able to setup my laravel but everytime i try executing an artisan command on the command line i get this error
"unable to load dynamic library. " C:/wamp/bin/php/php5.4.12/ext/php_mcrypt.dll" - the specified module could not be found
From phpinfo() it is said that mcrypt is enabled
I have tried
adding "extension=php_mcrypt.dll" to my php.ini file as suggested on similar questions but it did not work
what can i do to solve this problem ?
Its because your PHP CLI is runing a different config to your PHP which your web server is running.
You need to update both php.ini files to load php_mcrypt.
/etc/php5/apache2/php.ini
apache2/php.ini
and maybe
cli/php.ini
How can I run a PHP script from the command line using the PHP interpreter which is used to parse web scripts?
I have a phpinfo.php file which is accessed from the web shows that German is installed. However, if I run the phpinfo.php from the command line using - php phpinfo.php and grep for German, I don't find it. So both PHP files are different. I need to run a script which the php on which German is installed.
How can I do this?
You should check your server configuration files. Look for lines that start with LoadModule php...
There probably are configuration files/directories named mods or something like that. Start from there.
You could also check output from php -r 'phpinfo();' | grep php and compare lines to phpinfo(); from web server.
To run php interactively:
(So you can paste/write code in the console.)
php -a
To make it parse a file and output to the console:
php -f file.php
Parse a file and output to another file:
php -f file.php > results.html
Do you need something else?
To run only a small part, one line or like, you can use:
php -r '$x = "Hello World"; echo "$x\n";'
If you are running Linux then do man php at the console.
If you need/want to run PHP through fpm (FastCGI Process Manager), use cli fcgi:
SCRIPT_NAME="file.php" SCRIP_FILENAME="file.php" REQUEST_METHOD="GET" cgi-fcgi -bind -connect "/var/run/php-fpm/php-fpm.sock"
Where /var/run/php-fpm/php-fpm.sock is your php-fpm socket file.
On SUSE Linux, there are two different configuration files for PHP: one for Apache, and one for CLI (command line interface). In the /etc/php5/ directory, you will find an "apache2" directory and a "cli" directory. Each has a "php.ini" file. The files are for the same purpose (PHP configuration), but apply to the two different ways of running PHP. These files, among other things, load the modules PHP uses.
If your OS is similar, then these two files are probably not the same. Your Apache php.ini is probably loading the German module, while the the CLI php.ini isn't. When the module was installed (auto or manual), it probably only updated the Apache php.ini file.
You could simply copy the Apache php.ini file over into the cli directory to make the CLI environment exactly like the Apache environment.
Or, you could find the line that loads the German module in the Apache file and copy/paste just it to the CLI file.
I was looking for a resolution to this issue in Windows, and it seems to be that if you don't have the environment variables ok, you need to put the complete directory. For example, with a file in the same directory as PHP:
F:\myfolder\php\php.exe -f F:\myfolder\php\script.php