Solution made with pear, db and Smarty

Hi,

I’ve installed these on my PC:

Ubuntu 14.04.1 LTS
Apache 2.4.7
PHP 5.5.12
PEAR 1.10.0
DB 1.10.0
MySQL 14.14

When I write this into bash:
php --ini

it gives me:
Configuration file (php.ini) Path: /usr/local/lib
Loaded Configuration file: (none)
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)

But then in browser phpinfo() gives me:

Configuration File (php.ini) Path /etc/php5/apache2
Loaded Configuration File /etc/php5/apache2/php.ini
Scan this dir for additional .ini files /etc/php5/apache2/conf.d
Additional .ini files parsed /etc/php5/apache2/conf.d/05-opcache.ini,
/etc/php5/apache2/conf.d/10-pdo.ini,
/etc/php5/apache2/conf.d/20-json.ini,
/etc/php5/apache2/conf.d/20-readline.ini

Why the outputs are so different?

I’m having a website(created in WAMP with Smarty) in html-folder: /var/www/html/website

but in the browser(localhost/website) when I try to use website, the browser gives totally empty.

Yes I know: use Composer and use newer platforms etc. I’m not in the postion that I could convert the whole solution to other platform.

Is there anything someone would suggest? Please help

PHP and PEAR I’ve already tested, they are working properly.

Ok, found out that PEAR isn’t working properly, browser gives this error:

Warning: require_once(System.php): failed to open stream: No such file or directory in /var/www/html/check_pear.php on line 2

Fatal error: require_once(): Failed opening required ‘System.php’ (include_path=’.:/usr/share/php:/usr/share/pear’) in /var/www/html/check_pear.php on line 2

Can’t find the rigth php.ini -file.

Well those sound correct to me. If you want to use Wamp, you must place your site you are testing in the folder under Wamp folder named www. So, it might be something like D:\WAMP\www\MySite…
In that folder, you would place all the files for the site.

Then, on the WAMP control in the tray, LEFT-CLICK on it and select LOCALHOST and it should open a browser starting at the ROOT of your WAMP server page. On this page is your server’s configuration, various tools and your site projects. The sites you put under the WAMP\www folder show up as projects. You can open the one you are working on and test it from there.

Hope that helps…

I can’t use WAMP.

This is my platform:

Ubuntu 14.04.1 LTS
Apache 2.4.7
PHP 5.5.12
PEAR 1.10.0
DB 1.10.0
MySQL 14.14

As I mentioned, I’m not in the position that I could convert the whole solution to other platform.

Okay, do you have Ubuntu or are you using Ubuntu Desktop on your computer?
If you just have Ubuntu Desktop installed on your computer, you access it’s localhost the same as Windows.
But, you need to know the port number in some cases. With Wamp or Ubuntu running, just bring up your browser and type in localhost and press return.
I found one note online that with your setup, you might need to use: localhost:4567
This included their default port number of 4567, but, depends on your setup.

( PS: I talked about WAMP because that is what you said the website was created under! )

I use ubuntu desktop.

Now, I’ve reinstalled the whole stack:

Ubuntu 14.04.5 LTS (with ubuntu desktop)
Apache/2.4.7
PHP 5.5.9-1ubuntu4.25
PEAR 1.9.4
DB 1.7.14
mysql Ver 14.14 Distrib 5.5.61

My apache error log gives errors:

[Tue Aug 21 09:19:57.729511 2018] [:error] [pid 1260] [client ::1:38799] PHP Warning: mysql_set_charset(): Access denied for user ‘’@‘localhost’ (using password: NO) in /UserHelper.class.php on line 163
[Tue Aug 21 09:19:57.729689 2018] [:error] [pid 1260] [client ::1:38799] PHP Warning: mysql_set_charset(): A link to the server could not be established in UserHelper.class.php on line 163
[Tue Aug 21 09:19:57.729748 2018] [:error] [pid 1260] [client ::1:38799] PHP Fatal error: Call to undefined method DB_Error::query() in UserHelper.class.php on line 163

How and where can I declare mysql username and pw?

I’ve installed an extension that should work with mysql_set_charset() ---->php5-mysqlnd, still gives error.
I have no idea why DB is not working. Could this website be so DB-version sensitive?

This says that you did not set the password in your conneciton string.
Normally, well, every time I have ever seen, you need to set a password and username after you have created a MySQL client. On a server, you go into the PHPmyadmin for MySQL and set it there or in your server’s control panel.

Now, under Ubuntu Desktop, you basically have to do some root commands to get a username access to your MySQL system. You assign a username and password using a command something like:
CREATE USER ‘mynewuser’@‘localhost’ IDENTIFIED BY ‘goodPassword’; under root control.
(I got this sample from a website I think is good for you to review.)

You can use NO password, but, then you have to rewrite the code when you put the site onto a server.
Much easier to do it the same way you would on a live web server. So, read up on this site as they list
most of the commands you need to use and should help you sort it out. Look at Securing-MySQL section!
MySQL on Ubuntu
Give it a try and if it fails, send us the new error messages. Good luck!

This is line 163:

$db = DB::connect(DSN);mysql_set_charset(‘utf8’);$db->query(“SET NAMES ‘utf8’”);

I’m unfortunately not allowed to reveal the code too much.

Should I configure DB somehow?

Configuration file needed the root pw. Don’t give error more about connecting to mysql. But still gives this:

[Wed Aug 22 09:40:17.176036 2018] [:error] [pid 1255] [client ::1:37863] PHP Fatal error: Call to undefined method DB_Error::query() in /var/www/html/blah/blah/blah/blah/UserHelper.class.php on line 163

Maybe it’s about the DB -version…?

