Install Apache + PHP + MySQL in ubuntu12.04

Source: Internet
Author: User
1, Apache1, install apache2: sudoapt-getinstallapache22, restart apache2: sudoetcinit. dapache2restart3, enter localhost in the browser or 127.0.0.1, if you see it, it indicates that Apache has been successfully installed. Apache is installed by default.

I. Apache 1. install apache2: sudo apt-get install apache2. Restart apache2: sudo/etc/init. d/apache2 restart 3. Enter http: // localhost or http: // 127.0.0.1 in the browser. If yes, Apache is successfully installed. Apache is installed by default.

I. Apache
1. Install apache2:

sudo apt-get install apache2

2. Restart apache2:

sudo /etc/init.d/apache2 restart

3. Enter http: // localhost or http: // 127.0.0.1 in the browser.

It indicates that Apache is successfully installed.
By default, Apache will create a Web directory named www under/var. All Web files to be accessible through a browser should be placed in this directory.

4. To disable apache2, run the following command:

sudo service apache2 stop


Ii. PHP
1. install php (recommended to install the extended php5-gd php5-mysql ):

sudo apt-get install libapache2-mod-php5 php5

2. Restart apache2 to load the PHP module:

sudo /etc/init.d/apache2 restart

3. The default PHP network server root directory is/var/www. Due to the security principles of the Linux system, the file read and write permissions under this directory only allow the root user to operate. Therefore, we cannot create or modify or delete PHP files in the www folder, you must first modify the read and write permissions of the/var/www directory. You cannot modify the File Permission by right-clicking the attribute in the interface manager. You must run the root terminal command:

sudo chmod 777 /var/www

Then you can write html or PHP files.

4. Create a test. PHP file under the Web directory to test whether PHP can run normally:

sudo gedit /var/www/test.php

Then enter:

 
 

Save the file and enter http: // 127.0.0.1/test. php In the browser. If "hello, world!" is displayed !! "And php information, as shown in:

If it is displayed on the webpage, PHP is running properly.

5. If garbled characters appear on the webpage when outputting Chinese characters, add the following code at the end of the/etc/apache2/apache2.conf file:

AddDefaultCharset UTF-8

Restart Apache2 and refresh the webpage.


Iii. MySQL
1. Install the mysql database (apt-get will automatically download and install the latest mysql version ):

sudo apt-get install mysql-server mysql-client

At the end of the installation, enter the root password (the root password is not the Ubuntu root password, but the root password you want to set for MySQL ).

Note: The MySQL configuration file is in the/etc/mysql directory.

To avoid Chinese garbled characters, change the default character set to UTF-8, modify the/etc/mysql/my. cnf file, and add the following in the corresponding location:

[client]default-character-set=utf8[mysql]default-character-set=utf8[mysqld]collation-server = utf8_unicode_ciinit-connect='SET NAMES utf8'character-set-server = utf8

2. Create the testmysql. php file in the/var/www directory and test the connection of php to MySQL. The file content is as follows:

 

Access testmysql. php In the browser. If the connection is successful, "MySQL connection succeeded" is displayed ".

3. Install phpmyadmin-Mysql Database Management

sudo apt-get install phpmyadmin

During installation, You must select Web server: apache2 or lighttpd, as shown in:

Use the Space key to select apache2, press the tab key, and then enter;

Then, you must enter the Mysql database password:


Set the password for phpmyadmin to register the database:


Then, establish a symbolic connection between phpmyadmin and apache2, because the www directory is in the/var/www directory, and phpmyadmin is in the/usr/share/phpmyadmin directory, so:

sudo ln -s /usr/share/phpmyadmin /var/www

Phpmyadmin test: Open http: // localhost/phpmyadmin and you will see the phpMyAdmin logon interface, as shown in:

You can also refer to the site: http://wiki.ubuntu.org.cn/Apache

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.