Configure Apache + PHP + MySql in centos!

Source: Internet
Author: User
Tags localhost mysql mysql commands php write

First;
Download software;
Apachehttp: // apache.mirror.phpchina.com/httpd/httpd-2.2.9.tar.gz
PHP: http://cn.php.net/distributions/php-5.2.6.tar.gz
MySQL: http://mysql.ntu.edu.tw/Downloads/MySQL-5.0/mysql-5.0.51a-linux-i686-glibc23.tar.gz
> -----------------------------------------------------
First
[Root @ localhost] # wget http://apache.mirror.phpchina.com/httpd/httpd-2.2.9.tar.gz
-- 00:47:30 -- http://apache.mirror.phpchina.com/httpd/httpd-2.2.9.tar.gz
Resolving apache.mirror.phpchina.com... 221.194.139.225
Connecting to apache.mirror.phpchina.com | 221.194.139.225 |: 80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 6396996 (6.1 m) [application/X-gzip]
Saving to: 'httpd-2.2.9.tar.gz. 1'

0% [] 36,300 41.3 K/s

[Root @ localhost] Tar zxvf httpd-2.2.9.tar.gz
Decompress the package below
Httpd-2.2.9/srclib/APR-util/test/abts_tests.h
Httpd-2.2.9/srclib/APR-util/test/data/
Httpd-2.2.9/srclib/APR-util/test/DBD. c
Httpd-2.2.9/srclib/APR-util/test/makefile. In
Httpd-2.2.9/srclib/APR-util/test/makefile. Win
Httpd-2.2.9/srclib/APR-util/test/nw_misc.c
Httpd-2.2.9/srclib/APR-util/test/nwgnuaputest
N characters are omitted here.
Go
[Root @ localhost ~] CD httpd-2.2.9
Compile Apache
[Root @ localhost httpd-2.2.9]. /configure -- prefix =/usr/local/Apache -- enable-track-vars -- enable-CGI -- With-config-file-Path =/usr/local/Apache/Conf
It takes some time to compile the code below.
The following is a brief description of the meaning of compilation,
-- Prefix =/usr/local/MySQL/Apache specify to install apahce to the/usr/local/MySQL/Apache directory;
-- Enable-CGI supports CGI;
-- With-config-file-Path =/usr/local/MySQL/Apache/conf specify to put the Apache preparation file in/usr/local/MySQL/Apache/conf; for example, httpd. the conf preparation file is in this directory;
-- Enable-track-vars enables Cookie get/post and other tracing functions
Almost compiled. A prompt is displayed, indicating that Apache is successfully installed,
[Root @ localhost] Make; make install // then input the compile command, which is simple: Make; make install!
Then enter enable apache service.
[Root @ localhost] Server httpd restart
Apache is successfully installed.
Delete lifecycle page
Rm-F/usr/local/Apache/CONF. d/welcome. conf to see the cute 403 error!
========================================================== ========================================================== =
2. install PHP;

Install libxml2-2.7.3.tar.gz before PHP installation

Wget ftp://xmlsoft.org/libxml2/libxml2-2.7.3.tar.gz
Sudo tar-zxvf libxml2-2.6.28.tar.gz
CD libxml2-2.6.28/
./Configure
Make
Sudo make install

[Root @ localhost ~] # Tar zxvf php-5.2.6.tar.gz // extract PHP File
[Root @ localhost ~] # Cd php-5.2.6 // go to the PHP installation directory

[Root @ localhost php-5.2.6] #. /configure -- prefix =/usr/local/MySQL/PHP -- With-mysql =/usr/local/MySQL-with-apxs2 =/usr/local/MySQL/Apache/bin/ apxs -- enable-track-vars -- enable-force-CGI-redirect -- With-config-file-Path =/usr/local/MySQL/PHP/etc/compile PHP

Change

[Root @ localhost php-5.2.6] #./configure -- prefix =/usr/local/MySQL/PHP
Installation:

[Root @ localhost php-5.2.6] # Make
[Root @ localhost php-5.2.6] # make install
Copy PHP. ini-Dist to PhP. ini and put it in the/usr/local/PHP Directory!
[Root @ localhost php-5.2.6] # cp PHP. ini-Dist/usr/local/PHP. ini
Edit the/usr/local/PHP. ini file and find the following line:
; Default_charset = "iso-8859-1"
Add a line below this line
Default_charset = "gb2312
// Combine Apache + PHP
Find the line # addtype application/X-tar. tgz and add a line below. Do not add the # sign before.

Addtype application/X-httpd-PHP. php

Find the following line and add index. php. This indicates that the website's homepage can also be index. php.