Well, first, "config file needed the root pw means that you did not set up the base system correctly.
Most likely, you did NOT set up Ubuntu and MySQL correctly. Did you walk thru the link above for the
MySQL on Ubuntu and set up the root pw, etc.???

Assuming you read the link and have set up MySQL correctly, set up a DB and table, and lastly set a username and password for a client to be able to connect to the DB, then you show a connection like:
( Normally, this would be done at the top of the page not down as far as line 163… but… )

This is really:

$db = DB::connect(DSN);
mysql_set_charset(‘utf8’);
$db->query(“SET NAMES ‘utf8’”);

So, the first one is the connection. That is not correct as no DB-Table, username or password is set…
And, who knows what is in the DSN variable. Next you set the UTF8 twice, which is not standard.
Here is one sample setting up PDO. Not sure, but, the DB connection makes me think you wanted to use PDO not MySQLi … This sample is PHP for PDO connections.

<?php try { $conn = new PDO("mysql:host=localhost;dbname=someDBname", "root", "mySecretDBpass"); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); echo 'Connected to the database.
'; $sql = 'SELECT name FROM employee'; echo "Employee Names:
"; foreach ($conn->query($sql) as $row) { echo $row['name'] . "
"; } $conn = null; } catch(PDOException $err) { echo "ERROR: Unable to connect: " . $err->getMessage(); } ?>

Not my code, just a sample I grabbed to show you.

I didn’t understand why there should add a user, isn’t root enough to access MySQL?

My task giver installing guide says nothing about a table, only DB. What is it? I do have a source file, which I’ve runned into mysql.

yes, if you are using EVERYTHING in command line mode…

In programming, you need to assign a user and password to give them permission to access the database.

A DB is a database. It houses the tables inside it. Each table houses fields to hold the data. Each field is assigned a field-type such as integer, text, var-char, boolean, etc. Inside each field is stored the data you use.

If you are planning to create scripts to just run under command lines, then you do not connect the same way you do in a program or website. Not sure what you need help with. Normally if you install all of those products on your system, you are trying to set up a website and use the pear, php, etc to program the site to create data from your database or whatever you are attempting. Running scripts in command line is tedious at best. Perhaps you need to tell us what you are attempting to create.

I know what database is. But this DB isn’t a database.
DB is a database abstraction layer for PEAR, DB.php:

https://pear.php.net/package/DB

I also do have db.sql, which I’ve runned into MySQL. And there is the database needed.

It doesn’ matter how I’m going to get the pages working on my computer. And then if I start to understand the structure of pages, I may do some improvements. Now my browser is just empty when I’m attempting run pages folder in localhost. All other test .php-files have worked properly.

Sorry if I bothered you. But, let’s be clear, Pear is just an add-on for PHP. So, anything you do in Pear it is just a PHP program. DB is DB is Database. So, a file named DB.php is a PHP script. For some unknown reason they decided to call it DB. It is just an outdated program that is no longer supported. But, I have used a lot of apps and add-ons that are outdated and do not have any issues.

I looked back at your original post and see where you mentioned /var/www/html/website as where you created your website. The one that won’t show in the browser. I have a WAMP setup on this computer with a lot of add-ons, not smarty and not the Pear-DB.php file and all my sites work well. But, none are set up with a server layout like the /var folders. I looked at the base set up and they are all under d:/wamp64/www/site-name. Looking back to your post, you said you installed an operating system Ubuntu on your Windows PC. This becomes an emulator. Then, you installed Apache web-server under that I assume. Then added in PHP, Pear, DB and MySQL. Then you mentioned WAMP which in itself is a web-server emulator and you have a website created in it. So, as I first stated, you have two different worlds going on here. If you need Pear and DB running so you can use the localhost thru Wamp, you need to install those on the WAMP not the others. If you need help installing Pear on Wamp, try this: pear on wamp Bash is not part of Wamp, so I am still guessing that you are confused on where your website needs to be to view locally on your localhost. But, then again, I might not understand your issues at all.

I thank you for your effort. The situation is hard to describe, because english is not my native language. But I’ll try once:

These pages I’m trying to see in my browser are made with wamp in a windows machine(pc) in an other machine(pc) many years ago. My laptop computer has just one and only operating system Ubuntu 14.04 LTS(Long Term Support) and nothing besides. Pages are made with php 5.5.12 and they are dependent of old DB. These pages are dependent of php5 because the old DB do not work with newer versions of php, and php5 do not work with newer versions onf Ubuntu. My task is to make improvements to pages just and only with Linux, not with windows.

Ocellata, thank you for the details. When you keep mentioning Wamp, I assumed you were using it on a Windows PC. Now I understand you are using just an Ubuntu Machine. That is where I was confused.

Are you using this Ubuntu machine as your webserver?

If so, you need to run a few commands to set up HTTP under your Apache system to allow them to get out to the browser. I do not have a Ubuntu machine set up to test for you except a small RaspBerry-Pi version, but it is very limited. I did do some looking around for you and found this article that makes it look very simple to do. Perhaps it will help: Hosts on Apache on Unbunto
Hope it helps. And, I am very sorry for my confusion on what you need for help.

Not webserver, just for developing in localhost.

Okay. GOOD! Now I understand your set up better. That link might solve it for you. I noticed it had some commands to link the HTTP (thru localhost) that is needed to make it work. Let me know…

Ok, I found solution.

There is a DSN defining in a certain file called config.php and there’s a line:

define("DSN", 'mysql://root:password@localhost/[database_name]');

This [database_name] in my config.php -file was wrong. I changed it to correct name and the page started to work!
Could you believe that I fought with this for over three months? :crazy_face:

Sponsor our Newsletter | Privacy Policy | Terms of Service