Ok, I am trying to create an email logger, that uses a PHP shell script. I have set up CPanel to pipe emails to my script. I am sure this is all configured properly. However I am having problems with the script, well any script for that matter when running it from the shell.
here is an example.
#!/usr/local/bin/php –q
<?php
/* Read the message from STDIN */
$fd = fopen("php://stdin", "r");
$email = ""; // This will be the variable holding the data.
while (!feof($fd)) {
$email .= fread($fd, 1024);
}
fclose($fd);
/* Saves the data into a file */
$fdw = fopen("mail.txt", "w+");
fwrite($fdw, $email);
fclose($fdw);
/* Script End */
?>
Real simple, right? Read from STDIN and write to a file…I thought something was wrong, not able to read STDIN for some reason. Hosting provider allows it, allow_url_open and allow_url_include are both on.
When executing the script via SSH I get the following error:
Could not open input file: âq
So once again I thought that was the script telling me, that is could not read from STDIN
So I tried just a simple script.
#!/usr/local/bin/php –q
<?php
echo 'Hello World';
?>
Same thing:
Could not open input file: âq
So it appears that the PHP program is telling me it is unable to open the script? The script is located in $HOME/mail/forward (CHMOD 755) and the script itself is CHMOD 755, as well the file mail.txt is CHMOD 755
I am really stumped on this.
Have you just got the Laravel error could not open input file artisan?
Usually, the error shows up when a user tries to open the Laravel project outside the project folder.
At Bobcares, customers often approach us to fix Laravel errors, as a part of our Server Management Services.
Today, let’s see how our Support Engineers fix this Laravel error.
Laravel application structure
Laravel is a PHP framework for web application development. A composer is a tool that integrates the dependencies and libraries.
It includes the dependencies in the composer.json file. This file is usually placed in the source folder.
Laravel has a command-line interface. This is known as Artisan. It has a set of commands to assist web application development. To start the Laravel service, we use the command,
php artisan
But in some cases, this ends up in errors. Our customers often approach us to fix errors while accessing the artisan console. Today, let’s discuss one such error.
Laravel error could not open input file artisan
Could not open input file: artisan
This is a very common error message that a Laravel user gets.
Usually, users get this error while trying to access a project using the command, php artisan
. In the command-line, the error appears as,
Now let’s see why does this error appears.
1. Wrong console location
This error mainly occurs when a user tries to open a Laravel project outside the project folder. Laravel can only execute the project if we open it inside the project folder.
That is what the error says ‘could not open input file‘. So whenever customers approach us with this error, we ask the customer to re-check the location where they execute the command.
2. Improper permissions of artisan
Sometimes the artisan may not be executable. If the user tries to execute the command, it cannot access it. And the user receives this error.
So to make artisan executable, we use the command
chmod +x artisan
Later try to use the command, and it will work.
[Still, having trouble in loading your Laravel project? – We can help you.]
Conclusion
So far we saw the reasons for the Laravel error could not open input file artisan. Incorrect console location and improper permissions trigger the error. We also saw how our Support Engineers fix it.
PREVENT YOUR SERVER FROM CRASHING!
Never again lose customers to poor server speed! Let us help you.
Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.
GET STARTED
var google_conversion_label = «owonCMyG5nEQ0aD71QM»;
php – Running Composer returns: Could not open input file: composer.phar
If you followed instructions like these:
https://getcomposer.org/doc/00-intro.md
Which tell you to do the following:
$ curl -sS https://getcomposer.org/installer | php
$ mv composer.phar /usr/local/bin/composer
Then its likely that you, like me, ran those commands and didnt read the next part of the page telling you to stop referring to composer.phar by its full name and abbreviate it as an executable (that you just renamed with the mv command). So this:
$ php composer.phar update friendsofsymfony/elastica-bundle
Becomes this:
$ composer update friendsofsymfony/elastica-bundle
I had the same problem on Windows and used a different solution. I used the Composer_Setup.exe installation file supplied by the composer website and it does a global install.
After installing, make sure your PATH variable points to the directory where composer.phar is stored. This is usually C:ProgramDataComposerSetupbin
(ProgramData might be a hidden directory). It goes without saying, but also be sure that the PHP executable is also in your PATH variable.
You can then simply call
composer install
instead of
php composer.phar install
php – Running Composer returns: Could not open input file: composer.phar
Background
It is helpful to know that there are two ways to install (and use) Composer: locally as a file in your project directory, or globally as a system-wide executable.
Installing Composer locally simply means that you are downloading a file (composer.phar
– which is a PHP Archive) into your project directory. You will have to download it for every project that requires Composer.
Like a regular PHP file that you want to execute on the command line, you will have to run it with PHP:
php composer.phar update
Which basically tells the php
executable to run the file composer.phar
with update
as argument.
However, if you install it globally, you can make composer itself executable, so you can call it without php (and dont have to download it for every project). In other words, you can use composer like this:
composer update
Since you are executing php composer.phar update
, and you are getting the error Could not open input file: composer.phar
, you probably dont have composer.phar
in your current directory.
Solution
If you have Composer installed globally, simply run composer update
instead of php composer.phar update
.
If you dont have Composer installed yet, download the PHAR using the following command:
curl -sS https://getcomposer.org/installer | php
This will download the installer and run it using php
. The installer will download the actual Composer PHAR to your current working directory, and make it executable.
To install Composer globally (I recommend this), copy the file to a location in your PATH
. The exact location differs per operating system and setup, see https://getcomposer.org/doc/00-intro.md#globally for more information.
Personally, I prefer to install Composer in my home directory so I dont need sudo
to install or update the composer
executable (which can be a security risk). As Im on Linux, I use the following command:
mv composer.phar ~/.local/bin/composer
Related posts on php :
- php – Zend 2 redirect with toRoute not working
- php – How to get url of current theme?
- php – Package php5-gd has no installation candidate
- php – regex match any whitespace
- php – How to get cookie value
- php get URL of current file directory
- apache – How to install php 5 on Ubuntu 16.04
- php – what is the difference between site_url() and base_url()?
Фон
Полезно знать, что есть два способа установить (и использовать) Composer: локально как файл в каталоге вашего проекта или глобально как исполняемый файл всей системы.
Локальная установка Composer просто означает, что вы загружаете файл (composer.phar
— это архив PHP) в каталог вашего проекта. Вам придется скачать его для каждого проекта, для которого требуется Composer.
Как обычный PHP файл, который вы хотите выполнить в командной строке, вам нужно будет запустить его с PHP:
php composer.phar update
Что в основном говорит исполняемому файлу php
запускать файл composer.phar
с update
качестве аргумента.
Однако, если вы установите его глобально, вы можете сделать сам Composer исполняемым, так что вы можете вызывать его без php (и не нужно загружать его для каждого проекта). Другими словами, вы можете использовать composer следующим образом:
composer update
Поскольку вы выполняете php composer.phar update
и получаете сообщение об ошибке. Could not open input file: composer.phar
, вероятно, в вашей текущей директории нет composer.phar
.
Решение
Если у вас установлен Composer глобально, просто запустите composer update
вместо php composer.phar update
.
Если у вас еще не установлен Composer, загрузите PHAR с помощью следующей команды:
curl -sS https://getcomposer.org/installer | php
Это загрузит установщик и запустит его с помощью php
. Установщик загрузит фактический PHAR Composer в ваш текущий рабочий каталог и сделает его исполняемым.
Чтобы установить Composer глобально (я рекомендую это), скопируйте файл в папку в вашей PATH
. Точное местоположение зависит от операционной системы и настроек, см. Https://getcomposer.org/doc/00-intro.md#globally для получения дополнительной информации.
Лично я предпочитаю устанавливать Composer в свой домашний каталог, поэтому мне не нужен sudo
для установки или обновления исполняемого файла composer
(что может быть угрозой безопасности). Поскольку я работаю в Linux, я использую следующую команду:
mv composer.phar ~/.local/bin/composer
I have installed Magento 2.2.5
on my localhost windows system. I use the wamp server.
I am unable to run any PHP command and getting the error Could not open input file: C:wamp64wwwmagento2
I got this
C:wamp64binphpphp7.0.32>php C:wamp64wwwmagento2 cache:flush
Could not open input file: C:wamp64wwwmagento2
I gave all permissions on the magento2 folder using system property still it doesn’t work.
Please suggest me a way out.
Msquare
7,1106 gold badges21 silver badges52 bronze badges
asked Jan 13, 2019 at 7:41
Magento LearnerMagento Learner
3851 gold badge5 silver badges17 bronze badges
Finally, It works for me.
I just add my PHP installation file path in the system user variable path. Closing and opening cmd and all of the commands work perfectly.
My PHP installation path is C:wamp64binphpphp7.0.32.
Msquare
7,1106 gold badges21 silver badges52 bronze badges
answered Jan 13, 2019 at 16:39
Magento LearnerMagento Learner
3851 gold badge5 silver badges17 bronze badges
I think you are running and using the command in the wrong way that’s why you are getting the error.
Do this instead:
- First, open
cmd
go toC:wamp64wwwmagento2
( I suppose this is your magento2 installation directory) - From there, run the following commands below and check if you still get the errors you get before
php bin/magento cache:flush
Msquare
7,1106 gold badges21 silver badges52 bronze badges
answered Jan 13, 2019 at 9:49
2
If like me you tried the command
php artisan
However, you had the following “Could not open input file: artisan” error when starting the Laravel service using the above command.
How come “Could not open input file: artisan” error is showing up in Laravel
There are a few causes behind this error.
- File doesn’t exist
- Incorrect console location
- Missing correct permission for artisan
- Composer install
File doesn’t exist
Yep — I know, I shouldn’t have to reference this one, but it’s amazing how common this is overlooked. Check does artisan exist? Doesn’t exist, first step install.
Incorrect console location
There is a chance of getting this error when you are running the “php artisan” command outside the Laravel project folder.
To resolve this, you need to run the “php artisan” command inside the Laravel project location.
cd my_laravel_project/ php artisan
You can replace the “my_laravel_project/” with your Laravel project location.
Missing correct permission for artisan
Otherwise there is a possibility of the artisan not being executable. In this situation the artisan command cannot able to access and it will throw this error.
So you need to confirm that artisan is executable.
chmod +x artisan
Composer install
OK, so you have reached here as the above two options didn’t work.
Now you need to try and run
composer install
When I initially ran this command, I received an awesome list of errors
Problem 1
— astrotomic/laravel-translatable is locked to version v11.10.0 and an update of this package was not requested.
— astrotomic/laravel-translatable v11.10.0 requires php ^8.0 -> your php version (7.3.33) does not satisfy that requirement.
Problem 2
— cartalyst/tags is locked to version v12.0.0 and an update of this package was not requested.
— cartalyst/tags v12.0.0 requires php ^8.0 -> your php version (7.3.33) does not satisfy that requirement.
Problem 3
— fruitcake/php-cors is locked to version v1.2.0 and an update of this package was not requested.
— fruitcake/php-cors v1.2.0 requires php ^7.4|^8.0 -> your php version (7.3.33) does not satisfy that requirement.
Problem 4
— laravel/framework is locked to version v9.3.0 and an update of this package was not requested.
— laravel/framework v9.3.0 requires php ^8.0.2 -> your php version (7.3.33) does not satisfy that requirement.
Problem 5
— league/commonmark is locked to version 2.2.3 and an update of this package was not requested.
— league/commonmark 2.2.3 requires php ^7.4 || ^8.0 -> your php version (7.3.33) does not satisfy that requirement.
Problem 6
— league/config is locked to version v1.1.1 and an update of this package was not requested.
— league/config v1.1.1 requires php ^7.4 || ^8.0 -> your php version (7.3.33) does not satisfy that requirement.
Problem 7
— league/flysystem is locked to version 3.0.10 and an update of this package was not requested.
— league/flysystem 3.0.10 requires php ^8.0.2 -> your php version (7.3.33) does not satisfy that requirement.
Problem 8
— league/flysystem-aws-s3-v3 is locked to version 3.0.10 and an update of this package was not requested.
— league/flysystem-aws-s3-v3 3.0.10 requires php ^8.0.2 -> your php version (7.3.33) does not satisfy that requirement.
Problem 9
— league/flysystem-azure-blob-storage is locked to version 3.0.9 and an update of this package was not requested.
— league/flysystem-azure-blob-storage 3.0.9 requires php ^8.0.2 -> your php version (7.3.33) does not satisfy that requirement.
Problem 10
— psr/cache is locked to version 2.0.0 and an update of this package was not requested.
— psr/cache 2.0.0 requires php >=8.0.0 -> your php version (7.3.33) does not satisfy that requirement.
Problem 11
— psr/container is locked to version 2.0.2 and an update of this package was not requested.
— psr/container 2.0.2 requires php >=7.4.0 -> your php version (7.3.33) does not satisfy that requirement.
Problem 12
— psr/log is locked to version 3.0.0 and an update of this package was not requested.
— psr/log 3.0.0 requires php >=8.0.0 -> your php version (7.3.33) does not satisfy that requirement.
Problem 13
— psr/simple-cache is locked to version 3.0.0 and an update of this package was not requested.
— psr/simple-cache 3.0.0 requires php >=8.0.0 -> your php version (7.3.33) does not satisfy that requirement.
Problem 14
— spatie/laravel-activitylog is locked to version 4.4.0 and an update of this package was not requested.
— spatie/laravel-activitylog 4.4.0 requires php ^8.0 -> your php version (7.3.33) does not satisfy that requirement.
Problem 15
— spatie/laravel-analytics is locked to version 4.1.0 and an update of this package was not requested.
— spatie/laravel-analytics 4.1.0 requires php ^8.0 -> your php version (7.3.33) does not satisfy that requirement.
Problem 16
— spatie/laravel-package-tools is locked to version 1.11.2 and an update of this package was not requested.
— spatie/laravel-package-tools 1.11.2 requires php ^7.4|^8.0 -> your php version (7.3.33) does not satisfy that requirement.
Problem 17
— spatie/once is locked to version 3.0.2 and an update of this package was not requested.
— spatie/once 3.0.2 requires php ^8.0 -> your php version (7.3.33) does not satisfy that requirement.
Problem 18
— symfony/cache is locked to version v6.0.5 and an update of this package was not requested.
— symfony/cache v6.0.5 requires php >=8.0.2 -> your php version (7.3.33) does not satisfy that requirement.
Problem 19
— symfony/console is locked to version v6.0.5 and an update of this package was not requested.
— symfony/console v6.0.5 requires php >=8.0.2 -> your php version (7.3.33) does not satisfy that requirement.
Problem 20
— symfony/css-selector is locked to version v6.0.3 and an update of this package was not requested.
— symfony/css-selector v6.0.3 requires php >=8.0.2 -> your php version (7.3.33) does not satisfy that requirement.
Problem 21
— symfony/deprecation-contracts is locked to version v3.0.0 and an update of this package was not requested.
— symfony/deprecation-contracts v3.0.0 requires php >=8.0.2 -> your php version (7.3.33) does not satisfy that requirement.
Problem 22
— symfony/error-handler is locked to version v6.0.3 and an update of this package was not requested.
— symfony/error-handler v6.0.3 requires php >=8.0.2 -> your php version (7.3.33) does not satisfy that requirement.
Problem 23
— symfony/event-dispatcher is locked to version v6.0.3 and an update of this package was not requested.
— symfony/event-dispatcher v6.0.3 requires php >=8.0.2 -> your php version (7.3.33) does not satisfy that requirement.
Problem 24
— symfony/event-dispatcher-contracts is locked to version v3.0.0 and an update of this package was not requested.
— symfony/event-dispatcher-contracts v3.0.0 requires php >=8.0.2 -> your php version (7.3.33) does not satisfy that requirement.
Problem 25
— symfony/finder is locked to version v6.0.3 and an update of this package was not requested.
— symfony/finder v6.0.3 requires php >=8.0.2 -> your php version (7.3.33) does not satisfy that requirement.
Problem 26
— symfony/http-foundation is locked to version v6.0.5 and an update of this package was not requested.
— symfony/http-foundation v6.0.5 requires php >=8.0.2 -> your php version (7.3.33) does not satisfy that requirement.
Problem 27
— symfony/http-kernel is locked to version v6.0.5 and an update of this package was not requested.
— symfony/http-kernel v6.0.5 requires php >=8.0.2 -> your php version (7.3.33) does not satisfy that requirement.
Problem 28
— symfony/mailer is locked to version v6.0.5 and an update of this package was not requested.
— symfony/mailer v6.0.5 requires php >=8.0.2 -> your php version (7.3.33) does not satisfy that requirement.
Problem 29
— symfony/mime is locked to version v6.0.3 and an update of this package was not requested.
— symfony/mime v6.0.3 requires php >=8.0.2 -> your php version (7.3.33) does not satisfy that requirement.
Problem 30
— symfony/process is locked to version v6.0.5 and an update of this package was not requested.
— symfony/process v6.0.5 requires php >=8.0.2 -> your php version (7.3.33) does not satisfy that requirement.
Problem 31
— symfony/routing is locked to version v6.0.5 and an update of this package was not requested.
— symfony/routing v6.0.5 requires php >=8.0.2 -> your php version (7.3.33) does not satisfy that requirement.
Problem 32
— symfony/service-contracts is locked to version v3.0.0 and an update of this package was not requested.
— symfony/service-contracts v3.0.0 requires php >=8.0.2 -> your php version (7.3.33) does not satisfy that requirement.
Problem 33
— symfony/string is locked to version v6.0.3 and an update of this package was not requested.
— symfony/string v6.0.3 requires php >=8.0.2 -> your php version (7.3.33) does not satisfy that requirement.
Problem 34
— symfony/translation is locked to version v6.0.5 and an update of this package was not requested.
— symfony/translation v6.0.5 requires php >=8.0.2 -> your php version (7.3.33) does not satisfy that requirement.
Problem 35
— symfony/translation-contracts is locked to version v3.0.0 and an update of this package was not requested.
— symfony/translation-contracts v3.0.0 requires php >=8.0.2 -> your php version (7.3.33) does not satisfy that requirement.
Problem 36
— symfony/var-dumper is locked to version v6.0.5 and an update of this package was not requested.
— symfony/var-dumper v6.0.5 requires php >=8.0.2 -> your php version (7.3.33) does not satisfy that requirement.
Problem 37
— symfony/var-exporter is locked to version v6.0.3 and an update of this package was not requested.
— symfony/var-exporter v6.0.3 requires php >=8.0.2 -> your php version (7.3.33) does not satisfy that requirement.
Problem 38
— chillerlan/php-qrcode is locked to version 4.3.3 and an update of this package was not requested.
— chillerlan/php-qrcode 4.3.3 requires php ^7.4 || ^8.0 -> your php version (7.3.33) does not satisfy that requirement.
Problem 39
— chillerlan/php-settings-container is locked to version 2.1.2 and an update of this package was not requested.
— chillerlan/php-settings-container 2.1.2 requires php ^7.4 || ^8.0 -> your php version (7.3.33) does not satisfy that requirement.
Problem 40
— composer/pcre is locked to version 3.0.0 and an update of this package was not requested.
— composer/pcre 3.0.0 requires php ^7.4 || ^8.0 -> your php version (7.3.33) does not satisfy that requirement.
Problem 41
— friendsofphp/php-cs-fixer is locked to version v3.6.0 and an update of this package was not requested.
— friendsofphp/php-cs-fixer v3.6.0 requires php ^7.4 || ^8.0 -> your php version (7.3.33) does not satisfy that requirement.
Problem 42
— nunomaduro/collision is locked to version v6.1.0 and an update of this package was not requested.
— nunomaduro/collision v6.1.0 requires php ^8.0.0 -> your php version (7.3.33) does not satisfy that requirement.
Problem 43
— orchestra/testbench is locked to version v7.1.0 and an update of this package was not requested.
— orchestra/testbench v7.1.0 requires php ^8.0 -> your php version (7.3.33) does not satisfy that requirement.
Problem 44
— orchestra/testbench-core is locked to version v7.1.0 and an update of this package was not requested.
— orchestra/testbench-core v7.1.0 requires php ^8.0 -> your php version (7.3.33) does not satisfy that requirement.
Problem 45
— spatie/macroable is locked to version 2.0.0 and an update of this package was not requested.
— spatie/macroable 2.0.0 requires php ^8.0 -> your php version (7.3.33) does not satisfy that requirement.
Problem 46
— symfony/filesystem is locked to version v6.0.5 and an update of this package was not requested.
— symfony/filesystem v6.0.5 requires php >=8.0.2 -> your php version (7.3.33) does not satisfy that requirement.
Problem 47
— symfony/options-resolver is locked to version v6.0.3 and an update of this package was not requested.
— symfony/options-resolver v6.0.3 requires php >=8.0.2 -> your php version (7.3.33) does not satisfy that requirement.
Problem 48
— symfony/stopwatch is locked to version v6.0.5 and an update of this package was not requested.
— symfony/stopwatch v6.0.5 requires php >=8.0.2 -> your php version (7.3.33) does not satisfy that requirement.
Problem 49
— symfony/yaml is locked to version v6.0.3 and an update of this package was not requested.
— symfony/yaml v6.0.3 requires php >=8.0.2 -> your php version (7.3.33) does not satisfy that requirement.
Problem 50
— laravel/framework v9.3.0 requires php ^8.0.2 -> your php version (7.3.33) does not satisfy that requirement.
— spatie/laravel-ray 1.29.4 requires illuminate/contracts ^7.20|^8.19|^9.0 -> satisfiable by laravel/framework[v9.3.0].
— spatie/laravel-ray is locked to version 1.29.4 and an update of this package was not requested.
Yeah, I know awesome right. But they all point to the same issue. PHP version conflict.
For me, the usual fix is to run
export PATH=/opt/plesk/php/8.0/bin:$PATH;
However, on running this command and then testing the PHP version I was going nowhere
php -v PHP 7.4.28 (cli) (built: Feb 18 2022 15:48:26) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with the ionCube PHP Loader + ionCube24 v11.0.1, Copyright (c) 2002-2022, by ionCube Ltd. with Zend OPcache v7.4.28, Copyright (c), by Zend Technologies
The resolution was to run the command
alias php='/opt/plesk/php/8.0/bin/php'
How did I know that the solution above would work? When I ran the command
which PHP
The response was
alias php='/opt/plesk/php/7.4/bin/php' /opt/plesk/php/7.4/bin/php
Whereas, I had been anticipating the following response
/usr/bin/php
Post running the command
alias php='/opt/plesk/php/8.0/bin/php'
A PHP version check
php -v
Produced the following response
PHP 8.0.16 (cli) (built: Feb 18 2022 15:47:57) ( NTS ) Copyright (c) The PHP Group Zend Engine v4.0.16, Copyright (c) Zend Technologies with Zend OPcache v8.0.16, Copyright (c), by Zend Technologies
Attempting to run composer install command again
composer install
Response
Installing dependencies from lock file (including require-dev) Verifying lock file contents can be installed on the current platform. Nothing to install, update or remove Generating autoload files
Attempting PHP artisan command again
Now that composer is friendly, PHP is running off 8.x, will the command PHP artisan work or produce the same error?
PHP artisan
Response
Could not open input file: artisan
Installing laravel
When installing Laravel, take note of the path when using the following command
composer global require laravel/installer
The response I had was
/Users/{name}/.composer
Summary
- TL;DR
- Remember the Laravel application structure
- What does php artisan serve to?
- You didn’t install composer correctly on your project, artisan permission missing
- You are trying to run laravel outside the project folder
- Using docker, your path is not set correctly
- My setup
- The script to start the container
- The Dockerfile to build the image
- The docker-compose setup
- The issue
- Why it failed during the docker build
- Why it worked during the
- The solution
- Conclusion
When I run my laravel application, I get the error Laravel docker image Could not open input file: /var/www/html/artisan. I finally found the root cause of the issue, let me share it with you.
I generated my application in Laravel sail but now I am working to make it run inside a docker container. My application runs well in I use the docker-compose run but during the docker build process to generate the image, I get an error.
Since I run it in a docker container, we are going to diagnose by Laravel is complaining.
TL;DR
The short answer is that your Laravel source code is not accessible by the process that is trying to run it.
First, let’s recall the structure of a Laravel application
Remember the Laravel application structure
A composer is a tool that integrates the dependencies and libraries. Laravel is a PHP framework for web application development.
Composer comes with the dependencies in the composer.json file. This file must be located in the source folder.
What does php artisan serve to?
Artisan in the other hand is a command line interface for Laravel. It has a set of commands to assist web application development.
To start the Laravel service, we use the command,
There is a command that can help you run a developpment server locally to test your project. The command is php artisan serve
.
You often get this error when you try to execute the above command. There are a few reasons where you can get that error.
You didn’t install composer correctly on your project, artisan permission missing
This error can happen because you didn’t install composer correctly on your project.
Hence, artisan
does not have the permissions to run as required.
To fix that issue, you need to make the artisan executable. Run this command:
You are trying to run laravel outside the project folder
Although the error will be slightly different, let’s coder this reason as well.
If you are trying to run laravel outside the project folder, you will get this error:
could not open input file
To solve the problem could not open input file
, move to your project location and try to start laravel again.
cd my_laravel_project/
php artisan
Using docker, your path is not set correctly
In my case, I run Laravel in a docker container using supervisord
.
To start, I run the application using the docker-compose up
command (see below the configuration that I have). It worked well because I have a volume linked to the source code (see the plain line below). This means that the docker-compose run
process has access to the source code, so it worked.
When I run the build process to generate my docker image docker build docker/7.4 -t mypersonaltag
there is no link to the source code (see the dotted line below). So the build process failed with that error :
Laravel docker image Could not open input file: /var/www/html/artisan
depending on your setup, you could get this alternate error message
could not open input file: artisan
Here is a schema of my setup:
graph
direction LR;
A[Source code]
B[docker-compose up process]
C[docker build process]
B-->A
C-.->A
My setup
My setup is quite similar to the laravel setup I did with docker in this post. The idea is to bundle your application inside a docker image, then use the image in other docker services to build something bigger.
The script to start the container
I created this script to run the necessary steps to start the application.
It takes care of the permission issies and then uses supervisord
to start the application.
At this stage, the source code of the application is assumed to be in the /var/www/html/
container image.
#!/usr/bin/env bash
if [ ! -z "$WWWUSER" ]; then
usermod -u $WWWUSER sail
fi
if [ ! -d /.composer ]; then
mkdir /.composer
fi
chmod -R ugo+rw /.composer
if [ $# -gt 0 ];then
exec gosu $WWWUSER "[email protected]"
else
/usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
fi
The supervisord
configuration file is below:
[supervisord]
nodaemon=true
user=root
logfile=/var/log/supervisor/supervisord.log
pidfile=/var/run/supervisord.pid
[program:php]
command=/usr/bin/php -d variables_order=EGPCS /var/www/html/artisan serve --host=0.0.0.0 --port=80
user=sail
environment=LARAVEL_SAIL="1"
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
The Dockerfile to build the image
Here is the Dockerfile I used to build the image. You can see that there is no instruction to copy the source code inside the container image.
But at the end of the file, there is an ENTRYTPOINT instruction asking the container to run the script we created above.
FROM ubuntu:20.04
LABEL maintainer="Taylor Otwell"
ARG WWWGROUP
WORKDIR /var/www/html
ENV DEBIAN_FRONTEND noninteractive
ENV TZ=UTC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt-get update
&& apt-get install -y gosu curl zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2
RUN apt-get install -y gnupg ca-certificates
RUN mkdir -p ~/.gnupg
&& chmod 600 ~/.gnupg
&& echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf
&& apt-key adv --homedir ~/.gnupg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys E5267A6C
&& apt-key adv --homedir ~/.gnupg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C300EE8C
&& echo "deb http://ppa.launchpad.net/ondrej/php/ubuntu focal main" > /etc/apt/sources.list.d/ppa_ondrej_php.list
&& apt-get update
&& apt-get install -y php7.4-cli php7.4-dev
php7.4-pgsql php7.4-sqlite3 php7.4-gd
php7.4-curl php7.4-memcached
php7.4-imap php7.4-mysql php7.4-mbstring
php7.4-xml php7.4-zip php7.4-bcmath php7.4-soap
php7.4-intl php7.4-readline php7.4-pcov
php7.4-msgpack php7.4-igbinary php7.4-ldap
php7.4-redis
&& php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer
&& curl -sL https://deb.nodesource.com/setup_15.x | bash -
&& apt-get install -y nodejs
&& curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list
&& apt-get update
&& apt-get install -y yarn
&& apt-get install -y mysql-client
&& apt-get install -y postgresql-client
&& apt-get -y autoremove
&& apt-get clean
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN setcap "cap_net_bind_service=+ep" /usr/bin/php7.4
# RUN groupadd --force -g www-data sail
RUN useradd -ms /bin/bash --no-user-group -g www-data -u 1337 sail
COPY start-container /usr/local/bin/start-container
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY php.ini /etc/php/7.4/cli/conf.d/99-sail.ini
RUN chmod +x /usr/local/bin/start-container
EXPOSE 8000
ENTRYPOINT ["start-container"]
The docker-compose setup
Here is my docker-compose stack. It is intended to pack everything together.
The Laravel application is build from the Dockerfile
we created previously.
It maps the source code from the current folder (where the docker-compose.yml
is located).
version: '3'
services:
laravel.test:
build:
context: ./docker/7.4
dockerfile: Dockerfile
args:
WWWGROUP: 'www-data'
container_name: laravel
image: sail-7.4/app
ports:
- '${APP_PORT:-80}:80'
environment:
WWWUSER: 'sail'
LARAVEL_SAIL: 1
volumes:
- '.:/var/www/html'
networks:
- sail
depends_on:
- mysql
mysql:
image: 'mysql:8.0'
container_name: 'mysql'
restart: 'unless-stopped'
tty: 'true'
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_USER: '${DB_USERNAME}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
SERVICE_TAGS: 'dev'
SERVICE_NAME: 'mysql'
volumes:
- 'sailmysql:/var/lib/mysql'
networks:
- sail
healthcheck:
test: ["CMD", "mysqladmin", "ping"]
networks:
sail:
driver: bridge
volumes:
sailmysql:
driver: local
The issue
Why it failed during the docker build
The root cause is releated to the presence of the source code.
The error below is thrown when:
- the container image build
- ENTRYPOINT run the script to start the container
supervisord
tries to run the code and then 💥 (the source code is missing)
Laravel docker image Could not open input file: /var/www/html/artisan
Why it worked during the
When I run the application using the docker-compose up
command. It worked well because I have a volume linked to the source code
volumes:
- '.:/var/www/html'
This means that the docker-compose run
process has access to the source code, so it worked.
The solution
To solve the issue, you need to add a COPY instruction to the Dockerfile
.
The source code is located in the current directory. The instruction will copy the source into the instance.
Here is the complete Dockerfile.
FROM ubuntu:20.04
LABEL maintainer="Taylor Otwell"
ARG WWWGROUP
WORKDIR /var/www/html
ENV DEBIAN_FRONTEND noninteractive
ENV TZ=UTC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt-get update
&& apt-get install -y gosu curl zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2
RUN apt-get install -y gnupg ca-certificates
RUN mkdir -p ~/.gnupg
&& chmod 600 ~/.gnupg
&& echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf
&& apt-key adv --homedir ~/.gnupg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys E5267A6C
&& apt-key adv --homedir ~/.gnupg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C300EE8C
&& echo "deb http://ppa.launchpad.net/ondrej/php/ubuntu focal main" > /etc/apt/sources.list.d/ppa_ondrej_php.list
&& apt-get update
&& apt-get install -y php7.4-cli php7.4-dev
php7.4-pgsql php7.4-sqlite3 php7.4-gd
php7.4-curl php7.4-memcached
php7.4-imap php7.4-mysql php7.4-mbstring
php7.4-xml php7.4-zip php7.4-bcmath php7.4-soap
php7.4-intl php7.4-readline php7.4-pcov
php7.4-msgpack php7.4-igbinary php7.4-ldap
php7.4-redis
&& php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer
&& curl -sL https://deb.nodesource.com/setup_15.x | bash -
&& apt-get install -y nodejs
&& curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list
&& apt-get update
&& apt-get install -y yarn
&& apt-get install -y mysql-client
&& apt-get install -y postgresql-client
&& apt-get -y autoremove
&& apt-get clean
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN setcap "cap_net_bind_service=+ep" /usr/bin/php7.4
# RUN groupadd --force -g www-data sail
RUN useradd -ms /bin/bash --no-user-group -g www-data -u 1337 sail
COPY . /var/www/html
COPY start-container /usr/local/bin/start-container
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY php.ini /etc/php/7.4/cli/conf.d/99-sail.ini
RUN chmod +x /usr/local/bin/start-container
EXPOSE 8000
ENTRYPOINT ["start-container"]
Conclusion
It is nice to have been able to pinpoint the root cause.
Hope you liked it.
Share your thoughts in the comments section.