0

I have a website that works without problems in WAMP. Recently I moved to Ubuntu, so I installed LAMP and all looks fine: localhost in browser shows the Apache2 Ubuntu Default Page.

Created an info.php file with the content:

<?php
phpinfo();
?>

Accessing the file with http://localhost/info.php in the browser works and displays the php info.

But trying to access my website with http://localhost/index.php doesn't load the website. I have put all required files in the var/www/html folder (where the info.php file also is and works).

Is there anything else I have to do to be able to load my website?

Additional info: The file /etc/apache2/mods-enabled/dir.conf has the below content:

<IfModule mod_dir.c>
    DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Edit 1:

ls -la /var/www/html/in* will list 3 files I have:

-rw-r--r-- 1 root          root          10918 Jul 21 19:18 /var/www/html/index.html
-rwxrwxrwx 1 mihail-cosmin mihail-cosmin  3931 Apr 26  2017 /var/www/html/index.php
-rw-r--r-- 1 root          root             20 Jul 21 20:55 /var/www/html/info.php

index.html and info.php work, they belong to user and group root. index.php which doesn't work, belongs to my user and group

I have set the user and group in etc/apache2/envvars but it still doesn't work:

export APACHE_RUN_USER=mihail-cosmin
export APACHE_RUN_GROUP=mihail-cosmin

Edit 2:

I realized that on Windows I was using an older version of PHP, more exactly: PHP 5.6. I went back on windows and changed the version in WAMP to a newer one, and my website stopped working there also, obviously.

On Ubuntu I installed the older version 5.6 and changed it for Apache also:

sudo a2enmod php5.6
Considering dependency mpm_prefork for php5.6:
Considering conflict mpm_event for mpm_prefork:
Considering conflict mpm_worker for mpm_prefork:
Module mpm_prefork already enabled
Considering conflict php5 for php5.6:
Enabling module php5.6.
To activate the new configuration, you need to run:
  systemctl restart apache2

But still my website doesn't work.

5
  • What happens if you just visit http://localhost/ ? – Amith KK Jul 22 '18 at 12:30
  • ´ localhost ´ in browser shows the Apache2 Ubuntu Default Page. – Mihail-Cosmin Munteanu Jul 22 '18 at 14:17
  • Can you give me the output of ls -la /var/www/html/index* – Amith KK Jul 22 '18 at 14:30
  • -rw-r--r-- 1 root root 10918 Jul 21 19:18 /var/www/html/index.html -rwxrwxrwx 1 mihail-cosmin mihail-cosmin 3931 Apr 26 2017/var/www/html/index.php – Mihail-Cosmin Munteanu Jul 22 '18 at 16:24
  • Remove index.html from that folder – Amith KK Jul 23 '18 at 4:38
0

I found the solution. I will add all steps I took, just in case it will help someone else when moving from Windows to Ubuntu.

1.There was no reason why my website shouldn't have worked. So the problem must have been the code inside index.php. So the first thing you should do is activate php errors. So I added this in my index.php:

 error_reporting(E_ALL);    
 ini_set('display_errors', TRUE);    
 ini_set('display_startup_errors', TRUE);

2.The first error I got was about the path to other php files. Probably due to the differences between Windows and Ubuntu.

Warning: require_once(/main/dbconnect.php): failed to open stream: No such file or directory in /var/www/html/index.php on line 7

Fatal error: require_once(): Failed opening required '/main/dbconnect.php' (include_path='.:/usr/share/php') in /var/www/html/index.php on line 7

The solution for this was to add a dot in front of the path ./main/dbconnect.php

3.After this I got a new error, about the connection to the SQL database:

Warning: mysqli_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: YES) in /var/www/html/main/dbconnect.php on line 4
ERROR: Could not connect. Access denied for user 'root'@'localhost' (using password: YES)

The problem, this time was that the password had special characters. The solution was to change the password to something simple, as 12345.

After this my website started working.

In conclusion the overall solution was to adapt the code in my files to the Ubuntu system.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.