Jump to content

code ok in xampp but issues an error on ubuntu VM


ajoo

Recommended Posts

Hi all,  :)

 

The 2nd line in this code gives an error on the ubuntu12.04 VM though it works fine on the local xampp installation.

    $login_attempts_query = $database_connection->query('SELECT @login_attempts');
    $login_attempts = $login_attempts_query->fetch_row()[0];
    $login_attempts_query->close();
 

specifically a syntax error due to the square bracket"[".

 

Why should this issue an error in one and not in the other environment? is this method deprecated or is this a version issue? Here is the the apache and php detail in the VM 

 

 

vagrant@precise32:~$ apache2 -v

Server version: Apache/2.2.22 (Ubuntu)
Server built:   Jul 15 2016 15:32:38
vagrant@precise32:~$ php -v
PHP 5.3.10-1ubuntu3.25 with Suhosin-Patch (cli) (built: Oct  3 2016 16:53:10)
Copyright © 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright © 1998-2012 Zend Technologies
vagrant@precise32:~$ ^C
vagrant@precise32:~$
 

 

The xampp vesrion of Apache is 2.4 and php is 5.6

 

Would the following be the correct code replacement for the above? ( sorry checking across the two environments is most cumbersome after a days work )

    $login_attempts_query = $database_connection->query('SELECT @login_attempts');
    $login_attempts = $login_attempts_query->fetch_row();
    $login_attempts = $login_attempts[0];
    $login_attempts_query->close();

    return $login_attempts;

Thanks !

 

Link to comment
Share on other sites

Hi, please can you suggest a lamp stack vagrant box with those specs ( Apache 2.4 and php 7) that would fulfill my testing needs. I have been trying to install a few of them without success on my 32 bit machine but most gave errors. One even had a virus ( scotch.io ). Any help appreciated. Thanks.

Edited by ajoo
Link to comment
Share on other sites

hmmm can I use a 64 bit linux on my 32 bit windows machine or do i need a 64 bit windows machine minimum ? I don't know about building our own image but yes we can build our own system using  vagrant but the commands for different versions of apache and php and other software are confusing. For e.g. after a searching I finally found and installed a hashicorp/precise32 machine after some hit n trial. And then it gave that error of array re-direction since it did not support. 

 

I then tried installing  the box boxcutter/ubuntu1604 (32-bit) but that gave error each time i tried. Then i just gave up and tried a few more to no avail.

 

Hence I am here !! Any and all help/suggestions appreciated.

 

Thanks all. 

Edited by ajoo
Link to comment
Share on other sites

It's still unclear to me why you can't just install the current Debian (or Ubuntu) in your VirtualBox, install PHP 7 via the package manager and be done with it. Then we don't have to spend our time debugging ancient PHP versions in old Ubuntu versions in Vagrant (which none of us three is familiar with).

  • Like 1
Link to comment
Share on other sites

I just learned Vagrant a few months back. It is actually very simple and is a great tool for it's purpose. The only thing with using the pre-built boxes is you really don't know for sure exactly how it was configured when it was made. The time it takes to download a box, you could just create your own. The pre-mades are good for a quick to get going solution or just trying different OS's.

 

Like @Jaques1 said, just download and install exactly what you want. For additional flexibility you can turn that into a Vagrant box of your own. If you're going to be a developer you need to get on 64 bit. You can't run 64 bit software on 32 bit hardware.

 

For those not familiar with Vagrant, it's worth a look. https://www.vagrantup.com/

  • Like 1
Link to comment
Share on other sites

Hi Benanamen and Guru Jacques,

 

Thanks again for the reply.

 

Ok so I have finally made my own box, just like both of you suggested and after two long hours finally managed to get it working.  The php version is still not 7.0 or 7.1 but it's 5.6.30 and i'll change that to 7 next as I am too tired to try it out now. I have apache 2.4.7 and mysql 5.5 i think. 

 

Will port the project next and get it working on the VM. 

 

Will also spin up a box with php 7 ( as Guru Jacques suggested) since I have a better hang of this now I think !  :)  Vagrant allows me to work on my project from the host and that's a good thing as I have configured it to achieve that as well !! I have recorder all the steps in setting up the stack and will put all the details here, after some editing, tomorrow so that it may benefit someone else !

 

Thanks Benanaman and  Guru Jacques !

Link to comment
Share on other sites

Hi all, 

 

For other beginners who may be struggling like me to install their own dev boxes on a VM. Here is what I did to finally have a VM up and running with apache2.4.7, PHP5.6 and MYSQL5.5

 

UBUNTU 14.04
Go to the hashicorp sitehttps://atlas.hashicorp.com
I have searched for the 1404 version and 32 bit (i-386) and so the link https://atlas.hashicorp.com/bento/boxes/ubuntu-14.04-i386
from there pick up the initialization commands there :

vagrant init bento/ubuntu-14.04-i386; 
vagrant up 

Executing the first command in the terminal ( I use gitbash ) :  

vagrant init bento/ubuntu-14.04-i386; the vagrant box is initialized. Any changes can then be made to the vagrant file and then issue the

vagrant up command at the terminal to download and install the selected  disk image if not already on the local system.

It takes quite some time to download and install the ubuntu image disk.

If the machine does not boot successfully and gives locking errors  (ERROR ACCESS or sth like that) check out  http://stackoverflow.com/questions/27670076/permission-denied-error-for-vagrant. I had this error and . On the windows host machine I went into C:/users/vagrant.d/data/machine-index and deleted all files there and the machine finally booted successfully.

