How to start a php backend app on Ubuntu remote host AWS - php

I have scp'ed a php backend app (rest server) to a remote ubuntu host on aws. When I was testing it locally I would just do a simple php -S localhost:8888 for testing the service locally. But now that I have it on a remote host (aws) which has a public ip address, I'm not sure how to start the app. How do I start this app?
So when I try to access the app from any where such as:
http://<server_addr>/api/get/record/1
I'll get expected response payload and 200 response code

To make it work try
php -S 0.0.0.0:8888
That way the server is going to listen on any interface. It doesn't work externally because it is listening only on the 127.0.0.1 interface.
With php -S localhost:8888 if you make a request with wget or curl, connected via ssh to the php server, it should get the content.
As the other answer says, try apache. The php built-in server is just for local development as the docs estipulate.
This web server was designed to aid application development. It may
also be useful for testing purposes or for application demonstrations
that are run in controlled environments. It is not intended to be a
full-featured web server. It should not be used on a public network
http://php.net/manual/en/features.commandline.webserver.php
Edit: Oh, and here you have the AWS docs on how to setup the apache server:
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/install-LAMP.html

To host a PHP based application you will need a webserver with php module enabled. For example you can use apache httpd server (I would suggest you to use if your website is php based). Once your server is installed you should be able to access it on http://yourserveraddress:serverport
To install http with php module on an ubuntu machine you just need to run this command (in most of the cases).
sudo apt-get install apache2

Related

Why does Symfony ask a valid token when I start a local server?

I have a symfony 5.1 application under development on my laptop.
This command failed:
symfony console server:start
Your token has been revoked, please login again
Then, the prompt purposes me to login, but I cannot always login, because I'm behind a firewall that rejects external access for some security reasons.
I tried :
to uninstall the local certificate authority,
to launch server without TLS,
to launch server with the command symfony serve -d (I got the same error message)
to launch application with different version of PHP (by using .php-version file)
It's perhaps because I tested a demo symfony cloud which is expired. So, I tried to remove all elements about cloud.
Without success...
As soon as I am offline, the server can be started.
As soon as I'm connected on other network I can login, but I want to launch this local server when I'm on our enterprise network. (And I'm tired to disconnect from network)
I had a problem like this. It helped me - symfony account:logout
Here I found the answer - https://github.com/symfony/cli/issues/281
edit by Alexandre: I only had to logout from cloud. Because of the firewall rules, symfony detected that Internet was available and try to get a new token, but fails because of firewall rules.
Now I only have to disconnect from cloud when I am connect on enterprise network:
symfony account:logout
If I got this right, you want to start your server only locally right?
symfony serve -d
The -d flag starts the server in the background. You might want to install the certificate in order to serve https:// with the following command: symfony server:ca:install. Both commands are issued inside the root directory of your project.
Once you're done, go into the root directory where you started your server and type in this command to stop the server: symfony server:stop
This should give you a local web server with your symfony project.
FYI: In case you have installed several PHP-Versions you might need to pick a specific one by saving a .php-version file to your root directory:
For any 7.x version:
echo 7 > .php-version
For 7.2 version:
echo 7.2 > .php-version

Using Apache-PHP as a Runner in AWS Cloud9

I am using AWS Cloud9 as my IDE for PHP web development. I have set up the environment on AWS with all the default settings and all appears to be working. I can use the "Run" and "Preview" functions in the IDE to run my .php file. However, it is using the "PHP (Built-in web server)" as default to run.
How do I run it through Apache HTTP instead? There isn't an option in the list of Runners. I can create one, but have no idea how to. I can see that Apache HTTP is available on the default EC2, though.
There is no option in the list of runners. You have to manually configure Apache to run on ports 8080, 8081 or 8082.
This page details how to run Apache on AWS EC2 Cloud9 server (port, root directory and htaccess): How to configure and run Apache server on AWS EC2 Cloud9?

Secure Linux Server Setup To Run Scripts via PHP exec()?

I'd like to run a script (phantomJS) via php exec() or shell_exec(). Everything is working fine on my development system.
I've installed phantomJS on my production server, and have run it successfully from the terminal after logging in via SSH.
But when I run it from PHP via exec() or shell_exec(), I get messages saying:
GLIBCXX_3.xx not found
GLIBC_2.xx not found
The support team at the web hosting provider is saying they don't know how to enable the server to access the script and still maintain security:
We're not familiar with the specifics of it, so we'll either have to
go through with disabling the chroot, but as our supervisor mentioned
this will allow all accounts on the server to account with each other
which is what the chroot prevents.
You can have your own system administrators look at the setup as you
do have root access, and see if they can devise a workaround, but on
our end this is the only thing we can suggest.
They are running CentOS, which is a 64-bit Linux OS.
I have very good experience with this web host up to this time, so I'm hoping there's a way to address this without changing hosts.
I have full root access to the account, so I can configure it in any way necessary.
Can anyone make some suggestions about how I might configure my production server to access phantomJS while maintaining a secure server?
UPDATE
Apparently my app is in a "chrooted environment" without full root access to GLIB on the server. The web host is saying there will be a lack of security if my php user is given full root access.
You have to remove your PhantomJS system call and create an API layer or a service that subscribes an MQ queue and then integrate it with PHP to avoid several problems, including the chroot limitation.

Apache could host a web server but "php -S" can't

I'm new to web development.
I installed Apache and PHP separately, not using XAMPP. Then I notice that after I create a PHP project, I could put it into htdocs folder and launch httpd from Apache and working fine. But if I use php -S localhost:80 -t my_folder, no matter which port I'm using, I can't access it via any browser or cURL.
My computer is running Windows 10 with Anniversary update and ZoneAlarm. I'm not quite sure if these information are related. Please let me know if I need to provide more information to identify the problem.
Thanks!

Cannot access Ubuntu web server from other device

I run the built-in PHP web server on Ubuntu 12.04:
php -S 0.0.0.0:8000
Locally, I can access my website on http://192.168.xx.yy:8000. However, I can not access the site from other devices in the same LAN on that same IP-address (the request times out).
I thought the Ubuntu firewall might be blocking the request and did:
sudo uwf disable
and
sudo iptables -F
but still no luck accessing my site form other devices. Does anyone have a clue on this?

Categories