Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

PHP and Apache PROBLEM!

  • 19-03-2014 6:43pm
    #1
    Closed Accounts Posts: 147 ✭✭


    Hi,

    I am running Ubuntu on a VM where I have installed php5, apache2 and mysql server. However, when I write a php program using nano, something as simple as a loop from 1-100, it doesn't appear on my 192.160.x.x/loop.php(name of file).

    Any reason why?

    Thanks.


Comments

  • Registered Users, Registered Users 2 Posts: 8,516 ✭✭✭RedXIV


    What directory do you have the php file in?


  • Closed Accounts Posts: 147 ✭✭Stanlex


    RedXIV wrote: »
    What directory do you have the php file in?

    /var/www


  • Closed Accounts Posts: 147 ✭✭Stanlex


    I made a phpinfo program

    <?php

    phpinfo()

    ?>

    ...and it works when I open it in the browser. Also in /var/www


  • Technology & Internet Moderators Posts: 28,842 Mod ✭✭✭✭oscarBravo


    When you say "doesn't appear", do you get a blank page? A 404? What?


  • Closed Accounts Posts: 147 ✭✭Stanlex


    oscarBravo wrote: »
    When you say "doesn't appear", do you get a blank page? A 404? What?

    I tried a for loop program, saved it in /var/www and it comes back with a blank page. Then I tried accessing a database with in php and it returns "Not found". Once again, saved in the same folder.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 1,991 ✭✭✭Ziycon


    Stanlex wrote: »
    I tried a for loop program, saved it in /var/www and it comes back with a blank page. Then I tried accessing a database with in php and it returns "Not found". Once again, saved in the same folder.

    Can you post the code, if you have any reference to mysql functions in the code and you haven't setup the mysql module properly this can occur, set php to display all errors on screen and see what you get.


  • Closed Accounts Posts: 147 ✭✭Stanlex


    Ziycon wrote: »
    Can you post the code, if you have any reference to mysql functions in the code and you haven't setup the mysql module properly this can occur, set php to display all errors on screen and see what you get.

    Here's an example of the code:

    <?php


    mysql_connect('localhost', 'root', 'password');


    mysql_select_db('test_db');


    $result = mysql_query("select * from contacts");


    $numrows = mysql_numrows($result);

    echo "There are $numrows in the table.";

    mysql_close();
    ?>


  • Closed Accounts Posts: 147 ✭✭Stanlex


    e5h6o2.png

    Does that look okay? That's like that by default but yet no error messages.


  • Registered Users, Registered Users 2 Posts: 26,584 ✭✭✭✭Creamy Goodness


    Firstly I'd be looking at the php error log it ironically will tell you what's wrong. You can find its location in the php.ini file.


  • Closed Accounts Posts: 147 ✭✭Stanlex


    Firstly I'd be looking at the php error log it ironically will tell you what's wrong. You can find its location in the php.ini file.

    Post #9


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 6,393 ✭✭✭AnCatDubh


    as you report it, your phpinfo code is a success, thus your basic php/apache setup would appear to be ok.

    try taking a look in /var/log/apache2/error.log and see if you are getting any error output when you run your script.


  • Registered Users, Registered Users 2 Posts: 773 ✭✭✭maki


    Can you attach your whole php.ini file? That bit in the screenshot is just the reference area and is commented out.
    Otherwise what you're looking for in that file is to make sure that:
    log_errors = On

    You can then set the location of the log by using something like this:
    error_log = /var/log/error_log (or wherever you want to put it)


  • Registered Users, Registered Users 2 Posts: 29 B000


    Try enabling errors with these commands. Put them at the top of your script.
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    


  • Registered Users, Registered Users 2 Posts: 1,991 ✭✭✭Ziycon


    Looks to me like mysql module isn't set up properly, if you view phpinfo() does the mysql section show up? Also post #10 is a good start, looking in the logs will point you in the right direction, what you've put in post #9 is the options, it's not the actual settings in your php.ini file, you need to scroll down further to see what's set, the semi-colon ';' is used to comment out a line.


  • Closed Accounts Posts: 147 ✭✭Stanlex


    This is the error.log file

    2i89fg6.png


  • Technology & Internet Moderators Posts: 28,842 Mod ✭✭✭✭oscarBravo


    Can you use cat instead of nano? It's a bit useless with the ends of the lines missing.


  • Closed Accounts Posts: 147 ✭✭Stanlex


    oscarBravo wrote: »
    Can you use cat instead of nano? It's a bit useless with the ends of the lines missing.

    Of course.

    2m6n0qh.png


  • Closed Accounts Posts: 147 ✭✭Stanlex


    The table.php file contains php/sql code that I posted earlier in the thread. That file is located in /var/www.

    How do you actually run PHP, just save and refresh the browser?


  • Technology & Internet Moderators Posts: 28,842 Mod ✭✭✭✭oscarBravo


    Could be a permissions issue. Can you "ls -l /var/www"? (Those are both lowercase Ls.)


  • Closed Accounts Posts: 147 ✭✭Stanlex


    oscarBravo wrote: »
    Could be a permissions issue. Can you "ls -l /var/www"? (Those are both lowercase Ls.)

    33k507q.png

    The table.php file is not there for some odd reason.


  • Advertisement
  • Technology & Internet Moderators Posts: 28,842 Mod ✭✭✭✭oscarBravo


    There's your problem. How did you create the file? Just "nano table.php" while logged on as root? Because that will put it in /root, not /var/www.


  • Closed Accounts Posts: 147 ✭✭Stanlex


    oscarBravo wrote: »
    There's your problem. How did you create the file? Just "nano table.php" while logged on as root? Because that will put it in /root, not /var/www.

    But when I run ex1.php, it doesn't work either.


  • Closed Accounts Posts: 147 ✭✭Stanlex


    33davt2.png

    Still doesn't work. What I do is, write the code in Nano, save it and enter 192.168.x.x/table.php in to my browser. Just an empty screen. Nothing.


  • Registered Users, Registered Users 2 Posts: 773 ✭✭✭maki


    Nothing in the error log after running it this time?


  • Registered Users, Registered Users 2 Posts: 1,991 ✭✭✭Ziycon


    Drop the below into a file and go to it in your browser, search for mysql, post what you find if anything relating to mysql please
    <?php
    phpinfo();
    


  • Closed Accounts Posts: 147 ✭✭Stanlex


    Ziycon wrote: »
    Drop the below into a file and go to it in your browser, search for mysql, post what you find if anything relating to mysql please
    <?php
    phpinfo();
    

    10rq0wm.png


  • Closed Accounts Posts: 147 ✭✭Stanlex


    maki wrote: »
    Nothing in the error log after running it this time?

    2yynv2h.png


  • Registered Users, Registered Users 2 Posts: 1,991 ✭✭✭Ziycon


    Stanlex wrote: »
    10rq0wm.png

    Is that it, no other references to mysql or sql? Is the phpinfo() page publicly available if so can you pm the url and I'll have a quick look?


  • Registered Users, Registered Users 2 Posts: 773 ✭✭✭maki


    Looks like it's not finding the mysql client libraries.
    Have you the php mysql libraries installed?
    sudo apt-get install php5-mysql

    By the way, in php you should be using mysqli functions instead of mysql.
    http://php.net/manual/en/mysqli.overview.php


  • Advertisement
  • Closed Accounts Posts: 147 ✭✭Stanlex


    I've found my problem. It's something very ridiculous and noob like.

    Well this is how I found out what it was.

    1. I turned errors on. Found a way and it worked.
    2. Decided to make a basic database in mysql
    3. Used php and html to get it on the server/browser
    4. Yesterday I had a problem with it appearing on the browser. The table just wouldn't appear.
    5. Well today, since I turned errors on, it told me "Access denied" even though my password in the php file was correct.
    6. I knew there was something wrong and the apache server wasn't talking with my directories.

    Now what the problem was.

    All my files were saved in ~/var/www Hence the ~

    ...instead of... /var/www

    When I copied them over it all worked fine. What made things really difficult was the fact that I was running a Ubuntu server on a VM so the interface was constantly the terminal.

    Anyway, the fun of debugging huh?

    Thanks to everyone who helped!


  • Registered Users, Registered Users 2 Posts: 6,509 ✭✭✭Talisman


    What virtualization software are you using? My recommendation would be to use VirtualBox and Vagrant.

    The beauty of Vagrant is that the folder you launch the VM from is mapped in the VM so you can edit the files within the folder structure on your local machine and not have to rely on using nano.


  • Closed Accounts Posts: 147 ✭✭Stanlex


    Talisman wrote: »
    What virtualization software are you using? My recommendation would be to use VirtualBox and Vagrant.

    The beauty of Vagrant is that the folder you launch the VM from is mapped in the VM so you can edit the files within the folder structure on your local machine and not have to rely on using nano.

    I'm using VMWare player. Free for non-commercial use. Sounds like a handy feature to have. Will give it a go. Is it free?


  • Registered Users, Registered Users 2 Posts: 241 ✭✭fcrossen


    Stanlex wrote: »
    What made things really difficult was the fact that I was running a Ubuntu server on a VM so the interface was constantly the terminal.

    Download something like Komodo Edit. It will allow you to set up a SFTP connection to your VM allowing you to edit files on it.


  • Registered Users, Registered Users 2 Posts: 6,509 ✭✭✭Talisman


    I'm using VMWare player. Free for non-commercial use. Sounds like a handy feature to have. Will give it a go. Is it free?
    VirtualBox and Vagrant are both free and cross platform.

    Here is a bash script that I use to automatically setup the Ubuntu VM for me. It contains the commands to install MariaDB (MySQL), PHP5.5, Nginx/Apache, Node.js, MongoDB, Git and Ruby on Rails - you just need the relevant lines uncommented to install the required software.

    install.sh:
    #!/usr/bin/env bash
    
    ## MySQL credentials
    sudo debconf-set-selections <<< 'mariadb-server mariadb-server/root_password password root'
    sudo debconf-set-selections <<< 'mariadb-server mariadb-server/root_password_again password root'
    
    ## Update Ubuntu sources
    sudo cp /etc/apt/sources.list /etc/apt/sources.list.old
    sudo sed -i -e 's/us.archive.ubuntu.com/archive.ubuntu.com/g' /etc/apt/sources.list
    sudo apt-get -y update
    
    ## Install Base packages
    sudo apt-get install -y python-software-properties curl vim
    
    ## Node.js repository
    #sudo add-apt-repository -y ppa:chris-lea/node.js
    #sudo apt-get -y update
    ## Install Node
    #sudo apt-get -y install nodejs
    
    ## How to find the fastest Ubuntu sources mirror
    ## sudo npm install -g ffum
    ## ffum
    
    ## MongoDB repository
    #sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
    #echo "deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen" | sudo tee -a /etc/apt/sources.list.d/10gen.list
    #sudo apt-get -y update
    ## Install MongoDB
    #sudo apt-get -y install mongodb-10gen
    
    ## MariaDB repository
    sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
    sudo add-apt-repository 'deb http://ftp.heanet.ie/mirrors/mariadb/repo/5.5/ubuntu precise main'
    sudo apt-get -y update
    ## Install MariaDB
    sudo apt-get install -y mariadb-server
    
    ## Nginx repository
    echo "deb http://ppa.launchpad.net/nginx/stable/ubuntu $(lsb_release -cs) main" | sudo tee -a /etc/apt/sources.list.d/nginx.list
    sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C300EE8C
    sudo apt-get -y update
    sudo apt-get -y install nginx
    
    ## Install Git
    sudo apt-get install -y git-core
    
    ## PHP5 repository
    sudo add-apt-repository -y ppa:ondrej/php5
    sudo apt-get update
    
    ## Install PHP5 packages
    sudo apt-get install -y php5 php5-mcrypt php5-gd php5-curl php5-mysql php5-fpm php5-cli php5-cgi php5-common php5-xcache php5-json
    ## Xdebug
    #sudo apt-get install -y php5-xdebug
    
    #cat << EOF | sudo tee -a /etc/php5/mods-available/xdebug.ini
    #xdebug.scream=1
    #xdebug.cli_color=1
    #xdebug.show_local_vars=1
    #EOF
    
    ## Install Apache
    #sudo apt-get install -y apache2 libapache2-mod-php5
    ## Enable Apache mod-rewrite
    #sudo a2enmod rewrite
    
    ## Set the document root to the shared vagrant folder
    rm -rf /var/www
    ln -fs /vagrant /var/www
    
    ## Enable errors
    #sed -i "s/error_reporting = .*/error_reporting = E_ALL/" /etc/php5/apache2/php.ini
    #sed -i "s/display_errors = .*/display_errors = On/" /etc/php5/apache2/php.ini
    
    ## Restart  Apache
    #sudo service apache2 restart
    
    ## Composer
    curl -sS https://getcomposer.org/installer | php
    sudo mv composer.phar /usr/local/bin/composer
    
    ## Ruby on Rails : Development
    #curl -L get.rvm.io | bash -s stable
    #source ~/.rvm/scripts/rvm
    #rvm install ruby
    #gem install rails
    
    ## Ruby on Rails : Production
    ## See https://github.com/joshfng/railsready
    #wget --no-check-certificate https://raw.github.com/joshfng/railsready/master/railsready.sh && bash railsready.sh
    
    You'll see there is a section where I remove /var/www and replace it with a symbolic link to /vagrant. /vagrant is the link to the folder where the VM was launched with the "vagrant up" command. The install.sh file goes in the same folder that the Vagrant VM is launched from.

    When you initialise Vagrant in a folder it creates a text file named "Vagrantfile" which you can edit. It comes with a warning not to edit it unless you know what you're doing so I've included my copy of the file so you can see how it's done, the file will then instruct Vagrant to run the install.sh script when the VM is launched.

    Vagrantfile:
    # -*- 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|
    
      config.vm.box = "precise64"
    
      config.vm.box_url = "http://files.vagrantup.com/precise64.box"
    
      #config.vm.network :hostonly, "33.33.33.10"
    
      config.vm.network :forwarded_port, guest: 80, host: 8080
    
      # MySQL port forward
      config.vm.network :forwarded_port, guest: 3306, host: 8306
    
      # Provision the system
      config.vm.provision :shell, :path => "install.sh"
    
      # www-root requirement
      config.vm.synced_folder ".", "/vagrant", owner: "www-data", group: "www-data", :nfs => false, :mount_options => ["dmode=777","fmode=666"]
    
    end
    
    You can see the file is for an Ubuntu Precise64 VM (64-bit Ubuntu 12.04 LTS Server). The additions I made to the file:

    MySQL port forward: This will allow you to access the MySQL database port (3306) on the local machine via the forwarded port (8306).

    Provision the system: This is the instruction to run the install.sh script.

    www-root requirement: By default the VM will set the ownership of the /vagrant directory structure to vagrant:vagrant, this can lead to permissions problems in development. The additional line tells the VM to set the owner and group of the share /vagrant structure to www-root:www-root which will get you around any permissions problems that might occur because you will be editing the files locally.

    If you encounter any issues let me know.


  • Registered Users, Registered Users 2 Posts: 6,470 ✭✭✭MOH


    If you're not going the Vagrant route, Notepad++ also has decent remote editing over FTP.

    Or you might find CodeLobster useful, it's a free IDE. The remote editing used to be a bit flaky but I haven't used it in a couple of years since I switched to linux, and they've apparently improved it since then.


  • Advertisement
  • Closed Accounts Posts: 147 ✭✭Stanlex


    Thanks for the suggestions, I really like the idea of having a shell script to download things automatically. Never thought of it really.

    I'm working on a script to download YouTube videos at the moment. Since YouTube changes their ways every year, last years stuff won't work this year.


Advertisement