Sqlite3, apache users, and easy installs - php

I'm writing a small app that needs to have a super easy install process. Version one used a csv file instead of a database, so priority #1 for v2 is getting sqlite going instead. I've used sqlite a lot with Ruby, and love it, but this is my first time using it with PHP.
Basically, in order to get SQlite3 to be able to insert into the db, I needed to make both the database.sqlite3 file and the folder containing it owned by the apache user. From reading the docs, this seems normal.
However, apache isn't always going to be running as the same user. Here, it's 'http', but I know on Ubuntu it's 'www-data', right?
So, is there a good way to detect the username Apache is running as, and changing it, or am I going about this wrong? It needs to be something I can just put in the install script, as the people who use this app don't know or care anything about tiny details like this.
Thanks.

I believe you're going at it from the wrong side: you need the SQLite db to be writable by the PHP script, as I understand the matter, and this might not be the same as the Apache user.
If PHP is installed as an Apache module it will inherit the Apache user, but a much more common case on shared servers is to have PHP set up as CGI under suphp or phpsuexec, so the scripts run with the permissions of the user himself.
I'd suggest you write an install.php script to create the folder and the database, so both will inherit the script's permissions, no matter which user it is. Look into the manual for mkdir() and sqlite_open(). If nothing else works there's always chmod().
As you specifically cite SQLite v. 3 you may want to check the server version with phpversion(); in PHP 5.3 sqlite_* functions do work with version 3, PHP 5.2 and below understand version 2 instead. To use version 3 in PHP 5.2 you must use pdo_sqlite.

Related

Laravel 5 Heroku Local doesn't work

I've successfully deployed the Laravel application to Heroku.
It works online.
But when I try to run "heroku local" I get:
vendor/bin/heroku-php-apache2: No such file or directory
Which makes sense, since looking into "vendor/bin", the only thing listed is:
psysh -> ../psy/psysh/bin/psysh
So, where's my heroku-php-apache or how do I fix this?
You should have these lines in your composer.json
"require-dev": {
"heroku/heroku-buildpack-php": "*"
}
be sure to run composer update after you add them.
After extensive research, trial and error and talking to the Heroku Support team, I found out that, although Slow Loris's answer was a part of the process, the following answer was given to me by Heroku's Support:
To cut a long story short, heroku local is not officially supported for PHP >applications. The reason is that unlike all the other languages we support on the >platform, PHP has no web servers written in userland. Instead, we use PHP-FPM >together with Apache or Nginx, and the boot scripts (vendor/bin/heroku-(php|hhvm)-(apache2|nginx)) dynamically inject the correct configuration for port >binding and the FastCGI comms sockets.
This works with vanilla PHP and Apache builds, provided that:
1) the current user has all the correct permissions (in your case, >/var/log/apache2/ isn't writable);
2) the correct proxy modules are loaded in the main httpd.conf;
3) the main httpd.conf doesn't bind to a port at all, or at least not to one >under 1024 (which are reserved for superusers).
The main config also needs to be handled by each user on their own, because >sometimes, the modules to be loaded are in libexec/, sometimes in >lib/apache2/modules/, and so forth. Just too many variations; otherwise, we could >ship a full Apache config to users and the experience would be much better.
But the problems don't end there. FPM does not work at all on Windows, and on >most Linux systems, httpd is not a command that works; instead, apache2ctl >handles starting and stopping, and thus, running a server in the foreground is >not possible. In the end, there are simply too many possible permutations in >system configs that make it impossible to ensure every user has a great >experience.
It's simply the current reality in PHP land. Ruby, Python, Node, Java all have >web servers that are written in each respective language, and you don't need >external servers. Which also makes it possible to stream file uploads, handle web >socket upgrades, and so forth. Maybe with PHP 7 we'll see something like that >emerge soon (in PHP 5 it's simply not feasible at all, because a fatal error >kills the engine, so your web server would be gone too).
I know this question is a little dated but I recently deployed a heroku app for the first time and was unable to get heroku local to work for me. I'm on the current branch of Laravel which is 5.8, I am also on Windows 10 using VS Code. I searched all over trying to rectify this issue and could not get it to work no matter what.
I did come up with a solution to be able to work on this locally with only a few lines in terminal.
In VS Code, I used gitbash terminal, once in my heroku project folder composer require laravel/homestead --dev, once that is complete, then we need to install homestead, vendor/bin/homestead make, and then once that is complete, simply run vagrant up and your app will be accessible through localhost:8000.
Docs - https://laravel.com/docs/5.8/homestead
Hope this helps someone!

How to bundle a php application with 1 click run/install

