This page has been automatically translated. Click here to open the original page

Setup Apache2, MySQL and PHP5 on Ubuntu linux





Apache2, MySQL, PHP Last weekend I decided to give a purpose to an old PC (Pentium III with 128MB RAM and 30GB HD) on which a few months ago I installed Ubuntu Server 6.0.6. As always what I was missing was an offline test environment that allowed me to try the changes and new features to be added to my site not make them hot, I needed to install and configure Apache2, MySQL and PHP5.


Starting from a guide on html.it, here is the steps I followed:

  • Update list of available packages (it is always good practice to do before the new facilities):

     sudo apt-get update 
  • Installing Apache2:
     sudo apt-get install apache2-mpm-prefork 
  • Installing MySQL:
     sudo apt-get install mysql-server 
  • Install the PHP5 module for Apache2:
     sudo apt-get install libapache2-mod-php5 
  • Installing the library to use MySQL from PHP5:
     sudo apt-get install php5-mysql 
  • Installing PHP library for image manipulation:
     sudo apt-get install php5-gd 
  • Installing the PHP library to run PHP also from the command line:
     sudo apt-get install php5-cli 
  • Activating the extension on the MySQL configuration file PHP5:
     vi /etc/php5/apache2/php.ini 

    Review of the line

     ;extension=mysql.so 

    in

     extension=mysql.so 
  • Restarting Apache2:
     sudo /etc/init.d/apache2 restart 

Then to test that everything worked properly, I proceeded as follows:

Test integration between Apache2 and PHP5

Creating the test_php.php in / var / www with the following content:

 <?php phpinfo();?> 

With access to a browser 'http://servername/test_php.php URL (where servername is the ip address or the name of the linux server) and check delal display configuration information for PHP5

Test of between PHP5 and MySQL

Create a test db in MySQL:

 mysqladmin -u root create test 

Creating the test_mysql.php in / var / www with the following content:

 <?php $link = mysql_connect('localhost', 'root', '') or die('Connessione fallita: ' . mysql_error()); mysql_select_db('test') or die('Selezione DB fallita: ' . mysql_error()); echo 'OK'; mysql_close($link); ?> 

With access to a browser 'http://servername/test_mysql.php URL (where servername is the ip address or the name of the linux server) and verify the message "OK" indicating that the connection to DB "test" is been successful.

Did you like this article? Subscribe now to receive updates or news articles:
Subscribe to RSS feed Subscribe to RSS feed

Articles related to "Setup Apache2, PHP5 and MySQL on Linux Ubuntu"


Comments

13 Responses to "Setup Apache2, PHP5 and MySQL on Linux Ubuntu"
  1. ilberni writes:

    all the apt-get are really apt-get install

    I also I had to add the repository

  2. davide wrote:

    You're right, thank you for your message! Not even the most 'capable of making good the cut & paste! However now I have corrected.
    You may specify further what other actions you have done? I have left from a Ubuntu Server 6.0.6

  3. vorax writes:

    It 'best on a single line

    otherwise often gives error.

    syntax error, unexpected T_STRING etc. ..

    Hello

  4. lamer01 writes:

    I wanted to tell you that in Test integration between Apache2 and PHP5
    php code that you wrote was a lack:
    must be

  5. lamer01 writes:

    I wanted to tell you that in Test integration between Apache2 and PHP5
    php code that you wrote was a lack:
    should be <?php phpinfo();?>

  6. Joseph writes:

    Excellent tutorial, no matter the error on phpinfo is a clear error of typing:))

    byee

  7. davide wrote:

    Thanks for reporting! I corrected the error.

  8. Athos wrote:

    Athos Athos @-desktop: ~ $ mysqladmin-u root create test
    mysqladmin: connect to server at 'localhost' failed
    error: 'Access denied for user' root '@' localhost '(using password: NO)'

    I thank you from the tutorial here but not go out

  9. ninja writes:

    Hello Athos anke I have the same problem ... someone help us?

  10. mark writes:

    Hello!
    Until testing of integration between PHP and MySQL tt good then when I try to connect to the page I test_mysql generates this error:

    Parse error: syntax error, unexpected $ end in / var / www / test_mysql.php on line 9

    you can help me? thanks

  11. Nicola Giosmin writes:

    Thank you,
    one of the most accurate guide to synthetic and have never used: very useful and accurate, I have done everything in an instant.

  12. ox4r writes:

    @ Athos

    $ link = mysql_connect ( 'localhost', 'root', 'mypassword')

    test files in mysql how to put the password here as otherwise try to connect to Db without pwd.

  13. Tr1t0N writes:

    Hello I have a problem.
    Follow all the instructions, I installed all
    I tried to make it work with e107, but I do not open the site and says that an application x-httpd-php