Connect PHP to Postgresql on OpenBSD - php

I have PHP and Postgresql installed on OpenBSD 7.0 (VPS). PHP is working (I can echo from an index.php file). And my Postgresql server is running (I can connect and create tables from the command line) but I can't get PHP to connect.
I suspect it has something to do with PHP not being able to access the DB socket (because it operates in chroot). Or it's related to my postgresql.conf not using "localhost" (explained below). But I'm not lost on trying to solve for those.
/etc/httpd.conf
(port 80 blocks are also there and redirect to 443)
server "db.example.com" {
listen on * tls port 443
root "/htdocs/db"
directory index index.php
authenticate with ".htpasswd"
tls {
certificate "/etc/ssl/db.example.com.fullchain.pem"
key "/etc/ssl/private/db.example.com.key"
}
location "*.php" {
fastcgi socket "/run/php-fpm.sock"
}
}
(and /etc/acme-client.conf is aligned and certificate installed)
PHP install
# pkg_add php php-pgsql (version 8 selected)
# rcctl enable php80_fpm
# rcctl start php80_fpm
# rcctl restart httpd
Postgres (part 1)
# pkg_add postgresql-server postgresql-contrib
# su - _postgresql
$ mkdir /var/postgresql/data
$ initdb -D /var/postgresql/data -U postgres -A scram-sha-256 -E UTF-8 -W
[password created]
Postgres (part 2)
/var/postgresql/data/postgresql.conf
(Localhost doesn't resolve to my VPS IP so I add my actual IP here)
listen_addresses = '123.45.67.89'
Postgres (part 3)
$ pg_ctl -D /var/postgresql/data -l logfile start
$ exit
# rcctl enable postgresql
# rcctl start postgresql
# psql -U postgres
# CREATE DATABASE test;
# CREATE USER tester WITH PASSWORD '12345';
# GRANT ALL PRIVILEGES ON DATABASE test TO tester;
/var/www/htdocs/db/index.php
<?php
echo "Hello world!"; (this part works, then no output after this)
$db = pg_connect("host=123.45.67.89 port=5432 dbname=test user=tester password=12345");
if ($db) {
echo "I'm in.";
} else {
echo "No luck.";
}
?>

Did you activate the PG PHP module by copying or symlinking its .ini file to /etc/php-8.0/? If not, take a look at the "Extension modules" section of /usr/local/share/doc/pkg-readmes/php-8.0:
For all extensions packaged separately (and for opcache), you will
find a file named /etc/php-8.0.sample/(MODULE_NAME).ini. To enable it,
add a symlink into /etc/php-8.0 and restart:
ln -sf ../php-8.0.sample/MODULE_NAME.ini /etc/php-8.0/
To disable, remove the symlink from /etc/php-8.0 and restart:
rm /etc/php-8.0/MODULE_NAME.ini
If you have installed a number of extensions and wish to enable them
all, you can use these shell commands:
# cd /etc/php-8.0.sample
# for i in *; do ln -sf ../php-8.0.sample/$i ../php-8.0/; done
After enabling or disabling extensions (or otherwise modifying php's
configuration), use rcctl(8) to restart php80_fpm or Apache.

Related

No such file or directory [duplicate]

I'm trying to set up WordPress. I have Apache and MySQL running, and the accounts and database are all set up. I tried to make a simple connection:
<?php
$conn = mysql_connect('localhost', 'USER', 'PASSWORD');
if(!$conn) {
echo 'Error: ' . mysql_errno() . ' - ' . mysql_error();
}
?>
And I always get this:
Error: 2002 - No such file or
directory
What file or directory could it be talking about?
I'm on a OS X Snow Leopard, using the built-in Apache. I installed MySQL using the x86_64 dmg.
UPDATE: I found that the socket is at /tmp/mysql.sock, so In php.ini, I replaced all occurrences of the wrong path with that.
I had a similar problem and was able to solve it by addressing my mysql with 127.0.0.1 instead of localhost.
This probably means I've got something wrong in my hosts setup, but this quick fix get's me going for right now.
If you use Linux: the path to the mysql.sock file is wrong. This is usually because you are using (LAMPP) XAMPP and it isn't in /tmp/mysql.sock
Open the php.ini file and find this line:
mysql.default_socket
And make it
mysql.default_socket = /path/to/mysql.sock
This is for Mac OS X with the native installation of Apache HTTP and custom installation of MySQL.
The answer is based on #alec-gorge's excellent response, but since I had to google some specific changes to have it configured in my configuration, mostly Mac OS X-specific, I thought I'd add it here for the sake of completeness.
Enable PHP5 support for Apache HTTP
Make sure the PHP5 support is enabled in /etc/apache2/httpd.conf.
Edit the file with sudo vi /etc/apache2/httpd.conf (enter the password when asked) and uncomment (remove ; from the beginning of) the line to load the php5_module module.
LoadModule php5_module libexec/apache2/libphp5.so
Start Apache HTTP with sudo apachectl start (or restart if it's already started and needs to be restarted to re-read the configuration file).
Make sure that /var/log/apache2/error_log contains a line that tells you the php5_module is enabled - you should see PHP/5.3.15 (or similar).
[notice] Apache/2.2.22 (Unix) DAV/2 PHP/5.3.15 with Suhosin-Patch configured -- resuming normal operations
Looking up Socket file's name
When MySQL is up and running (with ./bin/mysqld_safe) there should be debug lines printed out to the console that tell you where you can find the log files. Note the hostname in the file name - localhost in my case - that may be different for your configuration.
The file that comes after Logging to is important. That's where MySQL logs its work.
130309 12:17:59 mysqld_safe Logging to '/Users/jacek/apps/mysql/data/localhost.err'.
130309 12:17:59 mysqld_safe Starting mysqld daemon with databases from /Users/jacek/apps/mysql/data
Open the localhost.err file (again, yours might be named differently), i.e. tail -1 /Users/jacek/apps/mysql/data/localhost.err to find out the socket file's name - it should be the last line.
$ tail -1 /Users/jacek/apps/mysql/data/localhost.err
Version: '5.5.27' socket: '/tmp/mysql.sock' port: 3306 MySQL Community Server (GPL)
Note the socket: part - that's the socket file you should use in php.ini.
There's another way (some say an easier way) to determine the location of the socket's file name by logging in to MySQL and running:
show variables like '%socket%';
Configuring PHP5 with MySQL support - /etc/php.ini
Speaking of php.ini...
In /etc directory there's /etc/php.ini.default file. Copy it to /etc/php.ini.
sudo cp /etc/php.ini.default /etc/php.ini
Open /etc/php.ini and look for mysql.default_socket.
sudo vi /etc/php.ini
The default of mysql.default_socket is /var/mysql/mysql.sock. You should change it to the value you have noted earlier - it was /tmp/mysql.sock in my case.
Replace the /etc/php.ini file to reflect the socket file's name:
mysql.default_socket = /tmp/mysql.sock
mysqli.default_socket = /tmp/mysql.sock
Final verification
Restart Apache HTTP.
sudo apachectl restart
Check the logs if there are no error related to PHP5. No errors means you're done and PHP5 with MySQL should work fine. Congrats!
Restarting the mysql server might help. In my case, restarting the server saved a lot of time.
service mysql restart
P.S.- use sudo service mysql restart for non-root user.
Replacing 'localhost' to '127.0.0.1' in config file (db connection) helped!
First, ensure MySQL is running. Command: mysqld start
If you still cannot connect then:
What does your /etc/my.cnf look like? (or /etc/msyql/my.cnf)
The other 2 posts are correct in that you need to check your socket because 2002 is a socket error.
A great tutorial on setting up LAMP is: http://library.linode.com/lamp-guides/centos-5.3/index-print
Expanding on Matthias D's answer here I was able to resolve this 2002 error on both MySQL and MariaDB with exact paths using these commands:
First get the actual path to the MySQL socket:
netstat -ln | grep -o -m 1 '/.*mysql.sock'
Then get the PHP path:
php -r 'echo ini_get("mysql.default_socket") . "\n";'
Using the output of these two commands, link them up:
sudo ln -s /actualpath/mysql.sock /phppath/mysql.sock
If that returns No such file or directory you just need to create the path to the PHP mysql.sock, for example if your path was /var/mysql/mysql.sock you would run:
sudo mkdir -p /var/mysql
Then try the sudo ln command again.
Not that it helps you much, but in the recent versions (and even less recent) of MySQL, error code 2002 means “Can't connect to local MySQL server through socket [name-of-socket]”, so that might tell you a bit more.
I'd check your php.ini file and verify the mysql.default_socket is set correctly and also verify that your mysqld is correctly configured with a socket file it can access. Typical default is "/tmp/mysql.sock".
I encountered this problem too, then i modified 'localhost' to '127.0.0.1',it works.
in my case I have problem with mysqli_connect.
when I want to connect
mysqli_connect('localhost', 'myuser','mypassword')
mysqli_connect_error() return me this error "No such file or directory"
this worked for me
mysqli_connect('localhost:3306', 'myuser','mypassword')
The error 2002 means that MySQL can't connect to local database server through the socket file (e.g. /tmp/mysql.sock).
To find out where is your socket file, run:
mysql_config --socket
then double check that your application uses the right Unix socket file or connect through the TCP/IP port instead.
Then double check if your PHP has the right MySQL socket set-up:
php -i | grep mysql.default_socket
and make sure that file exists.
Test the socket:
mysql --socket=/var/mysql/mysql.sock
If the Unix socket is wrong or does not exist, you may symlink it, for example:
ln -vs /Applications/MAMP/tmp/mysql/mysql.sock /var/mysql/mysql.sock
or correct your configuration file (e.g. php.ini).
To test the PDO connection directly from PHP, you may run:
php -r "new PDO('mysql:host=localhost;port=3306;charset=utf8;dbname=dbname', 'root', 'root');"
Check also the configuration between Apache and CLI (command-line interface), as the configuration can be differ.
It might be that the server is running, but you are trying to connect using a TCP/IP port, named pipe, or Unix socket file different from the one on which the server is listening. To correct that you need to invoke a client program (e.g. specifying --port option) to indicate the proper port number, or the proper named pipe or Unix socket file (e.g. --socket option).
See: Troubleshooting Problems Connecting to MySQL
Other utils/commands which can help to track the problem:
mysql --socket=$(php -r 'echo ini_get("mysql.default_socket");')
netstat -ln | grep mysql
php -r "phpinfo();" | grep mysql
php -i | grep mysql
Use XDebug with xdebug.show_exception_trace=1 in your xdebug.ini
On OS X try sudo dtruss -fn mysqld, on Linux debug with strace
Check permissions on Unix socket: stat $(mysql_config --socket) and if you've enough free space (df -h).
Restart your MySQL.
Check net.core.somaxconn.
Make sure your local server (MAMP, XAMPP, WAMP, etc..) is running.
May be I am late to answer this, but what solved my problem was to install the mysql-server
sudo apt-get install mysql-server
after spending more than 5 hours I found this solution which helped me to proceed.
I hope this would help someone if the top answers won't help them
by using 127.0.0.1 insteady of localhost solve the problem
Digital Ocean MySql 2002-no-such-file-or-directory
Add this end of file /etc/mysql/my.cnf
[mysqld]
innodb_force_recovery = 1
Restart MySql
service mysql restart
First check MySQL server is running or not. if running then check socket path by login to MySQL through command line.
mysql -uUSER -pPASSWORD
then
show variables like 'socket';
You'll find path of mysql socket which you can use further in connection string like below:
$conn = mysqli_connect('localhost', 'USER', 'PASSWORD', 'path of
socket file');
If MySQL is not running. Then Please share error logs which you are getting to troubleshoot further.
I had a similar problem.
Basically here the problem is there are probably two instances of mysql running.
A) One running at /etc/init.d
B) Lamp being installed at /opt/lamp
Solution :
Step 1 :- Find all mysql running instances using commnad "find / | grep mysqld"
Step 2 :- Shutdown the services running at /etc/init.d using service mysql stop
Step 3 :- Restart your Lamp services using /opt/lamp/lamp restart
You should be good to go :)
On a Mac, before doing all the hard work, simply check your settings in System Preferences > MySQL. More often than not, I've experienced the team running into this problem since The MySQL Server Instance is stopped.
Click the Start MySQL Server button, and magic will happen.
Im using PHP-FPM or multiple php version in my server. On my case i update mysqli value since there is not mysql default socket parameter :
mysqli.default_socket
to :
mysql.default_socket = /path/to/mysql.sock
thanks to #Alec Gorge
I had the same problem. My socket was eventually found in /tmp/mysql.sock. Then I added that path to php.ini. I found the socket there from checking the page "Server Status" in MySQL Workbench. If your socket isn't in /tmp/mysql.sock then maybe MySQL Workbench could tell you where it is? (Granted you use MySQL Workbench...)
I've installed MySQL using installer. In fact, there was no data directory alongside 'bin' directory.
So, I manually created the 'data' directory under "C:\Program Files\MySQL\MySQL Server 8.0". And it worked (changing the root password following steps suggested on https://dev.mysql.com/doc/mysql-windows-excerpt/5.7/en/resetting-permissions-windows.html.
enable and start mariadb service
sudo systemctl enable mariadb.service
sudo systemctl start mariadb.service

Gitlab CI Symfony : SQLSTATE[HY000] [2002] Connection refused

I use gitlab to run unit tests each time someone push the code. I get this error during composer installation.
> Incenteev\ParameterHandler\ScriptHandler::buildParameters
Creating the "app/config/parameters.yml" file
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache
[Doctrine\DBAL\Exception\ConnectionException]
An exception occured in driver: SQLSTATE[HY000] [2002] Connection refused
[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[HY000] [2002] Connection refused
[PDOException]
SQLSTATE[HY000] [2002] Connection refused
Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the post-install-cmd event terminated with an exception
Here is my configuration :
.gitlab-ci.yml file
# Select image from https://hub.docker.com/_/php/
image: php:5.6
# Select what we should cache
cache:
paths:
- vendor/
before_script:
# Install ssh-agent if not already installed, it is required by Docker.
# (change apt-get to yum if you use a CentOS-based image)
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
#
Run ssh-agent (inside the build environment)
- eval $(ssh-agent -s)
# Add the SSH key stored in SSH_PRIVATE_KEY variable to the agent store
- ssh-add <(echo "$SSH_PRIVATE_KEY")
# For Docker builds disable host key checking. Be aware that by adding that
# you are suspectible to man-in-the-middle attacks.
# WARNING: Use this only with the Docker executor, if you use it with shell
# you will overwrite your user's SSH config.
- mkdir -p ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
- cp ci/custom.ini /usr/local/etc/php/conf.d/custom.ini
- bash ci/docker_install.sh > /dev/null
# Install composer
- curl -sS https://getcomposer.org/installer | php
services:
- mysql:latest
variables:
# Configure mysql service (https://hub.docker.com/_/mysql/)
MYSQL_DATABASE: symfony
MYSQL_ROOT_PASSWORD: root
# We test PHP5.6 (the default) with MySQL
test:mysql:
script:
# Install all project dependencies
- php composer.phar install
- phpunit --coverage-text --colors=never -c app/
parameters.yml.dist
parameters:
database_host: 127.0.0.1
database_port: ~
database_name: symfony
database_user: root
database_password: root
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: ~
mailer_password: ~
# A secret key that's used to generate certain security-related tokens
secret: ThisTokenIsNotSoSecretChangeIt
database_slave1_host: 127.0.0.1
database_slave1_port: ~
database_slave1_name: symfony
database_slave1_user: root
database_slave1_password: root
I have read and follow the instruction of the gitlab website. Maybe my mistake is obvious, but I can't see it.
As you are using MySQL that is running in another container, you have to use its hostname, not 127.0.0.1. The correct database host should be "mysql". This is covered in one of the sections of the GitLab's documentation:
The service container for MySQL will be accessible under the hostname mysql. So, in order to access your database service you have to connect to the host named mysql instead of a socket or localhost.
One of the possible reasons for this error is that you attempt to access the database while it still initialises. This is covered in the MySQL's caveats section on the Docker HUB.
If there is no database initialised when the container starts, then a default database will be created. While this is the expected behaviour, this means that it will not accept incoming connections until such initialisation completes. This may cause issues when using automation tools...
A crude solution would be to use sleep command before you start any process that accesses database. You can add it to the before_script section:
before_script:
- sleep 60s
A better and more complex solution would be to probe the MySQL server, repeatedly checking whether it already accepts connections.

Docker: wordpress dev sandboxed environment

I don't work with WP neither PHP. But sometimes I'm asked to have a look at a wordpress site (we've all been through this ... sight)
Instead of installing LAMP or whatever, I'd rather sandbox the shit in a docker, so I can easily uninstall everything once done.
I find the docker-compose approach as suggested in the official wordpress docker kind of complicated.
Instead, since it is for development purpose only, I'd rather have a single Docker that would contain the whole PHP + MySQL config, and simply having to:
Replace DB_NAME, DB_USER, DB_PASSWORD and DB_HOST in wp-config.php
Import the SQL of the existing DB. Eg. docker run mydocker /bin/mysql-import ~/Desktop/export.sql
docker start mydocker --source ~/Workspace/myproject
Does this approach make sense? Are there any ressource I could find to achieve this (if it hasn't been done already)?
This shall certainly be improved, but here are the steps I took:
Install Docker if not already done
Install the Lamp Docker (I'd have rather used nginx instead of apache but anyways): docker pull linode/lamp
Run sudo docker run -p 80:80 -v <local_path_to_site_sources>:/var/www/<sitename> -t -i linode/lamp /bin/bash
At this step, you have forwarded Docker's port 80 to your host 80 (which means you can try out http://localhost and should get a result), entered into the docker's bash with /var/www/<sitename> containing your source code.
Unfortunately there is still some little config to make, which should be automated IMHO.
Run apt-get update (no more sudo, you are root there)
Run apt-get install php5-mysql (for some unfortunate reason, the package was missing)
Make sure the path /var/www/<sitename>/log exists by running mkdir -p /var/www/<sitename>/log
Run nano /etc/apache2/sites-available/<sitename>.conf with the following content (everything's detailed there):
ServerAdmin webmaster# # Probably not mandatory
ServerAlias # Probably not mandatory
# Index file and Document Root (where the public files are located)
DirectoryIndex index.html index.php
DocumentRoot /var/www/
# Log file locations
LogLevel warn
ErrorLog /var/www//log/error.log
CustomLog /var/www//log/access.log combined
Run a2ensite <sitename>
The database needs to be created before being imported anyways (maybe there a way to avoid this): mysql -u root -p password: Admin2015 as explained here
Run in-there create database <dbname>; then exit
Import current data if exists: mysql -u root -p <dbname> < <dbbackupfile>.sql (note that the <dbbackupfile>.sql needs to be available in the docker, so putting in into your <local_path_to_site_sources> shall help.
Update (from your host, not the docker, the files are shared) wp-config.php with:
/** Nom de la base de données de WordPress. */
define('DB_NAME', '');
/** Utilisateur de la base de données MySQL. */
define('DB_USER', 'root');
/** Mot de passe de la base de données MySQL. */
define('DB_PASSWORD', 'Admin2015');
/** Adresse de l'hébergement MySQL. */
define('DB_HOST', '127.0.0.1');
Run service apache2 restart; service mysql restart
Go check http://localhost : annnnnndd DONE!!

vagrant provision : installing LAMP throwing errors

I am using ubuntu 13.04 machine,
I have installed vagrant properly.
Below are the versions
vagrant : Vagrant 1.5.1
Virtual box : 4.2.10_Ubuntur84101
I am running a shell script file to install Apache, MySQL and Php.
Apache gets installed properly but going further gives error. some special characters are getting displayed on terminal.
Below is my vagrant file content
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "hashicorp/precise32"
config.vm.provision :shell, :path => "bootstrap.sh"
# The url from where the 'config.vm.box' box will be fetched if it
# doesn't already exist on the user's system.
# config.vm.box_url = "http://domain.com/path/to/above.box"
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# config.vm.network "forwarded_port", guest: 80, host: 8080
# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network "private_network", ip: "192.168.33.10"
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network "public_network"
# If true, then any SSH connections made will enable agent forwarding.
# Default value: false
# config.ssh.forward_agent = true
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data"
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
# config.vm.provider "virtualbox" do |vb|
# # Don't boot with headless mode
# vb.gui = true
#
# # Use VBoxManage to customize the VM. For example to change memory:
# vb.customize ["modifyvm", :id, "--memory", "1024"]
# end
#
# View the documentation for the provider you're using for more
# information on available options.
# Enable provisioning with Puppet stand alone. Puppet manifests
# are contained in a directory path relative to this Vagrantfile.
# You will need to create the manifests directory and a manifest in
# the file hashicorp/precise32.pp in the manifests_path directory.
#
# An example Puppet manifest to provision the message of the day:
#
# # group { "puppet":
# # ensure => "present",
# # }
# #
# # File { owner => 0, group => 0, mode => 0644 }
# #
# # file { '/etc/motd':
# # content => "Welcome to your Vagrant-built virtual machine!
# # Managed by Puppet.\n"
# # }
#
# config.vm.provision "puppet" do |puppet|
# puppet.manifests_path = "manifests"
# puppet.manifest_file = "site.pp"
# end
# Enable provisioning with chef solo, specifying a cookbooks path, roles
# path, and data_bags path (all relative to this Vagrantfile), and adding
# some recipes and/or roles.
#
# config.vm.provision "chef_solo" do |chef|
# chef.cookbooks_path = "../my-recipes/cookbooks"
# chef.roles_path = "../my-recipes/roles"
# chef.data_bags_path = "../my-recipes/data_bags"
# chef.add_recipe "mysql"
# chef.add_role "web"
#
# # You may also specify custom JSON attributes:
# chef.json = { :mysql_password => "foo" }
# end
# Enable provisioning with chef server, specifying the chef server URL,
# and the path to the validation key (relative to this Vagrantfile).
#
# The Opscode Platform uses HTTPS. Substitute your organization for
# ORGNAME in the URL and validation key.
#
# If you have your own Chef Server, use the appropriate URL, which may be
# HTTP instead of HTTPS depending on your configuration. Also change the
# validation key to validation.pem.
#
# config.vm.provision "chef_client" do |chef|
# chef.chef_server_url = "https://api.opscode.com/organizations/ORGNAME"
# chef.validation_key_path = "ORGNAME-validator.pem"
# end
#
# If you're using the Opscode platform, your validator client is
# ORGNAME-validator, replacing ORGNAME with your organization name.
#
# If you have your own Chef Server, the default validation client name is
# chef-validator, unless you changed the configuration.
#
# chef.validation_client_name = "ORGNAME-validator"
end
here is my bootstrap.sh
#!/usr/bin/env bash
touch track_bootstrap_file.txt
echo -e "\n\n\t\t------ Initial installations -------\n\n"
echo -e "\n\n\t\tStep 1 of 5 ===> Updating existing packages <===\n\n"
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password password pass#123'
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password pass#123'
apt-get update
echo "step 1 of 5 - packages updated" > track_bootstrap_file.txt
echo -e "\n\n\t\tStep 2 of 5 ===> Installing mysql server <===\n\n"
sudo apt-get -y install mysql-server-5.5 php5-mysql
echo "step 2 of 5 - mysql server installed" >> track_bootstrap_file.txt
echo -e "\n\n\t\tStep 3 of 5 ===> Installing Apache server <===\n\n"
apt-get install -y apache2
echo "step 3 of 5 - apache server installed" >> track_bootstrap_file.txt
echo -e "\n\n\t\tStep 4 of 5 ===> Installing php5 <===\n\n"
apt-get install -y php5 libapache2-mod-php5
service apache2 restart
echo "step 4 of 5 - php5 installed" >> track_bootstrap_file.txt
echo -e "\n\n\t\tStep 5 of 5 ===> Restarting apache2 <===\n\n"
service apache2 restart
echo "step 5 of 5 - Restarted apache2 server successfully" >> track_bootstrap_file.txt
echo -e "\n\n\n\t\t----- Wohoo... Your machine configuration is ready now. -------\n\n"
echo "All operations from bootstrap.sh executed successfully" >> track_bootstrap_file.txt
Thanks in advance.
The problem is not within vagrant or the provisioning itself but in the way you try to install phpmyadmin. As the shell script runs without any interactive shall attached, the question phpmyadmin tries to ask while installing cannot be answered, messing up your installation. It should work if you put
export DEBIAN_FRONTEND=noninteractive
at the beginning of your shell script.

Sharing SQLite database with phpliteadmin

I just started using phpliteadmin to manage a SQLite database [1].
I set up local access using the build-in webserver in php5.4, exactly as shown the documentation [2]:
php -S localhost:8000
http://localhost:8000/phpliteadmin.php
I want to:
(1) Share phpliteadmin acess with several others on my network.
(2) Set up phpliteadmin with an Apache webserver (in case I needed to migrate away from the php server).
Interested in suggestions regarding ways to do both?
[1] On Linux machine running CentOS 6
[2] http://code.google.com/p/phpliteadmin/wiki/NoWebserver
I solved both, but wanted to open up what I did (perhaps it can be improved or is useful to others).
(1) Straightforward way to host using php5.4 webserver (specify IP address):
php -S <ip_address>:8000
http://<ip_address>:8000/phpliteadmin.php
(2) Host using Apache httpd (on CentOS 6) [1]:
(a) Set hostname of the webserver: /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=<NAME_OF_CHOICE>
NTPSERVERARGS=iburst
(b) Modify hosts file: /etc/hosts
<IP_ADDRESS> <NAME_OF_CHOICE>
(c) Modify Apache config file and include phpliteadmin.php as the default index : /etc/httpd/conf/httpd.conf
## Line 262 - Set the server admin mail ##
ServerAdmin <e-mail>
## Line 276 - Set the website name ##
ServerName <IP_ADDRESS>:80
## Line 292 - Set the web pages folder ##
DocumentRoot "/var/www"
## line 402 - Sent the index or home page of the website ##
DirectoryIndex phpliteadmin.php
(d) Make sure the server has php enabled. CentOS PHP module for Apache httpd is called "libphp5" [2]. For php54w install, the file was in: /usr/lib64/httpd/modules/libphp5.so
(e) Modify Apache config file [3]: /etc/httpd/conf/httpd.conf
LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php
(f) Move phpliteadmin.php to document root of the webserver.
(g) Modify $directory in phpliteadmin.php to point to the directory of the database.
(h) Modify iptables to allow webserver through firewall: /etc/sysconfig/iptables
-A INPUT -p tcp -m state --state NEW --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW --dport 80 -j ACCEPT
(i) Re-boot iptables:
service iptables restart
(j) Start the webserver:
service httpd start
(h) The server IP address in browser should recognize the phpliteadmin.php file and ask for database login.
If the .php file raw text displays, then php is not loading correctly and check step (e). If php loads, but reports database not found and / or directory not writable, check permissions on the database and DocumentRoot that phpliteadmin.php sits in (e.g., /var/www required sudo to modify and I had to open permissions).
[1] http://ostechnix.wordpress.com/2013/03/05/install-apache-webserver-in-centos-6-3-scientific-linux-6-3-rhel-6-3/
[2] http://www.rackspace.com/knowledge_center/article/centos-apache-and-php-install
[3] PHP code is not being executed, instead code shows on the page

Categories