I've seen people uploading .php files that give them command line access to a server by loading http://example.com/cli, similar to SSH, could you give me an example?
A client bought a shared hosting account from a web host that does not allow ssh and forces me to use cPanel. I abhor cPanel, it cripples my productivity by making me click around and wait for it to load a bloated gui. What I hate more is that i have to download files and then upload them to the host instead of a wget https://wordpress.org/latest.zip
I'll just ignore the unexplained downvotes this question received and keep it up because this might help someone else in the future:
Most people I've seen have called it a web based shell, or a php shell. It lets you execute arbitrary shell commands on php servers. Here are a few projects I've found:
PHP Shell: http://phpshell.sourceforge.net/
b374k: https://github.com/b374k/b374k
Just be sure to use a password, and to delete the shell when you're done so that someone doesn't accidentally find it in the future.
I am making an application for school but i need to be able to manage some Services running on my Debian 7 machine. I'm running "nginx" and "PHP5-FPM" so PHP 5.4. but how can I restart or stop for example "nginx" from my PHP file? i tried
exec("/etc/init.d/nginx stop");
Also I tried
shell_exec("/etc/init.d/nginx stop");
but no result php returns me:
Stopping nginx: nginx
Thanks in advance
You need to be root to restart these services, and unless your web service (like Apache) is running as your site(s) as root, this isn't going to work. There are a couple of options at your disposal, the best one would likely depend on your situation.
You can create a two-layered approach where the front-end (run by your web server) issues the commands, and the back-end is a service running as root that executes them. This could also add a layer of security as the back-end could sanitize the commands before they're executed. The communication between the front-end and back-end could be any number of things, such as a file that the front-end writes to and the back-end reads from every few seconds, or you could go with WebSockets and make it real-time.
You could run an additional instance of your web server as root that handles just this task. You would definitely want to run this over SSL, and it's somewhat risky since if someone could inject code into one of your pages, their code would be running on your server as root.
In my application i have to deploy my application on client system.
So is there any way to run my php application without installing xampp...
Because the client should access it as a readymade app without installing anything...
This is the description of my project...
We have to develop an application where the client will have our application he will connect to remote server
Then he will download the data from remote server...
Then he uses that downloaded data using that app
Here my requirement is the user may not have the knowledge of installing the xampp...
So is there any way to run the application in user system just by copying some files
U may suggest me a one click solution (like using installer which will include installation of xampp and copying my data into user system)
I really dont want to use any external software to render no database PHP pages so I did some digging and found that if you run php -S localhost:port in your working directory you basically start a server there.
S is a capital S and not s
I'm a big fan of server2go. I've used it to deploy PHP applications on CD/DVD. It comes with MySQL and is relatively easy to configure. I've even replaced their splash screen with my own so no one knows I'm using it. It's donationware, but I was impressed enough to donate:
server2go-web
With this application, you don't have to install all that other stuff. It's self-contained in this executable and directory.
EDIT: To clarify, server2go does not install anything on the client machine. It runs as an exe only when you specifically want it to. When you click on the .exe file, it launches your PHP application in a browser window, then you can right-click on the server2go icon in the system tray and close it when you're done.
EDIT2: One gotcha: if you want to save data to the MySQL db on the client machine, you'll need to copy serve2go to a directory on the client machine or run it on a writable USB stick. If you run this application off CD/DVD, it will be able to read data from the database, but not write.
The better way is to use PHP Desktop Application. It will allow you to run your PHP Script like a Desktop application and you don't need to install Xampp or any other web server to run.
PHP Desktop Application
After downloading the .Zip file unzips it to any folder that you like. After unzipping, Go to the folder, and there you can see a folder "www". Delete all the files contained in it and move all your php script to it.
Once you moved all your files into it. Run the .Exe file named "PHP desktop-chrome"
It will open your PHP Script really like a Desktop Application.
This script doesn't require any kind of server software like Xampp, Wamp, Etc installed in your PC.
You can either host the php application or install the application into one system as server and call in client system using the ip of the server system like the following
http://**ip address/php file name
If you don't want your client to install anything then you should create Client Server architecture, there is no another way.
PHP Application are not meant to be deployed on multiple clients. It's meant to be deployed on a webserver (your own server with sth. like IIS or XAMPP) so the clients can access it via their browser and doesn't have to install anything more.
If you want to deploy applications on the client pc's i recommened an other programming language like Java or C/C++.
I simply used xampp zip version so i copied my application into htdocs and the whole xampp is given to the customer so he simply running the application eazily without installation.
Make sure you have installed php from https://www.php.net/downloads.php. Once installed add it to path. Lastly type php -S localhost:8000
PHP needs to be installed on the machine it is running at in order to make sure it works. Since the app may grow and may require extension installing, PHP upgrading over time, hosting this on a client machine is not a very easy task in terms of management. You may want to host your project on a server and write a small bash script sending requests to the API.
If, for some reason you cannot host this on a server where your clients would send requests via the bash scripts, then you may want to install only PHP. If it does not need to listen to HTTP requests, then you do not need a server, you can just implement the PHP application and create a bash script so the user will be able to run it from the UI of their operating system.
No, you need some kind of server - Wamp, Xampp, etc.
You can host it online, and then he can just browse it from his PC.
I'm very new to socket programming, but do lot of coding with php.
I have tested some socket server example codes and worked fine with localhost. I use CLI to run the server. But my concern is how do I run the socket server .php file at my hosting server? Do hosting providers normally give access to CLI to run the servers? How do I make sure my server is always running? If the hosting server is restarted, what happens to my server? In case, my server crashes (whatever reason), do I have to run it manually?
Can someone help?
If you are talking about a hosting server I expect you are talking about shared hosting. In that case it will be difficult to keep it stable if you even manage to run the service etc. I would suggests using at least a VPS for it. That way you can run it in the background, automatically start it at reboot but also install software to check the process and restart it if it failed.
For example: Testing whether the reboot startup works is impossible at shared hosting.
I don't know if your provider give you ssh access. Some provider do it but this are managed server or root server.
Then you can run your script over the CLI.
When you can run your server over CLI and when you have enough rights you can insert the script to the runlevel. And there is something that is called "shebang". With this you can give your script direct the php interpreter and run the script without the php command before.
php test.php or /usr/bin/php testScript.php
You can run direct run your script with test.php or name your script only testScript.
When you put your script to /usr/local/bin (for debian) you can run it everytime over the command like the php command.
Edit: I have forgotten something. For this solution you have to copy the /etc/init.d/skeleton to /etc/init.d/runPHPSocketServer for example and change the script values on top. Then you can insert it to the runlevel.
#: testScript or runPHPSocketServer start
When the script is under a executable directory you can insert it to your system runlevel.
#: update-rc.d runPHPSocketServer defaults
So you see there are some solution but for the most solutions you need ssh access.
I am working a LAMP web app running on Ubuntu 11.10.
I followed instructions on the web to harden my apache, php and mysql.
I have a PHP script which work fine when I run from the command line under my own id. But when I put the scripts into the web app framework, it can't not even open a log file to write (in /tmp) and it can't read other files in /var/www/myapp/html as well.
I used Ajax to retrieve file contents on the server and then serve those files to the browser. So my url will look like: "php/myphpscript.php?arg=.......".
My directory structure is
/var/www/myapp/html|php|js|cfg.
I know this problem has something to do with permission, security but I am quite at loss.
Can someone describe what I need to do here?
Thanks,
I suspect you copied the files with your username, but apache executes as user www-data an thus has no access to your files. Either change them to belong to the apache user, or if you are the only develper on this machine, cahnge apache to run as you.