I've just finished a web application written in PHP. I thought it was as easy as compressing my .php files and dumping my database in order to decompress those files in the "production" server, creating the database structure and database user, but it doesn't work. Several php files have include directives that are not working, I was using "relative" paths in those directives, I've tried $_SERVER[DOCUMENT_ROOT] and fixed the trailing slash issue in that parameter and still is not working. Any suggestions? Maybe you know some "tips" or "instalation-patterns" for PHP web applications.
Check the include_path on the production server compared to your development machine-- the server may be looking for files in different locations compared to your own box.
Regarding deployment there's two projects that I've come across that might be of some help (unfortunately, I've not used either; both are on my ever-growing to-do list):
Phar are PHP Archives; basically, a way of distributing apps in a .zip file that can be run without being unzipped
Phing is a build tool similar to Apache Ant. It can be used to automate the deployment, say if you need files copied to many different locations.
Are you using the same version of php (and host operating system) on the new server as you were on the old one?
PHP can parse your code differently in different version and installations.
PHP has some different behaviors between versions. Also, depending on the setting in your development php.ini file and the one in the production environment, you could see massive differences as they usually have very different security setups.
Related
I am currently working alongside a project team for the development of a website and we are using SmartFtp for file sharing.
Does anyone know how to compile/edit php files through SmartFtp? I.e. using apache for compiling and atom for editing.
Please note: I have already tried copying the files into the htdocs folder within xampp but had no luck. The php files did not successfully copy into the htdocs folder.
Thanks again
Fair warning...
This is a terrible way to host a project. Each developer should have their own isolated project installation. Even though you only have a few developers, it's only a matter of time before you get a collision and somebody loses work.
Using FTP is also a terrible idea. It is completely insecure.
That said, you've got a couple options:
If your dev server is a *nix flavor, you can probably use SSHFS to mount the remote directory on your local machine. This will allow you to edit the remote files live, as if they were any other regular local file. This is secure and relatively easy to set up, but you may find it a bit too slow for anything but small projects.
Use FTPS/SFTP/SCP to push files to the remote server when you save them locally. I'm not terribly familiar with Atom, but many IDEs (like NetBeans and PHPStorm) can be configured to automatically FTPS/SFTP/SCP push changed files to remote servers. Just save locally as you normally would, and in the background, the IDE will perform an FTPS/SFTP/SCP push. Do not use FTP. If your server has FTP configured, it probably also has SFTP and/or FTPS configured.
Create your own development environment. Host your own site on your own machine so that you don't collide. You can run Apache/Nginx/PHP/MySQL directly on your machine, in a virtual box, or even a docker container. This is the best and most flexible option, but also requires the most effort to get running.
This should be a comment, but its a bit long.
I am really confused by your question.
how to compile/edit php files
PHP uses a run-time compiler. Are you talking about Roadsend or HipHop or something else?
development of a website and we are using SmartFtp for file sharing
Presumably you don't give a damn about your code integrity, managing conflicting code changes, version control or the security of your development environment. It's 2017. FTP was way past its sell-by date before the turn of the millenium.
compile/edit php files through SmartFtp
It's an FTP client. Just one of many things you don't use to compile or edit files (others include an avacado, a tennis shoe, scissors, a sunset...).
Presumably you are using this client to connect to a server - which you've told us nothing about. You probably want to do the collaborative bit of your code management (if that is what you are asking) on the server.
(from comments)
Development sever with multiple people pushing edits ad hoc while they code through an Ftp server.
That's not a "development server" that's a recipe for code armageddon.
Another way I could ask this question is:
How do I set pages served by Apache to have higher privileges? This would be similar to me setting an Application Pool in IIS to use different credentials.
I have multiple Perl and Python scripts I am publishing through a web front end. The front end is intended to run any script I have in a database. With most of the scripts I have no issues... but anything that seems to utilize the network returns nothing. No error messages or failures reported. Running from CLI as ROOT works, run from WEB GUI as www-data calling same command fails.
I am lumping Python and Perl together in this question because the issue is the same leading me to believe it isn't a code issue, it is a permissions issue. Also why I am not including code, initially.
These are running on linux using Apache and PHP5. Python 2.7 and Perl5 I believe. Here are examples of apps I have that are failing:
Python - Connecting out to VirusTotal API
Perl - Connecting to Domains and Creating a Graph with GraphViz
Perl - Performing a Wake On LAN function on a local network segment.
So after I posted this I looked into Handlers like I use for IIS. That led me down the path of SUEXEC and through everything I tried I couldn't get Apache to load it. Even made sure that I set the bits for SETUID and SETGID.
When I was researching that I ran across .htaccess files and how they can enable CGI scripts. I didn't want to put in .htaccess files so I just made sure the apache.conf was configured to allow CGI. That also did not help.
So finally while I was studying .htaccess they referred to ScriptAlias. I believe this is what solved my issue. I modified the ScriptAlias section in an apache configuration file to point to my directory containing the script. After some fussing with absolute directories and permissions for the script to read/write a file I got everything to work except it isn't going through the proxy set by environment http_proxy. That is a separate issue though so I think I am good to go on this issue. I will attempt the same solution on my perl LAMP.
I know this may be a long and general question but I am struggling with it for the past two days and have achieved nothing.
I am a C# .net developer and I use Visual Studio IDE for my development which does all the back-end work for me when creating projects, setting virtual hosts, publishing the project and etc.
Now for some reasons I have to do a project in PHP and I chose PhpStorm as my IDE. I installed XAMPP and the Apache server is working ok, and I set its' php executable as an php interpreter in PhpStorm.
I don't want all my projects to be in xampp/htpdocs so I choose another location (d:\projects\phpStorm\<name of the project>) as my working space when I first created a project.
I installed xdebug using the tutorial it gave me:
Download php_xdebug-2.4.0rc4-5.6-vc11.dll
Move the downloaded file to C:\xampp\php\ext
Edit C:\xampp\php\php.ini and add the line
zend_extension = C:\xampp\php\ext\php_xdebug-2.4.0rc4-5.6-vc11.dll
Restart the webserver
And I can confirm that it is installed using phpinfo() in a php file located in xampp/htpdocs.
My problem is with the debugging. When I click Run->Run in an opened php file in PhpStorm, it uses a free port and opens the php file with a url like this: localhost:port_number/<name of the project> and everything is ok.
Now I followed this tutorial to configure the xdebug. In step two, when I go to Run->Web Server debug validation, fill the Path to create validation script with d:\projects\phpStorm\<name of the project> and Url to validation script with localhost:port_number/<name of the project> (as mentioned above) and click validate I get this information (and an error in the last line):
Server Name: PhpStorm 10.0.3
Loaded php.ini: C:\xampp\php\php.ini
No debug extension is loaded
Follow this links to configure Xdebug or Zend Debugger. If you have
already configured debug extension in php.ini file check possible
reasons why it was not loaded:
You forgot to reload web server after changes in php.ini file.
You are configuring debug extension in the wrong php.ini (see the
loaded php.ini files below).
There are errors on attempt to load debug extension, e.g. version
incompatibility.
I want to know what should I do?
I really really want to set my projects in another location other than xampp/htpdocs to organize them properly, just like I do it in Visual Studio. So please don't suggest solutions involving me changing my working directory.
Thanks in advance.
P.S.: In JetBrain's tutorial, I see that the xdebug's IDKEY is PHPSTORM whereas mine is my pc's username, it it ok?
I really really want to set my projects in another location other than xampp/htpdocs to organize them properly, just like I do it in Visual Studio. So please don't suggest solutions involving me changing my working directory.
Well you're really going to hate this then, but unfortunately Apache (which is what php runs on) only recognizes htdocs (or public_html, or www, depending on what specific server you are running, but anyhow in your case only htdocs) as a valid directory for php execution. Sooooo...
That doesn't really mean this is hopeless, but you might have to jump through some silly hoops to get it to work this way.
Option 1
You may have some luck creating a symbolic link from .htdocs to your projects folder from the command line:
ln -s C:xampp/htpdocs d:/projects/phpStorm
If you're on windows, this probably won't work. It also likely won't work between drives. It also may not work depending on your Apache configuration in XAAMP.
PROS: If it works, will do exactly what you want.
CONS: Probably won't work, if it does, will require nightmarish levels of config fiddling
Option 2
Use a remote development server, and sync over FTP with your IDE. I'm not super familiar with PhpStorm, but I can pretty easily do this in Netbeans or Eclipse. This is a good option when you need a local archive of a project retained. You might be able to set up an FTP server on your machine and accomplish this, however you are going to wind up with two copies of your project; one in your projects folder and the other in htdocs.
PROS: Your projects stay organized where you want them without much issue.
CONS: File duplication, they will have to be in htdocs anyhow for Apache to run php
Option 3
Accept that the technology is not designed to work this way and just put everything in htdocs where it belongs. Resisting the way technology works because you are used to a different workflow is how design flaws and really bad bugs happen. Use it the way it was meant to work and don't be scared of learning new things.
PROS: No conflicts with the XAAMP stack whatsoever
CONS: You specifically stated you don't want to do it this way, but this is really the best way
Option 4 (Don't do this)
Install PHP as a globally accessible command line utility across your entire system, and consequently get all kinds of crazy viruses and errors that you may not be able to fix ever.
PROS: Minor alleviation of aggravation with foreign workflows
CONS: All of the things. The worst things.
Option 5 (probably not going to work)
Try using VirtualHosts. There's a bunch of caveats with this though. First, doing this between different drives is nearly impossible to configure correctly due to security policies in your operating system that are difficult to overrule. Second, if you're on Windows (I assume you are if you are using XAAMP), you need to do all of the following:
-In apache.conf, you need to enable your hosts file.
-In the vhosts file, you need to create a new vhost.
-In the windows hosts file, you also need to create a host, because for whatever reason windows likes to arbitrarily add redundant steps. On every other OS, this step is not neccessary. Also, you need to run your text editor as administrator to even do this at all.
-Restart apache when it's all set up
-Pray your machine will let you do this between drives (C: -> D:), or not take a million years to enable.
I'm used to using python's virtualenv tool to create separate environments that can mimic deployment environments for projects I write.
Now, I'm going to be working on a php project and I'm wondering if there's any equivalent to that? Specifically I'm hoping to be able to run one virtualhost on apache with one (older) version of php, while everything else runs on the normal up to date version.
My development machine is running ubuntu 11.04, so solutions that work on that platform would be preferred.
Assuming that you are using mod_php, there is no way to load multiple different versions into the same Apache instance. You can run multiple different versions if you're running PHP as CGI or FastCGI, but this will itself introduce some differences in behavior from mod_php.
Another alternative to virtual machines is docker.
As loading different versions of php within apache with mod_php seems not to be posible, the easiest way of mimicking deployment and development setups will be with a virtualmachine, which you stated you would like to avoid.
One way of making the burden of vm's for developers a bit easier is to use something like vagrant. With two files (the vagrant file, and the chef/puppet file) you can "version" your vm's, easily create them and destroy them for each project and when needed.
virtPHP is a tool for creating and managing multiple isolated PHP environments on a single machine. It's like Python's virtualenv, but for PHP. (README)
https://github.com/virtphp/virtphp
You might be interested in this: https://github.com/phpenv/phpenv
(Haven't coded php in years, so this might be outdated)
As far as I remember you just had to point to another directory where your libraries reside (include PATH), using something like:
include_path = .:/usr/local/lib/php:./include (this goes in php.ini, default libararies)
and in your php files:
ini_set("include_path", ".:../:./include:../include");
PHP never really had a robust packaging system and library repository like perl/python/ruby has, PEAR was trying to move in that direction but it is very closed in comparison and was hard to configure in multiproject environments.
Phark is trying to build a brew/bundler port for php, https://github.com/lox/phark, although it's not deployment ready.
As of now, there is no out of the box solution to this problem. The only solution which comes close is Vagrant and puPHPet.com as discussed here: https://drupal.org/node/2055947
Why can't we have an environment like python's virtualenv or ruby's rbenv? It makes up a nice open source project. Multiple instances of PHP can be handy if we want to test out some libraries in sandboxes rather than globally. We can install dependencies for different projects using a package manager like Composer.
Cloudlinux with PHP Selector has this for ages. It is integrated with popular control panels like CPanel, DirectAdmin etc.
Each linux account can have its own version of php and select any extensions they sit fit.
https://www.cloudlinux.com/php-selector
I am strictly a LAMP dev but an ad agency I work with is courting a government agency whose RFP requires that their site be delivered via a Windows server.
What advice do folks have on this? Are there specific pitfalls? It seems like I have heard that file uploads and folder permissions are very different on Windows servers.
Any advice would be greatly appreciated.
IME, IIS can behave very oddly at times.
The permissions model is primarily ACL based - so its certainly possible to design a system which mimics the way Unix works - but (just as with Unix) get the permissions model right - and don't tinker with permissions / ownership in your code.
And of course you'll get yourself tied in knots if you try to move up directory hierarchies and cross over 'drives'.
Add to that a complete absence of the services you might invoke via popen(), and the POSIX tools.
Yes, people keep telling me its a nice place to visit but I wouldn't want to live there.
OTOH, a self-contained set of PHP files will run quite happily there.
PHP on a windows server is definitely trying on your patience. Problems that I've run into are making sure that IIS is configured to use the correct php.ini file, and as you said, writing to files on the server as well as folder permissions.
That being said, if you can get it working correctly, it's not a bad production environment.
I would suggest getting your dev environment as similar as possible to what production will look like. That way you run into as few problems as possible when you deploy.
I can see some pitfalls for using PHP on IIS
Since IIS is multithreaded unlike
linux which is multiprocess. Some
PHP scripts might be unsafe.
Because of this PHP should be installed and
run as a CGI extension. CGI is
slower than IIS's ISAPI and worse
when compared to Apache's mod_php.
Another pitfall I can think of is URL rewriting. IIS, versions below
v7 do not support url rewriting.
Configuration of PHP with IIS is really a pain. But when you do configure it, make sure you use the same configuration, exact mirror images everywhere you are developing because a lot can go wrong with just one glitch.