I create php application for small businesses. Some of the clients may prefer running the app on a local server, therefore my requirement is to create/bundle an app with apache/mysql/php with all the necessary confirguration and one click executable (be it a batch file) such that when the user opens it, it runs the apache server on some port say localhost:1234 and mysql as well.
and opens up the application in the default web browser.
To be more exact, Im looking for something like http://www.simpleinvoices.org/go, check their Simple Invoices for Windows which come budled with apache/php/mysql.
P.S - Im not sure if this question should be at SO or Superuser.
If you actually want to install a web server and a SQL server then Lars' solution would be a way to go. On windows you can generate a .msi installer containing the dependencies you need (like WAMP). An installer executable would be a cleaner solution than a batch file in my opinion, as it will also provide the user with an option to uninstall your software if they wish.
If you want to distribute your application in a standalone version, then you might also want to check a solution like NuSphere's PHPDock - http://www.nusphere.com/products/phpdock.htm
I had the same challenge and came across Uniform Server:
http://www.uniformserver.com/
You download it, add your application to it, start it and everything runs. Lovely.
Superuser would have been better. But depending on your requirements, you should just create a package to install. On windows, package it with WAMP, on linux, package it with either one-click-install or creating packages for the two biggest systems, namely APT and RPM. With the dependency-system on all of them you can make sure, that your application runs right off the bat.
PHP Desktop is the best option I found when researching this.
https://github.com/cztomczak/phpdesktop
PHP Nightrain is also an option:
https://download.cnet.com/PHP-Nightrain/3000-10248_4-76169308.html
Bitnami WAMP stack looks good as well:
https://docs.bitnami.com/installer/infrastructure/wamp/

Pure PHP implementation of SQLite?

Is there a pure PHP implementation of SQLite that will run on PHP 5.1.6? I am working on an application that would benefit from being able to store data in a relational database, but the server that it has to run on is stuck with PHP 5.1.6 and has been configured "'--without-sqlite"
I have no control over this server; cannot recompile, upgrade or otherwise modify PHP aside from using .htaccess files. Hosting externally is also not an option, unfortunately. MySQL may be possible but would be a nightmare trying to get their IT to create a database for me. (It took them 6 weeks to get .htaccess files enabled because of red tape and other things)
Am I out of luck? My fall back is to write everything to flat files but I really would rather not do that.
EDIT: Fixed typo. PHP does not have the SQLite extension and was configured "'--without-sqlite" according to the output of phpinfo()
Actually, you could easily download and install sqlite in your userspace, whether on windows or on a linux remote shell doesn t usually matter unless your host is unusually restrictive, if that is the case you should change service provider.
Once sqlite is installed, you can one of the available pear extensions or pecl extension to allow easy access through php.
Tutorial and code examples for the pear solution here.

how to start php?

I am asp.net developer , i want to learn php
what are the software need to run compile php file ?
how to install this software any path that should be set ?
what kind of database it needs to store data and retrieve date ?
see me as beginner and then give the idea / information ..........
thanxx
You just need the PHP interpreter and if you want to do web stuff a webserver.
You can get the interpreter from http://www.php.net - if you are using windows you really want to get a binary version and not compile it on your own - and the Apache webserver.
As a database PHP developers usually use MySQL (but it can also connect to most other databases).
The easiest way for your to get started is getting a package like XAMPP which will contain all you need without requiring you to configure everything manually.
For actually learning PHP, please get a recent book/tutorial. Old stuff is usually telling people to do horribly things every sane developer will hate you for (cluttering your global namespace with variables settable by the user for example).
You could have a look at the official PHP docs which also contains a "getting started" guide.
Since you are an ASP.NET developer I assume that you are familiar with IIS and that you're probably using IIS 7.5. If so then the easiest way to familiarize yourself with PHP is to use Microsoft Web Platform Installer and install PHP directly to IIS. You don't have to set any paths after that, just create a site on IIS and start putting PHP files there. Keep in mind that Web Platform Installer automatically enables WinCache extension and your changes might not be there when you hit the refresh button. Just locate the php.ini and comment out the relevant line.
Straight from the horses mouth. Getting Started. You will need a php interpreter, if you have access to a webhost that has php installed you're half way there, if you have a linux partition you're half way there, otherwise check out XAMPP.
Software: XAMPP will get you up and running
Tutorial: w3schools
If you are familiar with IIS and want to use it as your web server you can download PHP for IIS here and use some of the learning material there to get started.
If you did not want to use IIS and wanted to use Apache instead then I agree with the others XAMPP will get you a dev environment up and running quickly.

start php, apache?

I've just started reading about php, it needs me to install php, apache and MySql to run any php script. can any one suggest me a simplest method to install php, apache and MySql so that i can sun those php script.
I've tried the zip files from php.net, Are those required to run the script offline for practicing the script? what do i do with them? i felt the things given on the same site a bit complex, and was unable to run the script. please help.
I'm assuming you're using Windows - get wamp - it has exactly what you need:
Apache
MySQL
PHP
Wamp comes with a nifty tray controller app which you can use to access the most common tasks, like restarting services, editing config, etc.
Equivalent to Artem's post, just a different organization which packages it differently. And my preference. It is called XAMPP.
If you are using Windows, you could install XAMPP to have the environment setup for you. You'll then need to learn how to bring up the server (basically executing the XAMPP control panel program), copy your PHP scripts into the correct directories (for XAMPP, it'd be C:/[xampp installation dir]/htdocs), access MySQL and creating the necessary MySQL databases (you could access the MySQL via the included PhpMyAdmin).
You can probably refer to a tutorial here (it's a YouTube video, BTW).
Don't have enough rep to comment but wanted to add something to Artem's recommendation of Wampserver. It's what I use on my windows machine, and one of the nicest things about it I find is the ability to have multiple versions of versions of apache, php and mysql installed alongside each other as plug-ins and then select which to have running at any time. It makes it easy for me to emulate the eventual hosting environment for any given project.

Categories