How to run PHP and mySQL in openSUSE

Hi to all,

I’m a PHP developer and have been using xampp/wamp under Windows. I just decided to have a try at web development under Linux and would like to do this on my oS 12.3 VMware installation. I would like to know :

1- How do I run PHP and mySQL services? (Names of required packages and procedure to start the service will be helpful)
2- Where do I place my PHP files and which local URL can I use to run the PHP files?
3- Where are the mySQL database files located?
4- Any helpful information on running PHP/mySQL commands from the terminal

(5- Python too, any helpful info on how to run Python files)

I’m sorry if my questions are too many and thanks in advance for your help.

Cheers

MySQL (well, MariaDB actually, which is a drop-in replacement by the original MySQL author) should be installed by default, you just have to enable automatic start on boot:

sudo systemctl enable mysql

For PHP I guess the easiest would be to just install the LAMP pattern: Enter YaST->Software Management, select “View”->“Patterns” and search for “Web and LAMP server” in the list on the left (in the “Server Functions” category). Tick it and click “Accept”. This should install both Apache and PHP.

Then enable automatic start on boot for apache:

sudo systemctl enable apache2

And you should have a working webserver after reboot. Call “http://localhost/” in a webbrowser to check.

2- Where do I place my PHP files and which local URL can I use to run the PHP files?

The default location is /srv/www/htdocs/, you can access them with just “http://localhost/” then.
There’s also a public_html directory in your home dir, which can be accessed with “http://localhost/~username/”…

3- Where are the mySQL database files located?

In /var/lib/mysql/ by default.

4- Any helpful information on running PHP/mySQL commands from the terminal

(5- Python too, any helpful info on how to run Python files)

I don’t quite understand. What do you mean with running PHP commands from the terminal?
You can run php scripts with “php filename.php”, is that what you mean?. The same with python.
Or add something like “#!/usr/bin/python” at the top of your script and make it executable.

For mySQL commands, just run “mysql -u root” and enter them. (or use any other user)

On 2013-08-21, wolfi323 <wolfi323@no-mx.forums.opensuse.org> wrote:
>> (5- Python too, any helpful info on how to run Python files)
> I don’t quite understand. What do you mean with running PHP commands
> from the terminal?
> You can run php scripts with “php -filename.php-”, is that what you
> mean?. The same with python.
> Or add something like “#!/usr/bin/python” at the top of your script and
> make it executable.

Perhaps I’m missing something obvious here, but the basic way to run a python script is

either:


sh-4.2$ python file.py

…or:


sh-4.2$ python
Python 2.7.3 (default, Apr 14 2012, 08:58:41) [GCC] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> execfile("file.py")

Yes, of course. That’s what I wanted to imply with “The same with python.”
I guess I should have been more explicit there, sorry.

Besides what has been posted

Install the LAMP pattern for a fully functional PHP/MySQL setup, fully configured.

Ordinarily you place your website files in /srv/www/htdocs , in fact if you install a full PHP based framework you may only need to copy some bootstrap files there and open a web browser to Localhost which will not only complete installing web pages but also create your MySQL database complete with tables, relationships, autentication, etc

PHP files can be run standalone but that’s not likely what you want… You likely want a PHP website running in Apache webserver.

Most people manage/modify their MySQL from a terminal, typically does not require any knowledge where files are located.

TSU

If you want to use the same data as you have used in Windows, use

mysqldump -u root -p --all-databases > [path to]backup.sql

to make a back up your existing mysql files.

mysql -u root
souce [path to]backup.sql;
flush privileges;

to install them in openSUSE.

When mysql/mariadb is initially installed, mysql.user has no passwords; this will carry over all the users, passwords and databases you had in Windows.

A big huge thank you to all for your help!! All your posts have been very extremely super helpful. I had everything set, up and running in no time at all.

Thanks again to everyone who replied to this thread.
Cheers

PS: Only one last little question: how can I get phpmyadmin? Is there some sort of phpmyadmin package? (I could not find one from Yast)

This is included in standard 12.3, see here: software.opensuse.org:

So you should be able to install it with just “sudo zypper in phpMyAdmin” or YaST.

But I never used this package myself, so can’t tell you how to set it up, maybe it “just works” after installing the package?

software.opensuse.org: Download openSUSE 12.3 is your friend :), see software.opensuse.org:

Well, I tried it now:
Just install the package and point your browser to “http://localhost/phpMyAdmin/”.

And you’ll find the config file in /etc/phpMyAdmin/ …

Mind, before being able to use phpMyAdmin you have to create a password for the mysql root user. Once that is done, my habit is to create a user per database, and login to phpMyAdmin as that user. Plus one user that has privileges for all databases.

Thanks but I am unable to perform live downloads from the Internet. Is there an RPM version of the phpmyadmin installer anywhere which I can download seperately and install offline?

Download it here:
http://download.opensuse.org/update/12.3/noarch/phpMyAdmin-4.0.5-1.8.1.noarch.rpm

And then install it with:

sudo rpm -i phpMyAdmin-4.0.5-1.8.1.noarch.rpm

That’s a “noarch” package, so suited for 32bit as well as 64bit systems…