Build an Apache + PHP + MySQL environment on Ubuntu

Source: Internet
Author: User
1. Install and test apache package 1.1 install the apache package sudoapt-getinstallapache21.2. Start and test the apache environment sudo/etc/init. d/apache2start access http: // localhost, you can see that the page has "Itw

1. Install and test the apache package

1.1 install the apache package

  1. Sudo apt-get install apache2

1.2. Start and test the apache Environment

  1. Sudo/etc/init. d/apache2 start
Visit http: // localhost and you will see "It works!" on the page !" .

2. Install and test related php packages

2.1 install php-related packages

  1. Sudo apt-get install php5-cli php5-dev libapache2-mod-php5
2.2. test the apache + php environment and create a test. php file in the/var/www/directory. The content is as follows:
  1. Phpinfo ();
  2. ?>
2.3 restart apache2
  1. Sudo/etc/init. d/apache2 restart
Access http: // localhost/test. php to view the environment information of apache and php.

3. Install and test mysql and related packages

3.1 install mysql-related packages

  1. Sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql
3.2 Test mysql. Run the following command to log on to mysql
  1. $ Mysql-u -P
3.3 test apache + php + mysql

3.3.1 restart apache2

  1. Sudo/etc/init. d/apache2 restart
3.3.2 create a testdb. php file in the/var/www/directory. The content is as follows:
  1. $ Conn= Mysql_connect ("Localhost","Root","Mysql","Mysql");
  2. If(!$ Conn){
  3. Echo("Unable to connect to database .");
  4. }Else{
  5. Echo("Connect to database successful .");
  6. }
  7. Mysql_close ($ Conn);
  8. ?>
3.3.3 access http: // localhost/testdb. php. If "Connect to database successful." is displayed, the apache + php + mysql environment is successfully set up.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.