1. Install and test the Apache package
1.1 install the Apache package
Sudo apt-Get install apache2
1.2. Start and test the Apache Environment
Sudo/etc/init. d/apache2 startVisit http: // localhost and you will see "It works!" on the page !" .
2. Install and test related PHP packages
2.1 install PHP-related packages
Sudo apt-Get install php5-cli php5-dev libapache2-mod-php52.2. Test the Apache + PhP environment and create a test. php file in the/var/www/directory. The content is as follows:
<? Php <br/> phpinfo (); <br/>?>2.3 restart apache2
Sudo/etc/init. d/apache2 restartAccess 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
Sudo apt-Get install mysql-server libapache2-mod-auth-mysql php5-mysql3.2 Test mysql. Run the following command to log on to MySQL
$ Mysql-u <username>-P <password>3.3 test Apache + PHP + MySql
3.3.1 restart apache2
Sudo/etc/init. d/apache2 restart3.3.2 create a testdb. php file in the/var/www/directory. The content is as follows:
<? Php <br/> $ conn = mysql_connect ("localhost", "root", "MySQL", "MySQL"); <br/> If (! $ Conn) {<br/> echo ("unable to connect to database. "); <br/>}else {<br/> echo (" connect to database successful. "); <br/>}< br/> mysql_close ($ conn); <br/>?>3.3.3 access http: // localhost/testdb. php. If "connect to database successful." is displayed, the Apache + PHP + MySQL environment is successfully set up.