Troubleshooting PHP 5
Does your browser ask if you want to download the php file instead of displaying it? If Apache is not actually parsing the php after you restarted it, install libapache2-mod-php5. It is installed when you install the php5 package, but may have been removed inadvertently by packages which need to run a different version of php.
If sudo a2enmod php5 returns "$ This module does not exist!", you should purge (not just remove) the libapache2-mod-php5 package and reinstall it.
Be sure to clear your browser's cache before testing your site again. To do this in Firefox 4: Edit â†’ Preferences â€¦ Privacy â†’ History: clear your recent history â†’ Details : choose "Everything" in "Time range to clean" and check only "cache", then click on "Clear now".
Remember that, for Apache to be called, the URI in your web browser must begin with "http://". If it begins with "file://", then the file is read directly by the browser, without Apache, so you get (X)HTML and CSS, but no PHP. If you didn't configure any host alias or virtual host, then a local URI begins with "http://localhost", "http://127.0.0.1" or http://" followed by your IP number.
If the problem persists, check your PHP file authorisations (it should be readable at least by Ubuntu user "apache"), and check if the PHP code is correct. For instance, copy your PHP file, replace your whole PHP file content by "" (without the quotation marks): if you get the PHP test page in your web browser, then the problem is in your PHP code, not in Apache or PHP configuration nor in file permissions. If this doesn't work, then it is a problem of file authorisation, Apache or PHP configuration, cache not emptied, or Apache not running or not restarted. Use the display of that test file in your web browser to see the list of files influencing PHP behaviour.
php.ini development vs. production
After standard installation, php configuration file /etc/php5/apache2/php.ini is set so as "production settings" which means, among others, that no error messages are displayed. So if you e.g. make a syntax error in your php source file, apache server would return HTTP 500 error instead of displaying the php syntax error debug message.
If you want to debug your scripts, it might be better to use the "development" settings. Both development and production settings ini's are located in /usr/share/php5/
so you can compare them and see the exact differences.
To make the "development" settings active, just backup your original php.ini
sudo mv /etc/php5/apache2/php.ini /etc/php5/apache2/php.ini.bak
and create a symlink to your desired settings:
sudo cp -s /usr/share/php5/php.ini-development /etc/php5/apache2/php.ini
or you may of course also edit the /etc/php5/apache2/php.ini directly on your own, if you wish.
PHP in user directories
According to this blog, newer versions of Ubuntu do not have PHP enabled by default for user directories (your public_html folder). See the blog for instructions on how to change this back.
Installing MYSQL with PHP 5
Use any method to install
mysql-server libapache2-mod-auth-mysql php5-mysql
After installing PHP
You may need to increase the memory limit that PHP imposes on a script. Edit the /etc/php5/apache2/php.ini file and increase the memory_limit value.
After installing MySQL
Set mysql bind address
Before you can access the database from other computers in your network, you have to change its bind address. Note that this can be a security problem, because your database can be accessed by other computers than your own. Skip this step if the applications which require mysql are running on the same machine.
$ sudo nano /etc/mysql/my.cnf
and change the line:
bind-address Â Â Â Â Â Â Â Â Â Â = localhost
to your own internal ip address e.g. 192.168.1.20
bind-address Â Â Â Â Â Â Â Â Â Â = 192.168.1.20
If your ip address is dynamic you can also comment out the bind-address line and it will default to your current ip.
If you try to connect without changing the bind-address you will recieve a "Can not connect to mysql error 10061".
Set mysql root password
Before accessing the database by console you need to type:
$ mysql -u root
At the mysql console type:
$ mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('yourpassword');
A successful mysql command will show:
Query OK, 0 rows affected (0.00 sec)
Mysql commands can span several lines. Do not forget to end your mysql command with a semicolon.
Note: If you have already set a password for the mysql root, you will need to use:
$ mysql -u root -p
(Did you forget the mysql-root password? See MysqlPasswordReset.)
Create a mysql database
$ mysql> CREATE DATABASE database1;
Create a mysql user
For creating a new user with all privileges (use only for troubleshooting), at mysql prompt type:
$ mysql> GRANT ALL PRIVILEGES ON *.* TO 'yourusername'@'localhost' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION;
For creating a new user with fewer privileges (should work for most web applications) which can only use the database named "database1", at mysql prompt type:
$ mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON database1.* TO 'yourusername'@'localhost' IDENTIFIED BY 'yourpassword';
yourusername and yourpassword can be anything you like. database1 is the name of the database the user gets access to. localhost is the location which gets access to your database. You can change it to '%' (or to hostnames or ip addresses) to allow connections from every location (or only from specific locations) to the database. Note, that this can be a security problem and should only be used for testing purposes!
To exit the mysql prompt type:
$ mysql> \q
Since the mysql root password is now set, if you need to use mysql again (as the mysql root), you will need to use:
$ mysql -u root -p
and then enter the password at the prompt.
Please, let's say something in which directories mysql stores the database information and how to configure a backup
There is more than just one way to set the mysql root password and create a database. For example mysqladmin can be used:
$ mysqladmin -u root -p password yourpassword
$ mysqladmin -u root -p create database1
mysqladmin is a command-line tool provided by the default LAMP install.
Phpmyadmin and mysql-workbench
All mysql tasks including setting the root password and creating databases can be done via a graphical interface using phpmyadmin or mysql-workbench.
To install one or both of them, first enable the universe repository
I am using Ubuntu server (command line)
I am using a desktop
Use any method to install