I have hostgator cpanel web server. And I want to run exe file on it with php. Is it possible to do that? On window computer it is possible to start a program with the help of php command exec() with command line arguments. I'm looking for a solution so that I can do the same on my web server too.
The first thing you must understand is the difference between a web host and a dedicated server. On a dedicated server, you do what you want whereas a shared hosting server is shared among hundreds, sometimes thousands of users.
That difference is reflected in the price and justifies severe restrictions that need to be imposed by the host to maintain a good overall service level.
That said, functions of the exec() and system() family are also available for Linux, but you won't be able to run Windows executables on Linux without additional tools such as Wine which certainly won't be available on a shared host.
If your hosting sever running UNIX-like OS, Linux,
for example, it's not possible, you have to look for alternative binaries on that server.
Related
First, I am a complete novice when it comes to programming, so pardon my ignorant questions.
I hired two programmers to work on my project. They say they need a remote test server for testing things, before making it live, so that the changes are not live until all are okay.
My questions:
What are Remote Test Servers?
Why are they necessary?
Can they be set up with normal reseller or shared hosting?
How can you prevent the world from seeing what's on it?
Do you need a domain name for this?
How do I go about setting up a remote test server?
Any other comprehensive document to read up on this?
Thanks.
About Test Servers
A test server, in the case of websites, is used for changing around a website ( a copy ) without it being displayed to the public. This is done because, when a developer changes a webpage, the page will often seize to function or contain bugs due to incomplete changes of the source code. By putting these pages on a remote test server, the developers can use copies of the website - that are placed on this server - to make changes without affecting the pages that are being sent to the clients. You can actually configure this kind of server locally or remotely, depending on how you weigh the pros and cons.
Remote Test Server
You may set up a remote test server on sites like GoDaddy or DynDns. These services usually package a domain name with their server space. The benefit of this is that most of the 'set up' is already done for you. Also, as Silvertiger has pointed out, the service fees of this are usually quite low. This might be recommended because the massive amount of software your programmers may need is readily available on these servers. The only downside is that the only way to prevent the public from viewing this ( that I know of ) is to make it password protected. However, you may need public access anyway if your developers plan on working outside of your work environment.
Local Test Server
Alternatively, you may set up one of your own computer as a test server. The benefit of this is that the only fees you will have to pay are the costs of the computer ( it can be a low-end computer ). Since this computer would be connected to the network you wouldn't need a domain name, instead you will use an IP address assigned to the machine. It won't be hosted on the internet, so it's much easier to prevent other people from seeing it. The only downside is that your programmers must be within your network to work and setting this server up may be rather involved ( depending on the needs of your programmers ).
You will mainly have to download and configure all the appropriate software ( ie Apache, mySQL, PHP ) to get it working. This is typically done on a server OS ( ie Ubuntu Server ), but can be done on most operating systems. This process can also be made less painful by installing server software packages ( ie WAMP, LAMP, MAMP ), which include the basic software components your developers will need. I would recommend using Ubuntu. You may use Ubuntu Desktop if you'd like to keep a graphical interface during set up. Or, you may use Ubuntu Server - which saves a lot of memory by using a terminal-based user interface ( can make it more difficult to use ).
You may additionally consider adding a service called FTP to a local server. This is a service that allows you to remotely read and write to files on the server, and may be desired by your web developers for some of their editing programs ( Dreamweaver, for instance, can access files with FTP ).
As a side note, most developers should be familiar with setting up basic server software. In fact, it is usually part of the curriculum in webdesign. So, you may allow them to configure this software if you provide the computer for them. If you otherwise would like to configure it yourself, you may find some of the links following to be helpful.
Informational Links
General Web Servers
Wikipedia - general information on web servers
HowStuffWorks - information on how web servers work
Remote Servers
Godaddy - A common web hosting company from which you may use their service.
DynDns - ( as the aforementioned )
Local Servers
Ubuntu Server : A popular OS for servers
Apache : A popular HTTP server ( aka Web Server )
PHP : A commonly used language by web developers
LAMP : A package of basic server software for Linux ( Linux Apache mySQL PHP )
WAMP : A package of basic server software for Windows ( Windows Apache mySQL PHP )
MAMP : A package of basic server software for Mac ( Mac .. .. PHP )
Setting up LAMP : [Steps 1-5] A wonderful article on setting up a web server on Ubuntu.
A remote test server is a working php server that you can execute code on. It can be any server you have access to meaning that any reseller of hosting can provide you with a server but effectually it is just a web server you have access to. I presume you have a software that is asking for a remote test server like Dreamweaver or some other IDE.
I use my godaddy $8 a month hosting account account for testing..
I need to set up cron/automatic taks on windows(shared)/linux(shared)/wamp servers.
the problem is that the project is running on multiple environments.
so what is the best way to set up cron/scheduled taks ?
Actually what i need to do is check email servers for new emails and if something found save it to the local DB. If you have any alternative other than cron job then please let me know.
Thanks.
EDIT:
As i mentioned in the question i have multiple emails/filtering , so i need to run something on background to fetch data periodically. CRON in linux and Scheduled Tasks on Windows.
But the real problem is that i am doing it on a shared hosting ( or it depends the client ) so i cannot use CRON/Scheduled Tasks.
Ex : Project is installed on GOdaddy windows shared hosting , it is a windows server so no support for CRON(normally) and they wont allow to use Scheduled Tasks.
the question is : is there any alternative for CRON/Scheduled Tasks
?
Short Answer
I don't know alternatives to CRON/ScheduledTask which would fulfill your need.
I suggest you outsource the schedule to another server, see my possibilities below.
I came up with the following possibilities:
Shared hosting with CRON jobs (easiest)
Look for a shared hosting provider who lets you add cron jobs (e.g. through webspace management). HostEurope (german) would be such a host.
You own a dedicated (virtual) server
Given you deploy this project to multiple shared servers but own a dedicated (virtual) server for yourself:
Make your script publicly available but guard it with a strong authorization mechansims. (hard-to-guess request token, white-list certain IPs as callees, ...).
Set up a cron job on your own server which calls the script on the client's webhost.
You don't own a server
As the last possibility but you don't own a dedicated server.
Setup a virtual machine at some cloud provider (e.g. OpenShift) and add the cronjob there. Don't use this instance for other jobs and it should fullfill your needs perfectly (Reference: https://openshift.redhat.com/community/blogs/getting-started-with-cron-jobs-on-openshift)
Requirements don't meet infrastructure (likely!)
Your client/project has requirements which don't fit a shared hosting environment. You are strongly encouraged to get a hosting plan fulfilling your true needs. Price differences between shared hosting and first virtual servers or dedicated hosting aren't so steep that investigating is out of question.
As everyone else suggested if this is a web page you can use wget to run it.
If it is a CLI script you will have to run it with php /directory/filepath.php
If the actual question is HOW you are going to periodically run it you will have to use
cron on *NIX and scheduled tasks on windows server.
If you want to automatically install the cron you will have to check the OS and act depending on whether the OS is windows or *NIX.
A google search will give you results on how to do it in both environments.
Edit after reds clarification
As Samuel Herzog pretty nicely says, on shared hosting you (usually) have a control panel.
Most well known for linux are:
Cpanel: http://www.siteground.com/tutorials/cpanel/cron_jobs.htm
Plesk: http://www.hosting.com/support/plesk/crontab
Webmin: Setting up a cron job with Webmin
And for windows I only have some familiatiry with plesk for which the procedure is the same as before.
If you dont have control panel but have shell access (linux) you could follow this tutorial.
If you dont have control panel but have remote desktop (windows) you could follow this tutorial.
If you dont have any of the above you should follow Samuel Herzog suggestion about a vm on a cloud provider or consider upgrading to a VPS or a dedicated server.
and I've read a bunch of related posts here on SO and have gotten the following ideas here:
First, my website is shared-hosted at 1and1.com. And my objective is to call exec() in my PHP code to run ffmpeg to convert short videos (30 seconds) from format A to format B.
1) Now, because of my shared hosting situation (the 1and1 web server my website runs on is shared with other 1and1 customers) -- 1and1's administrator probably has their server in 'safe' mode, so that my desire to exec() in PHP to do the ffmpeg conversion of a video -- will fail.
(Supposedly there is a 'safe mode' shared directory but that's a hoop to jump through with 1and1).
2) And even if 1and1 does not mind if, from my PHP code, I call 'exec( ffmpeg -i yada yada)' for converting between video formats -- I've heard it's unseemly to do that. I'm led to believe I need a dedicated server and not a shared server. Which sounds weird because (a) the web site will never scale to massive # of users, and (b) when I run ffmpeg on my 2 1/2 year-old laptop, Windows Vista, running Xampp as my localhost development web server, the conversion happens like right now. Very fast.
Are the above restrictions correct ('safe mode' on shared web hosting, running ffmpeg is a no-no without a dedicated box)?
I'd like to think that 1and1 would not even notice if my web site did a few (say, under 20) short-video conversions per day.
Also if anyone can recommend the proper web hosting company for my situation I would be in your debt. Thanks.
I believe safe mode would allow you to use exec because 1and1 would have you chrooted so any program you run would not be able to access other users. But, you might want to check the AUP to see if the prevent those kind of processes (that consume a lot of resources).
For the best performance you should use a VPS server in which you can control your php environment. ffmpeg has potential to be very resource intensive, so for best performance a VPS/dedicated would be best. Also, using ffmpeg on shared hosting would impact performance on other sites as well.
Any VPS would do, but because you asked for a recommendation, I would recommend BlueMileCloud.
PS: You should never call a process directly from exec. You should add it to a queue, so the script does not wait for the process to finish and cause the site to hang.
I need a simple "development" server for php, e.g. not apache.
In a modern environment, such as node.js, I can run node server.js inside any folder, and it will run as a server running the site specified by server.js. I can then run another node process from a different folder, and the two servers will never interfere or get in each other's way.
Is there a similar setup for php?
With apache, it seems to me that I need to "configure" the server ahead of time; I can't just drop into some folder and serve its content on some arbitrary port.
I want a command that I can use to run a php server from inside some folder, with minimum amount of configuration, for the purpose of being a development/testing only server.
For instance, suppose this server is called sps, then, I should be able to:
cd ~/code/proj1
sps
Perhaps it could require a simple config file, sps.conf that specifies the port number the server should listen to, plus maybe information about the database connection; but nothing more.
Does such a tool exist for php?
With the current version of PHP (< 5.4), you indeed have to configure a webserver (Apache, nginx, ...) to serve the directory in which you'll have your website -- the directory in which you'll work.
Generally, though, you'll only have a couple of websites, which means you won't have to re-configure your webserver too often.
And if you often have to create / test some small scripts, just create an Apache VirtualHost that points to some tests directory, in which you'll put all your test scripts (I have exactly that on my computer).
With PHP 5.4 (currently in alpha -- so not to be used on a production server just yet ^^), you'll have a built-in web server, which should pretty much answer your question.
try XAMPP Lite version http://www.apachefriends.org/en/xampp-windows.html
I'm trying to implement a socket server that will run in most shared PHP hosting.
The requirements are that the Socket server can be installed, started and stopped from PHP automatically without the user doing anything. It doesn't matter what language the socket server is written in, as long as it will run on the majority of shared hosting globally.
Currently, I've written a Socket Server with PHP that implements an Object Cache:
http://code.google.com/p/php-object-cache/
source: http://code.google.com/p/php-object-cache/source/browse/trunk/socket.class.php
However, PHP has to be compiled with sockets support, and not many servers run with PHP sockets support.
My real question is: What language should I implement the socket server in, and have maximum platform support and be invokable from within PHP.
In other words, what scripting language is the most common on PHP enabled Servers?
Or do I have to write the socket server in a compiled language to have it works across all servers?
Lets leave IIS out of the picture at the moment, just Linux servers. I don't think many PHP sites are running on IIS...
edit:
Sorry I think my question is not clear.
I'd like to know, what languages is best suited for creating a socket server given the following requirements:
The language must exist in shared hosting, alongside PHP running in Apache (not CLI).
The sockets support must be enabled natively, not via a required extension.
PHP must be able to write the deamon to file as well as start and stop the deamon.
I'm not asking for a solution for a single server. It has to run natively on the majority of shared hosting servers.
Any server can be stopped or started by PHP under Linux. Of course, if you are running a server which accepts sockets from the internet, then you can just connect directly to the server and tell it to shutdown. No need to go via PHP!
As for "starting a server from PHP", well, under Linux, anything can be started from pretty much anything. Just shell out to start the process and have it drop into daemon mode.
I'm a Perl fan myself. Not surprisingly, there's a
Perl Daemon library available.
If your hosting provider offers Perl script support, then you probably have permission to use "system" or backticks command. Then you can very likely start a daemon. However, you will need to use a non-privileged port (over 1024). Also, you should ASK THEM FIRST! They may not appreciate you tying up ports on their server. This is very definitely something you should discuss with your hosting provider.
It really depends on what the install requirements are. Often the easiest and most standard way to write a socket server is to write an inet.d service. This is a standard daemon on my unix machines, and it will fork a process and handle the socket level details. If you want your service to run on port below 1024 on Unix, this is one of the easier ways to get it done. However, the initial install requires root to configure inet.d.
If you shared hosting allows PHP to do an exec call, then you could start the daemon that way. Keep in mind though, it'll need to run above port 1024. You next need to decide if your program is going to be multi-threaded or multi-process. Typically Java programs are multi-threaded, while an Apache instance is normally multi-process.
Lastly, the host may have a firewall in place. This helps prevent shared hosting accounts from becoming part of a bot-net. If the firewall rules don't allow connections to other ports, you won't be able to connect to it remotely.