I am developing a PHP app on Heroku. Is it possible for me to use Foreman to test my application? Everywhere I look I find references to Ruby, but nothing for PHP.
Yes, using PHP 5.4 built-in web server:
sudo foreman start -f Procfile_dev
And in Procfile_dev:
web: php -S 127.0.0.1:80 -t /path/to/doc/root
This is how I develop locally. I also have a line worker: watchr watcher.rb that listens for file changes to combine/minify JS, compile SCSS, etc.
You could probably add db: /usr/bin/mysqld or similar to start mysql if need be.
ALSO: you'll want to install the Heroku Config add-on, which will write the app config keys to a .env file that Foreman will send to php server on startup (accessible via getenv just like on Heroku.)
Related
I've been trying to connect my local files to my app using `heroku local web`, but it throws this error:
3:24:15 AM web.1 | 'vendor' is not recognized as an internal or external command,
3:24:15 AM web.1 | operable program or batch file.
[DONE] Killing all processes with signal SIGINT
3:24:15 AM web.1 Exited with exit code null
I'm sure my Procfile is there in the directory and here is the command line web: vendor/bin/heroku-php-apache2.What I'm doing wrong? What is vendor and why it's not recognizing it?
Additional info:
OS: Windows 10
buildpack: PHP
Based on the error message, it looks like you're running this in cmd.exe. Commands there often use forward slashes for options (e.g. foo /a /b) instead of dashes (e.g. foo -a -b).
I believe the slashes in your command are being interpreted as options, making vendor the command that would run.
A common pattern for using a different command local development on Windows is to create a file called Procfile.windows containing a Windows-specific command, e.g. one that uses backslashes instead of forward slashes, and then run locally as heroku local -f Procfile.windows.
But that heroku-php-apache2 binary is unlikely to run on Windows, so that will be insufficient. The getting started with PHP page is notably missing the "run the app locally" step that, for example, the Python page has.
One good option is to use Windows Subsystem for Linux to run a Linux distribution in Windows and develop there. Another might be to use something like Docker or Vagrant to run a development environment in a virtual machine.
Or, if you have PHP installed on Windows already, try using something like php -S instead of Apache:
web: php -S localhost:8000 -t main_folder/
Make sure to keep your existing Procfile as you'll want to use that on Heroku. php -S should only be used for local development.
You might also simply have better luck using PowerShell instead of cmd.exe. It is generally much better-behaved.
I started a new project in new Symfony 5 and i can't open my local server.
On Symfony 4.4 the command PHP bin/console server:run is OK,
But with Symfony 5 the command appears not to be defined...
C:\Users\Chris\Code\api-test> php bin/console server:run
Command "server:run" is not defined.
Do you want to run "server:dump" instead? (yes/no) [no]:
So how to downgrade or start the local server?
The Web Server Bundle is not included with Symfony 5.
But you can simply require it and install it separately.
E.g.:
composer require symfony/web-server-bundle 4.4
It is important that you specify the version (4.4), because otherwise it will attempt to install version 5 (which does not exist, and it will fail).
After that you'll be able to run bin/console server:run as you used to do.
Otherwise, you may use the Symfony CLI as well. This is an executable binary which includes the Symfony Server by default. Then you may run symfony server:start or the better know alias symfony serve to start the local webserver.
Read more about Symfony's server here.
You can also use the built-in web server in the PHP runtime. Just go to your project's root directory and run:
php -S localhost:8000 -t public/
It's not a fully featured webserver, but for developing purposes it is usually more than enough.
For running a local web server you can now use Symfony Client, or simply 'Symfony'.
Download the binary and install it globally.
Open a terminal and run once: symfony server:ca:install. This will install a local SSL certificate authority that allows you to run the local webserver on https://.
Inside the terminal, move into your project directory and run symfony serve. A local webserver will start; by default on https://localhost:8000/.
If you wish to run the webserver on another port you can use symfony serve --port=8080 (in this case port 8080). For the most useful commands Symfony Client has to offer, simply run symfony. To see all available commands run symfony help.
I am using symfony 5 and I just replace the former command php bin/console server:run" by php -S localhost:3000 -t public and it works in a similar way.
-t public to indicate the targeted file.
php -S localhost:9000 -t public | PHP Inbuild Server / -t set to the public dir
php bin/console server:run | Only for Symfony 4.* and below
symfony serve | Symfony Server symfony ServeBundle
To run symfony serve you must first install the ServerBundle: composer require symfony/web-server-bundle
The really really really cool think is that you can use https out of the box. You need only run symfony server:ca:install.
I am using symfony 5,4 and I just use command
$ symfony serve
You need to install symfony by running theses commands:
cd my-project
composer require symfony/web-server-bundle --dev
And run the server
php bin/console server:run
I'm using a Node package called exec-php to execute PHP functions within Node.js app.
I would like to push that app to Heroku, but I'm wondering how to make that, and how that would be in the PHP bin locally.
I'm using /Applications/MAMP/bin/php/php7.0.0/bin/php. What would be the path to PHP bin in Heroku?
I tested vendor/bin/heroku-php-apache2 but it doesn't work, so what would be the path to PHP binary in Heroku?
You'll need to inform the build API that you'd like to use multiple buildpacks. Try:
$ heroku buildpacks:clear
$ heroku buildpacks:add heroku/php
$ heroku buildpacks:add heroku/nodejs
Then you can inspect the compiled slug via heroku run bash to verify that the bins are where you expect them to be.
The bin directory in heroku is : .heroku/php/bin/php
I've installed git-ftp onto my CentOS Server so that I can do deployments from an activeCollab installation running the ac_gitolite module.
Everything installed fine and the app lives at
/usr/local/bin/git-ftp
When I log into the server via ssh I can run git-ftp commands without the full path, but when attempting to use PHP to run commands with exec ie:
exec ("git-ftp --version 2>&1", $output);
I receive the following error:
sh: git-ftp: command not found
Is there an environment path I need to specify somewhere specifically for PHP, or what am I doing wrong?
The two options discussed in "command not found - error in exec() command" are:
One easy solution would be to put the full path of the git-ftp executable.
The other is to add git-ftp to the php server user's PATH.
I would like to ask if I can run a php without having installed a web server. Do I have to use the php like CGI and run my page via command line? And if so, what are the steps that I do I have to choose through the installation of php? I mean the preferences as CGI and the components after that step?
I installed the php 5.3.3 but is seems not working, I get several message that the php5ts.dll is missing and when I put that file in my ext folder other error messages appear. Are there any configuration files or steps that I have to use?
(is php 5.3.3 suitable for doing something like this?)
If I have to have a web server installed how can I run my php code through the command line?
You should normally be able to run a php file (after a successful installation) just by running this command:
$ /path/to/php myfile.php // unix way
C:\php\php.exe myfile.php // windows way
You can read more about running PHP in CLI mode here.
It's worth adding that PHP from version 5.4 onwards is able to run a web server on its own. You can do it by running this code in a folder which you want to serve the pages from:
$ php -S localhost:8000
You can read more about running a PHP in a Web Server mode here.
For windows system you should be able to run php by following below steps:
Download php version you want to use and put it in c:\php.
append ;c:\php to your system path using cmd or gui.
call $ php -S localhost:8000 command in a folder which you want to serve the pages from.
PHP is a normal sripting language similar to bash or python or perl. So a script with shebang works, at least on linux.
Example PHP file:
#!/usr/bin/env php
<?php
echo("Hello World!\n")
?>
How to run it:
$ chmod 755 hello.php # do this only once
$ ./hello.php
You can use these kind of programs to emulate an apache web server and run PHP on your computer:
http://www.wampserver.com/en/
http://www.apachefriends.org/en/xampp.html