Directoryindex index.html. var index. php
Let's take a look at the PHP testing page.
Edit VI/var/www/html/test. php write
Echo >><? Phpinfo ();?> /Var/www/html/test. php. The PHP + Apache installation is successful here.
========================================================== ==============================================
3. Install MySQL;

1] Extract
[Root @ localhost root] # cd/usr/local/MySQL/software

[Root @ localhost software] # ls
Mysql-4.0.16.tar.gz

[Root @ localhost software] # tar zxvf mysql-4.0.16.tar.gz

2] compilation and installation: In this place it is worth noting that we want to install the mysql-4.0.16 to the directory we specify for system and security optimization, we recommend that you store all the server software installed with the source code package in the/usr/local/MySQL directory. So here, we need to install the mysql-4.0.16 to the/usr/local/MySQL directory;
[Root @ localhost software] # cd

[Root @ localhost software] # cd mysql-4.0.16
[Root @ localhost mysql-4.0.16] #
. /Configure -- prefix =/usr/local/MySQL -- With-mysqld-user = beinan -- With-extra-charsets = all -- With-Unix-socket-Path =/usr /local/MySQL/var/MySQL. sock

[Note] A description of configure options:

-- Prefix =/usr/local/MySQL install the mysql-4.0.16 specified to the/usr/local/MySQL directory;
-- With-extra-charsets = all supports multiple languages;
-- With-Unix-socket-Path =/usr/local/MySQL/var/MySQL. sock: Specifies the location and file name of the online socket file after the MySQL server is started. That is, if the MySQL server is started successfully, you can see MySql in the/usr/local/MySQL/var directory. sock file. If not, MySQL cannot start.
-- With-mysqld-user = beinan: This enables the MySQL server to enable the common user beinan in the system to start the MySQL server. Of course, if you want to learn and use it, you can replace beinan with an existing common user in your system. For example, if your system already has a user named Sir, replace beinan with sir. The advantage of starting MySQL with a common user is that the MySQL process will die and automatically exit. Of course, the root user can do the same, but sometimes some MySQL processes are dead, but they will not automatically exit, and the root user cannot kill themselves. Therefore, common users have the following benefits: most of them will not see the MySQL process dead, but will not quit;

[Root @ localhost mysql-4.0.16] # Make
[Root @ localhost mysql-4.0.16] # make install
The installation is complete.
3] preparing MYSQL: installation is only the first step. We need to prepare MySQL accordingly;
In general, MySQL is looking for the configuration file my. CNF, which is located in the/etc directory, so we have to put the file my. CnF in the/etc/directory. Let the MySQL server find it when it is started.

After we install MySQL, the preparation file should be in the/usr/local/MySQL/share/MySQL directory, the preparation file has a few, such as my-huge.cnf my-medium.cnf my-large.cnf my-small.cnf
Websites with different traffic and server environments with different configurations must have different configuration files. Under normal circumstances, the preparation of my-medium.cnf files can meet most of our needs;

Go to the/usr/local/MySQL directory and check whether the directory has been installed ??

[Root @ localhost mysql-4.0.16] # cd/usr/local/MySQL/
[Root @ localhost MySQL] # ls
Bin include info lib libexec man mysql-test share SQL-Example

We copy the my-medium.cnf under the/usr/local/MySQL/share/MySQL directory as my. CNF to the/etc directory.
[Root @ localhost MySQL] # cp/usr/local/MySQL/share/MySQL/my-medium.cnf/etc/My. CNF

After doing this, you have to create a MySQL authorization table. Otherwise, the database cannot be started. Mysql_install_db. This command is used for this purpose. MySQL commands are installed in the/usr/local/MySQL/bin directory.

[Root @ localhost MySQL] #/usr/local/MySQL/bin/mysql_install_db

After running the mysql_install_db command, we can view/usr/local/MySQL and find a var directory. This directory is used to hold all database locations. For example, after we create the linuxsir database, we have the linuxsir directory in the/usr/local/MySQL/var directory. I should have understood this time.

4] It may be easiest to start the MySQL server, but it cannot be too early, because sometimes permission errors may occur.

When the MySQL server is started, it should be mysql. server in the/usr/local/MySQL/share/MySQL directory.
The startup method is:
[Root @ localhost MySQL] #/usr/local/MySQL/share/MySQL. Server start
If it cannot be started, run/usr/local/MySQL/bin/mysqld_safe -- user = root to start it !!
Then, enter/usr/local/MySQL/share/MySQL. Server start to start the instance.
Now, set the password to 123456/usr/local/MySQL/bin/mysqladmin-u Root Password 123456.
If no error is returned, the description is correct.
Enter/usr/local/MySQL/bin/MySQL-u root-P to manage MySQL.
========================================================== ========================================================== ======

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.