Downsides of working with php's built-in server. - php

I would like to use the php built-in server just for dev environment, as opposed to starting WAMP everything, which consumes more resources, and since my site does not depend on any of the apache modules, I was able to do some work just fine, also using mysql from the command line.
The problem I have encountered is that, The built-in server is definitely slower compared to WAMP. Specially when doing database queries.
But what I would like to know is that, if the server is 100% reliable in-terms of building projects with it and directly uploading it to my server. Are there any other precautions to consider before attempting to use it as replacement for wamp?

Your observations are correct. PHP's built-in webserver is usually slower than Apache+PHP, but for quick & dirty testing on your machine it's fine.
I prefer it over full stacks, because I don't like having Apache as a Service on my system which always starts (as XAMPP does by default) manually starting/restarting a Windows Service on the other hand can be quite annoying (compared to a simple php -S). You also might have to change configs (e.g. when using vhosts), copy/symlink your project, maybe edit your /etc/hosts-file. All in all I think the built-in server is less hassle, than full stacks like WAMP.
I don't think #Areks concern weighs heavily against using the built-in server. If this really is a concern for you, you should account for different systems/configurations, e.g. by writing tests and using tools TravisCI, Vagrant and/or others. If you develop for a specific system you probably have a staging environment (as similar to the production env as possible) anyway.

yes, you must been warned that the php builtin webserver does not provide support for .htaccess, which is extremely useful (though i use it quite often for small tests)

Related

Best PHP search technique for heavy database like apache solr for java

