Apache + MySQL + PHP installation guide

Source: Internet
Author: User

L. a. m. p. (Linux, Apache, MySQL, PPH) is a golden combination of open-source software. Almost every Linux developer or administrator has the opportunity to access lamp. "How to install it? "Is the most asked question. This article will provide a concise guide on how to install Apache, MySQL, and PHP on Linux, hoping to help you.


First, install MySQL

The installation of MySQL is relatively complex. I chose to use the RPM file provided by RedHat for automatic installation, which reduces many mistakes.

Go to the http://dev.mysql.com/downloads/mysql/4.0.html to download the RPM file for MySQL 4.0. Find the Linux x86 RPM downloads column. Generally, you only need four rpm, namely server (standard), client, shared, and devel. We downloaded the four RPM files to the/root directory.

Note: The following commands require the root permission.

Before installation, run the following command to determine whether the MySQL RPM has been installed in your system:

Rpm-Qa | grep "* MySQL *"

If it is displayed that the related MySQL RPM has been installed on your system, we recommend that you delete the RPM first:

Rpm-e rpm_file_name

If the dependency problem occurs, you can use rpm-e -- force -- nodeps rpm_file_name to forcibly delete it.

Make sure that all the RPMs related to MySQL are deleted, and we will start to install MySQL 4.0. In the/root directory, ls displays all the RPM files. You should find the four MySQL RPMs downloaded just now. Start installation:

Rpm-I MySQL-server-4.0.18-0.i386.rpm

Rpm-I MySQL-shared-4.0.18-0.i386.rpm

Rpm-I MySQL-client-4.0.18-0.i386.rpm

Rpm-I MySQL-devel-4.0.18-0.i386.rpm

Note: if an error occurs during the above installation, try to change the order of the above commands.

After successful installation, MySQL mysqladmin and other files will be stored in the/usr/bin directory. And a MySQL file will be added to your/etc/init. d directory. This file is used to automatically start MySQL service every time the system reboot. You can use service MySQL start, service MySQL restart, and service MySQL stop to start, restart, or terminate MySQL service. Run the chkconfig -- LIST command to check whether MySQL service has been added to the service list. If not, run the following command to add MySQL service:

Chkconfig -- add MySQL

Note: If you find that your system does not know the command chkconfig, you can try/sbin/chkconfig.

Note: After MySQL rpm is installed, it automatically installs the MySQL built-in database (MySQL and test ).

After installing MySQL, use

Mysqladmin-u Root Password your_new_password

Reset the password of the root user MySQL, such as doodoofish.

Mysqladmin-u Root Password doodoofish

Next time, you must use root and doodoofish as the user name and password to use MySQL:

Mysql-u root-P

After the prompt, enter the doodoofish password and you should be able to access MySQL.

Note: Enter/Q to exit MySQL.

This is not complete yet. For your security, we recommend that you run the following command to protect your MySQL:

Mysql-u root-P

Mysql> use MySQL

Mysql> Delete from user where not (host = "localhost" and user = "root ");

Mysql> flush priviledges;

This forces the user to log on to MySQL using the root account.

It is best to change root to a name that is not easy to guess, for example:

Mysql> Update user set user = "sqladmin" where user = "root ";

Mysql> flush priviledges;

OK, you have successfully installed MySQL, which is the most difficult part to install Apache + MySQL + PHP.


Install Apache

Install Apache is much simpler, go to the http://httpd.apache.org/download.cgi to download httpd-2.0.49.tar.gz to the/root directory.

In the/root directory, enter:

Gunzip httpd-2.0.49.tar.gz

Tar-xvf httpd-2.0.49.tar

A new httpd-2.0.49 directory is created under the/root directory. Move the entire directory to/usr/local/src


Go to the/usr/local/src/httpd-2.0.49 directory


Now, we have started the installation:

-- Prefix =/usr/local/Apache/
-- Enable-shared = max/
-- Enable-module = rewrite/
-- Enable-module = so

If you run the preceding command, there should be no error message. -- Prefix =/usr/local/Apache indicates that Apache is to be installed in the/usr/local/Apache directory.


Compile with make.

Make install

Install Apache.

After the installation is successful, Apache will be stored under/usr/local/Apache.


Install PHP

Similarly, you must first download PHP. Download PHP 4.3.6 (tar.gz) source code from the http://www.php.net/downloads.php (note that it is not binary ). Download to the/root directory.

Gunzip php-4.3.6.tar.gz

Tar-xvf php-4.3.6.tar

Move the new php-4.3.6 directory to the/usr/local/src directory. Switch to the/usr/local/src/php-4.3.6 directory


Next, we will install PHP into a module of Apache.

-- With-apxs2 =/usr/local/Apache/bin/apxs/
-- Disable-Debug/
-- Enable-FTP/
-- Enable-inline-optimization/
-- Enable-safe-mode/
-- Enable-track-vars/
-- Enable-trans-SID/
-- Enable-XML/
-- With-MySQL/
-- With-XML/

There should be no error message.


Make install

Installation is complete. Copy/usr/local/src/php-4.3.6/PHP. ini-Dist to/usr/local/lib/and rename it PHP. ini

CP/usr/local/src/php-4.3.6/PHP. ini-Dist/usr/local/lib/PHP. ini

The installation is successful. Configure Apache as follows.


VI httpd. conf

In the httpd. conf file, add

Addtype application/X-httpd-PHP. php
Addtype application/X-httpd-PHP-source. PHPs

Add the preceding two statements after other addtype statements.

Make sure that the file contains the following sentence. If not, add it after all loadmodules.

Loadmodule php4_module modules/libphp4.so

Okay, ": WQ", save the httpd. conf file, and exit VI. Start Apache server:

/Usr/local/Apache/bin/apachectl start

If you want your Apache to start automatically after every reboot, you can do this:

CP/usr/local/src/httpd-2.0.49/support/apachectl/etc/rc. d/init. d/httpd

VI/etc/rc. d/init. d/httpd

In the third line of the httpd file, insert the following two sentences:

# Chkconfig: 345 85 15
# Description: starts and stops the Apache HTTP Server.

": WQ": Save the httpd file and exit VI.

Turn httpd into an executable file:

Chmod + x/etc/rc. d/init. d/httpd

Add httpd to the service list:

Chkconfig -- add httpd

Check whether httpd is added to the service list.

Chkconfig -- list

After success, you can use service httpd start, service httpd restart, and service httpd stop to start, restart, and terminate HTTPd service (httpd service is Apache service ).

All right, All installation is complete. Let's test PHP and Apache.


Test PHP and Apache

In the/usr/local/Apache/htdocs directory, create a test. php file with only one sentence:

Phpinfo ();?>

Save the file.

Enter http: // localhost in your browser. You should see the Apache welcome page.

Enter http: // localhost/test. php in your browser. You should see the PHP system information.


Finally, your light bulb (L. A. M. P.) is installed successfully. Congratulations!


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.