I have a too basic php application that I wante to run through the built-in php server and that lives in my VM in my windows machine:
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require '../vendor/autoload.php';
$app = new \Slim\App();
$app->get('/', function (Request $req, Response $res, $arg = []) {
return 'hello world!!';
});
$app->run();
My project structure
tree -I vendor
.
|-- cache
| `-- 6a
| `-- 532bg9987gt23f4356546poo999vvb234234.php
|-- composer.json
|-- composer.lock
|-- public
| `-- js
| `-- app.js
|-- routes
| `-- web.php
`-- views
`-- templates
`-- index.html
7 directories, 7 files
When I run curl from within my VM it obviously works:
php -S localhost:9899&
curl localhost:9899/routes/web.php
Hello world!!
The problem is when I try to connect to this server from my browser (windows machine) I get
This site can’t be reached
Although this doesn't work for my php built-in server, it works perfectly for two other projects developed with nodejs that are on the same VM as the php one.
Why I'm not able to reach the php built-in server especially that nodejs built-in server are accessible?
You are binding your server to localhost. It is only listening on the localhost network interface. It won't be accessible outside of that machine.
Tell it to listen on your externally facing IP address instead.
Alternatively, tell it to listen on all network interfaces:
php -S 0.0.0.0:9889
Related
i have a created project using symfony 5.
For hosting website i am using amazon AWS.
Amazon AWS instance is using nginx.
Everytime i deploy code using Elastic beanstalk i have to add following lines to the etc/nginx/nginx.conf file
location / {
try_files $uri $uri/ /index.php?$args;
}
if i don't add following configuration and don't restart nginx server then only page of my website is visible . Whenever i try to open another page of website excepts homepage i get following error :
404 Not Found
nginx/1.18.0
How can i automate deployment of the ngnix configuration whenever i upload code using elasticbeanstalk ?
If you want to modify your nginx configuration, you should modify your Configuration Files by extending ElasticBeanstalk as explained here
I will assume you are using Amazon Linux 2, if not the ElasticBeanstalk is working completely differently as documented here.
Elastic Beanstalk (using Amazon Linux 2) will automatically look for a .platform directory at the root of your zip file.
By adding .platform/nginx/conf.d/elasticbeanstalk/php-custom.conf with the following content, you should be good to go (assuming you are using the default configuration). Note that you could overwrite the nginx.conf by adding this file .platform/nginx/nginx.conf to your project, but since what you want to do is fairly simple, I would only add a file that will be automatically loaded by nginx.
location / {
try_files $uri $uri/ /index.php?$args;
}
So your project tree should look something like this.
project root
├── .platform
│ └── nginx
│ └── conf.d
│ └── elasticbeanstalk
│ └── php-custom.conf
└── your project files
I am curious if there is a best practice concerning the location of a website's cache folder (templates, images, etc)?
I often see it residing in the webroot with index.html/index.php like so,
Server
`-- /var/
`-- www/
-- example.com/
|-- .git/
|-- public_html/
| |-- cache/
| |-- assets/
| `-- index.html
|-- src/
|-- test/
|-- .gitignore
`-- package.json
However, would it be considered bad practice or create any security concerns if I place the cache folder up one level with the rest of the private project files (.git, node_modules, etc)? Like so...
Server
`-- /var/
`-- www/
-- example.com/
|-- .git/
|-- cache/
|-- public_html/
| |-- assets/
| `-- index.html
|-- src/
|-- test/
|-- .gitignore
`-- package.json
Apologies if this isn't a question for here, but I wasn't able to find much information on best practices regarding project folder structure for the cache. The only stuff I could find was about best practices on using the browser cache and other caching tools.
Thanks!
In Bluemix if I create an application starting from php template then the DocumentRoot is set to:
/htdocs.
I actually would like to have a dir structure like this:
/htdocs
/public_html
index.php
/myCode
myPhpClass.php
with httpd.conf DocumentRoot="${HOME}/htdocs/public_html".
So I tried to push this community buildpack https://github.com/cloudfoundry/php-buildpack.git from my local myAppName dir:
/var
/www
/myAppName
/public_html
index.php
/myCode
myOhoClass.php
/.bp-config
options.json
using cf:
[... myAppName]# cf push -s cflinuxfs2 -m 128M -b https://github.com/cloudfoundry/php-buildpack.git myAppName
where options.json file:
{
"WEBDIR": "htdocs/public_html"
}
but what I ended to get in Bluemix is:
/htdocs
/public_html
/public_html
index.php
/myCode
myPhpClass.php
Is there a way to have a custom directory structure for an apache httpd/php application in Bluemix?
Your .bp-config/options.json file is a little wrong. It should be the following.
{
"WEBDIR": "public_html"
}
I just tried things myself with a PHP app and it worked fine.
cf push php-test-jbs -b https://github.com/cloudfoundry/php-buildpack.git -s cflinuxfs2
Additionally to deploy the sample click the following.
or goto the Github project to check out a full sample.
I'm starting in Doctrine 2.4 and I'm developing a system where I separate the core files and application files, as follows:
/ root
|-- /Src
|-- / App
|-- /Model
|- ** (Application Entities) **
|-- /Core
|-- /Model
|-- ** (Core Entities) **
In the Doctrine documentation shows the following form to set 1 directory for Esntitys:
$config = Setup::createAnnotationMetadataConfiguration(array(__DIR__. "/src"), $isDevMode);
But when I have to configure more than one directory that will contain the Entitys of my application, how to proceed?
Thanks in advance!
I found a way to resolve the issue. Simple!!!
Put like this:
$config = Setup::createAnnotationMetadataConfiguration(array(__DIR__."/src/App/Model/", __DIR__."/src/Core/Model/"), $isDevMode);
I'm creating an app in Symfony which is using a library I'm writing at the same time.
While my application is being built with symfony, I want the component library to be completely framework independent as it needs to be reusable by applications not necessarily written in symfony.
Therefore I have a symfony bundle which integrates the library (the component)
The folder structure is a follows
src/MyVendor/
|-- Bundle
| `-- MyComponentBundle
| |-- Controller
| |-- DependencyInjection
| |-- Resources
| | |-- config
| | `-- views
| | `-- Default
| |-- Tests
| `-- Controller
| `-- MyObjectControllerTest.php
| `-- MyComponentBundle.php
`-- Component
`-- MyComponent
|-- doc
|-- src
`-- MyObject.php
|-- test
`-- MyObjectTest.php
|-- .gitignore
|-- composer.json
|-- LICENSE
|-- README.md
`-- phpunit.xml.dist
Questions:
Is MyComponent directory structure correct as per the PSR-x Autoloading standards? For example, how do I use MyObject from the library inside the bundle, i.e. in MyObjectControllerTest.php
Can MyObject reside in the namespace of MyVendor\MyComponent? If not, how do I have to amend the directory structure so that (1) I can use that namespace, and (2) so that it can be autoloaded inside MyObjectControllerTest.php, i.e. new MyVendor\MyComponent\MyObject(); will work; right now I'm getting PHP Fatal error: Class 'MyVendor\MyComponent\MyObject' not found in ...
Could you please direct me to an online resource to help me to publish MyComponent on github and make it available to symfony (I'm guessing most of that involves just setting up composer.json correctly)
Thank you
It's compatible with PSR-x autoloaders. But your namespaces should be properly registered (PSR-4, PSR-0).
You should create proper autoload to use your component (using composer, for example).
Just create a repo for your component on github, create your composer.json (or copy/past and edit some side one), submit your package on packagist (just insert github project link)