vagrant ssh into the VM now and it should work fine.

I followed this:  https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu to install the lamp on the ubuntu machine.

INSTALL APACHE:
sudo apt-get update
sudo apt-get install apache2
The public ip address is given as set in the vagrantfile by the line :

config.vm.network "private_network", ip: "192.168.33.10"  which I had un-commented before vagrant up.


browsing to this address, namely, 192.168.33.10, shows the Apache2 ubuntu default page !!!! ( Happyeeeee !!).  Here I exited the VM and saved a snapshot of the machine using the command :
vagrant snapshot save ubuntu14_with_apache2.4.7

Now I can safely try and install mysql and if something goes wrong, I will restore my snapshot and get to it again.

INSTALL MYSQL ver 5.6 :
Install using :
sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql
and activate using :
sudo mysql_install_db


 The activation ended with this loooong message:

To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password';    /usr/bin/mysqladmin -u root -h vagrant password 'new-password'
Alternatively you can run:

/usr/bin/mysql_secure_installation

which will also give you the option of removing the test databases and anonymous user created by default.  This is strongly recommended for production servers. See the manual for more instructions.

You can start the MySQL daemon with:  cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl;  cd /usr/mysql-test ; perl mysql-test-run.pl

Please report any problems at http://bugs.mysql.com/

vagrant@vagrant:~$    

Continuing installation : sudo /usr/bin/mysql_secure_installation . This gives another looong list of questions the answer to most of which is “y”:
 

Setting the root password ensures that nobody can log into the MySQL root user without the proper authorisation.

You already have a root password set, so you can safely answer 'n'. 

Change the root password? [Y/n] n

 ... skipping.

By default, a MySQL installation has an anonymous user, allowing anyone 

to log into MySQL without having to have a user account created for them.  This is intended only for testing, and to make the installation go a bit smoother.  You should remove them before moving into a production environment.

Remove anonymous users? [Y/n] y

 ... Success!

Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y

 ... Success!

access.  This is also intended only for testing, and should be removed before moving into a production environment.

Remove test database and access to it? [Y/n] y

 - Dropping test database...

ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist

 ... Failed!  Not critical, keep moving...

 - Removing privileges on test database...

 ... Success!

Reloading the privilege tables will ensure that all changes made so far will take effect immediately. 

Reload privilege tables now? [Y/n] y

 ... Success!

Cleaning up...  All done!  If you've completed all of the above steps, your MySQL installation should now be secure.

Thanks for using MySQL!

Going on to INSTALL PHP now. Going to try and install PHP version 5.6 from

Followed this:   http://stackoverflow.com/questions/40567133/cannot-add-ppa-ppaondrej-php5-5-6 ( GOOD THREAD MUST READ) . The steps are:

1.    sudo add-apt-repository ppa:ondrej/php

2.    sudo apt-get update

3.    sudo apt-get -y install php5.6 php5.6-mcrypt php5.6-mbstring php5.6-curl php5.6-cli php5.6-mysql php5.6-gd php5.6-intl php5.6-xsl php5.6-zip

 

AND THE INSTALLATION ENDED WITH THE FOLLOWING :

Creating config file /etc/php/5.6/mods-available/dom.ini with new version  Creating config file /etc/php/5.6/mods-available/simplexml.ini with new version

Creating config file /etc/php/5.6/mods-available/wddx.ini with new version  Creating config file /etc/php/5.6/mods-available/xml.ini with new version

Creating config file /etc/php/5.6/mods-available/xmlreader.ini with new version  Creating config file /etc/php/5.6/mods-available/xmlwriter.ini with new version

Creating config file /etc/php/5.6/mods-available/xsl.ini with new version  Setting up php5.6-xsl (5.6.30-1+deb.sury.org~trusty+1) ...

Setting up php5.6-zip (5.6.30-1+deb.sury.org~trusty+1) ...

Creating config file /etc/php/5.6/mods-available/zip.ini with new version

Processing triggers for libc-bin (2.19-0ubuntu6.9) ...

Processing triggers for libapache2-mod-php5.6 (5.6.30-1+deb.sury.org~trusty+1) ...

vagrant@vagrant:~$ 

 GIG !!!!!!!
 

CHANGING THE ROOT DOCUMENT TO YOUR OWN PROJECT

I finally changed the default RootDirectory to my own project on the host machine. I had to make changes to the following 2 files : 

1.  /etc/apache2/sites-available/000-default.conf 
changes made and lines added:
                 

                 #DocumentRoot /var/www/html    --------------- (commented this out)

 

         DocumentRoot /vagrant/www/myProject ------------ (used this one) 

 

and added these :

 

         <Directory />

                 Options FollowSymLinks

                 AllowOverride None

        </Directory>

        <Directory /vagrant/www/myProject>

                Options Indexes FollowSymLinks MultiViews

                AllowOverride None

                Order allow,deny

                allow from all

        </Directory>

 

2.  /etc/apache2/apache2.conf. 
changed to
 <Directory /vagrant/www/>  FROM   <Directory /var/www/>

             Options Indexes FollowSymLinks

             AllowOverride None

             Require all granted

       </Directory>

Now I can make changes to my project in its's folder (/vagrant/www/myProject) on the host windows machine and that's linked to the Document Root of the VM !!!!!!!!!!!!!!!!!!!!!!!!

 

Thanks all !

Edited by ajoo
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.