I have used apache solr in my java project smoothly, but when i come to the end to solve a same kind of issue with PHP, this issue is arising:
To run apache SOLR, we need JVM to be installed on the server. But I don't know whether there is JVM installed in my client server or not. Because it is PHP apache linux server (not dedicated), I don't know whether I will get to access the console by which I can manage a bit.
Could any body tell me what is the alternative for apache solr for simple PHP environment?
Or please suggest me best indexing search technique for PHP.
Some options:
The worst solution, but probably the easiest if you want to remain in this (shared?) environment is to use a php solution like aitchnyu suggested. You could even use your own.
Shared environments often have access to mysql, you could search based off that. (Also not ideal, but possible)
Upgrade servers to like a virtual-shared server or use a seperate server for SOLR (I use ec2 free-tier which works well)
Not really an option but to answer your question, yes you can access the terminal through php but this is far from what you should really do because most shared servers disable access through php (in fact they didn't give you ssh access for a reason).
Also because even if they forgot to close this security hole (which happens sometimes) you will exhaust your resources (ram, cpu) pretty quick and you'll have to upgrade servers anyway.

Does Wamp Server differ from a normal internet hosting provider?

I am using wamp server to develop a website using php, mysql, PDO, html and css.
My wamp server is using PHP 5.3.5, MySQL 5.5.8 and Apache 2.2.17, I am also using InnoDB for transactions.
Considering that my internet hosting provider has at least these versions of php, mysql, apache, and supports InnoDB will the website I build act in the exact same way.
Is it possible to design a website in wamp and then expect several errors when going live? And if so how is this overcome?
Thanks.
As others note, there are many potential hiccups (but I view them as learning opportunities.) But I've done it this way for over five years and have yet to find a difference that wasn't easily overcome. Just stick to the middle of the road, use defaults as much as makes sense, and have fun. It's a great way to explore the platform.
There are many things that can go wrong, most of them having to do with how the web server and PHP are built and configured.
The simplest example is PHP's safe mode: there are many things that safe mode does not allow, and turning it off may not be an option if you are on a shared host. Another example is which extensions are enabled in PHP (your app may require one which the host does not have).
Of course this is all moot if you rent the whole server (or a VM), as in this case you will be able to do whatever you please.
For completeness, I have to mention that there might be platform-specific differences in behavior resulting from the same library (which PHP uses to provide some functionality) compiling into different behavior on different platforms (think platform sniffing in C with #ifdef). I have been bitten by this in the past, but the possibility is not large enough to worry about it beforehand.
A lot of the issues can be worked around by moving constants into config files, like Jon says. Some issues will be less in your control and harder to diagnose. For instance, the output buffer control may be configured differently outside the DocumentRoot you have access to. This can cause confusing problems when you try to write headers out when other content has already been sent out. Similar issues with the timeout numbers, etc.

Lightweight PHP server to bundle with application?

Does there exist some sort of PHP server that can be bundled with a locally-deployed application? It sounds wonky, but the end result is I can't use a remote web server to do anything. Clients will be downloading a package, and the plan is to use a Java backend that reads from a flat file. The flat file contains settings and is modified through a GUI written in HTML/JS, and this is where the server would come in. The forms in HTML should be able to submit to the server, which does a simple file write to the flat file.
Is there any simple, lightweight server that has that simple feature? When running the executable for the application, it would start the installation process for the server before moving the web GUI files to the appropriate locations.
Note that I'm doing this for a client, so I can't quite change the reqs and would rather not discuss their effectiveness. I would be ever thankful if people had suggestions for the server though!
You should check out roadsend php.
It can compile php scripts into a binary with its own build in server.
https://github.com/weyrick/roadsend-php
Nanoweb might do the trick for you, it's an HTTP server written in PHP. So long as the client has a PHP install you should be able to package things up nicely. In fact with a little extra effort you should be able to package up the PHP binary along with your code.
Nanoweb: http://nanoweb.si.kz/
Since PHP 5.4, PHP have a built-in web server and this works on any system where PHP binaries exists.
$ cd ~/public_html
$ php -S localhost:8000
I can't think of any lighter server...
http://php.net/manual/en/features.commandline.webserver.php
If you have a java backend, what do you need php for?
You could simply bundle a small java based webserver.
http://java-source.net/open-source/web-servers
A while ago I created a small web interface for Transmission (mac/linux bittorrent client) that needed to run a local web server with a custom PHP setup. I used lighttpd + php w/ fastcgi. When zipped up, I believe, it weighted in at <3MBs. If you don't need to run any PHP lighttpd is only a few MB's (and light on resources) and offers a very flexible configuration.
Source: http://svn.recurser.com/transmission/trunk/cocoa/
If you're already using Java, you may want to look at Quercus, an implementation of PHP and many common extensions in Java. It's a bit restrictive, but it may fit your needs.
Like unomi, I don't really understand the situation, but I'll assume you do...
Apache is by far the most popular and best-tested platform on which to run PHP, but in theory it should run on any web server that supports CGI/FastCGI. Alternatives include Lighttpd, nginx, and a few dozen others.
Whatever you choose, the key is to pre-configure it and keep it self-contained in its own folder. I think Apache would easily work here. Set it to port 43948 or something; remove all unnecessary modules; pare down the httpd.conf to its most basic requirements; allow only local connections; and write clickable scripts (.bat or .sh or what have you) to start and stop it.
This project is an interesting option...
An embeddable web server designed for (and written in) PHP. it handles
the control of the assigned port, setting common environmental
variables (such as $_SERVER, $_GET, $_POST and $_COOKIE) and calling a
function or method in your application to delegate the request.
The web server is able to be packaged in, and controlled from, your
application. Therefore eliminating the requirement that your user have
a standard web server installed and configured to use your web
application. Combined with a database such as a flat-file database, a
Berkley DB or SQLite, PHP Embeddable Web server can remove the need
for the user to have any specialised libraries installed, except PHP
(which is preinstalled in many Unix and Linux distros).
I have used this. It does work.. It is cool. As easy as...
# php server.php
You kind of have to get your hands dirty.. but it's TINY, a single file, and HIGHLY configurable... Word of warning though.. don't bother with this unless you know what a header, a class, a method, and an object, etc... And be prepared to apply that knowledge.

Using autotools for a LAMP application

I have a LAMP (Linux/Apache/MySQL/Php) application that I should release soon.
Even if I've never used it, I'm thinking about using autotools for it, to make the configuration and installation process easier (for the customer and for me, in the future).
Have you ever done (or thought) such a thing? Are there any drawbacks? Does it make a bit of sense?
Autotools is used mostly when you are trying to compile your programs for multiple target platforms. This applies for C code in general and checks stuff like available libs, size of data types, libc functions etc. So unless your program is written in C and you have a need for supporting all kinds of Unix flavors, dont bother with autotools.
If you are trying to build some kind of installation program for Linux, I suggest you look into rpmbuild (for redhat distros). Rpmbuild is easy to use if all you are doing is packaging files for easier distribution. A good tutorial is available here. One great aspect of rpmbuild is that you can specify requirements on the target system, for example: apache, mysql and even specific php-modules that you need.
For configuration and deployment, you can have a look at ant.
In my previous employment, we were using ant for deployment/configuration of a mix of perl, php, xml, xsl, unit test , Apache config ...
You have a build.properties file where you can put some default values and the customer will jsut have to create a local.properties where its values will overwrite the one from build.properties.
Also if you need to launch some scripts that are parts of the setup, you can also do that with ant.
simple idea
I may be stating obvious, but wouldn't it be easier for the sake of it, just to use
phpinfo();
?
From it you may mostly read everything - server version, PHP version, MySQL version and running PHP extension, compare it against what you need and advice to your client or their hoster that "I need this and that installed".

When to prefer XAMPP over a complete installation of Linux, Apache, MySQL, and PHP

In which cases, except development, would you prefer XAMPP over a complete installation and configuration of Linux, Apache, MySQL, and PHP?
Other than development, the only other time I use it is for demos - it's nice being able to take a "solution on a stick" to a customer.
I'd never consider it for a live/public site though.
I would say that XAMPP would be preferred over a complete manual install, whenever one is not confident enough, skilled enough, experienced enough, or educated enough to properly install, the OS, HTTP server, database server, and language system with all the mainstream security and stability aspects in mind, and compensated for.
Although I recognize that XAMPP is not perfect, it is, in 99% of cases, much better than anyone without proper knowledge could accomplish.
XAMPP is great for development because it's simple and fast.
It's not about lack of skill or knowledge to build a server. It's a simpler solution. It's great if you want to use PHP and MySQL. I wouldn't try to run a production server or try to add modules to it.
LAMP will perform 4x better
Benchmarks: http://www.formboss.net/blog/2010/02/hosting-php-linux-vs-windows-benchmarks/

Categories