Build the best lamp environment under CentOS5.5

Source: Internet
Author: User
Tags mcrypt php software
This article elaborated in the Linux system constructs the PHP environment, because PHP is written by the C language, originally also runs in the Linux system, therefore Linux is the PHP best environment.

The authors of this article are experimenting with CentOS 5.5, which is installed with virtual machines (VMware). The following installation detailed

1. Preparatory work

First, please confirm that you installed the Linux system has installed Apache, MySQL, PHP, if installed please uninstall first.

See if it's installed (Apache, for example)

[Root@gamejzy linux]# Rpm-qa|grep httpd

Note: Rpm-qa is to view all the software that is already installed on this computer. grep httpd is filtering out software related to httpd (Apache). Note: grep php is view php;grep mysql is view MySQL

If there is a null after executing the command, then the Apache software is not installed in the machine, if any, such as the following instructions have been installed.

If so, then you need to uninstall all three of the software.

The uninstall command is as follows:

[Root@gamejzy linux]# rpm-e Httpd-2.2.3-43.el5.centos--nodeps

Note:--nodeps is mandatory uninstall

Second, please ensure that your Linux system installed GCC, g++ compiler

Check whether the installation is simple, typing "GC" or "g+" on the command line, pressing the TAB key to see if there are any commands displayed below.

If not, it doesn't matter, the method of installing GCC and g++ is very simple.

To install GCC:

Yum-y Install GCC

Install g++:

Yum Install gcc-c++


Copy all the software (most of the tar packages) to the/tmp/lamp and unzip

Unzip the tar.gz command (PHP software for example): Tar zxvf php-5.2.6.tar.gz

When this command is finished, a php-5.2.6 folder is created under the current directory, and all extracted files are placed in the php-5.2.6 folder

Please unzip all the packages in the same way, and delete all the *.tar.gz files.

[Root@gamejzy lamp]# RM-RF *.gz

The above command deletes all the. gz files

Iv. Introduction to compiling and installing packages

The process for installing each source code package on a Linux system is as follows:

Configuration (Configure)

Compile (make)

Install (make install)

2, build LAMP environment (please follow the order given below to install)

All the software here is installed under the/usr/local

First, install the Libxml

Installation order: 1, enter the Libxml directory, 2, configuration parameters (including installation path, dependent software, installation function, etc.), 3, compiling, 4, installation. Note: All packages are installed similarly

[Root@gamejzy lamp]# cd Libxml2-2.6.30/[root@gamejzy libxml2-2.6.30]#./configure--PREFIX=/USR/LOCAL/LIBXML2

./configure for the package configuration Parameters command,--prefix represents the specified installation directory, most of the directories are not created automatically, individual will not, we need to manually create

[Root@gamejzy libxml2-2.6.30]# make && make install

The above command is compiled and installed together to execute, due to the small software, installation speed is relatively fast, if the large software, it may take a long time.

Second, installation Libmcrypt

[Root@gamejzy lamp]# cd Libmcrypt-2.5.8/[root@gamejzy libmcrypt-2.5.8]#./configure--prefix=/usr/local/libmcrypt[ Root@gamejzy libmcrypt-2.5.8]# make && make install

Third, installation zlib

[Root@gamejzy lamp]# cd Zlib-1.2.3/[root@gamejzy zlib-1.2.3]#./configure[root@gamejzy zlib-1.2.3]# Make && Make install

Do not follow the--prefix parameter after the./configure to install it in the default directory because zlib is used when installing libpng.

Iv. installation of libpng

[Root@gamejzy lamp]# cd Libpng-1.2.31/[root@gamejzy libpng-1.2.31]#./configure--prefix=/usr/local/libpng[ Root@gamejzy libpng-1.2.31]# make && make install

V. Installation of JPEG6

This software configuration will not automatically create a directory, we need to manually create

[Root@gamejzy libpng-1.2.31]# Mkdir/usr/local/jpeg6[root@gamejzy libpng-1.2.31]# mkdir/usr/local/jpeg6/bin[ Root@gamejzy libpng-1.2.31]# Mkdir/usr/local/jpeg6/lib[root@gamejzy libpng-1.2.31]# mkdir/usr/local/jpeg6/include[ Root@gamejzy libpng-1.2.31]# mkdir-p  /usr/local/jpeg6/man/man1

Build directory Complete!

[Root@gamejzy lamp]# cd Jpeg-6b/[root@gamejzy jpeg-6b]#./configure--prefix=/usr/local/jpeg6/--enable-shared-- Enable-static[root@gamejzy jpeg-6b]# make && make install

Description of the parameters in./configure:

--enable-shared Creating a shared library using the GNU Libtool

--enable-static creating a static library using the GNU Libtool

Vi. installation of FreeType

[Root@gamejzy lamp]# cd Freetype-2.3.5/[root@gamejzy freetype-2.3.5]#./configure--prefix=/usr/local/freetype[ Root@gamejzy freetype-2.3.5]# make && make install

Vii. installation of autoconf

[Root@gamejzy lamp]# cd Autoconf-2.61/[root@gamejzy autoconf-2.61]#./configure[root@gamejzy autoconf-2.61]# Make && make Install

This software is installed directly in the default directory.

Viii. installation of GD

[Root@gamejzy lamp]# cd Gd-2.0.35/[root@gamejzy gd-2.0.35]#./configure--prefix=/usr/local/gd2--with-jpeg=/usr/ local/jpeg6/--with-png=/usr/local/libpng/--with-freetype=/usr/local/freetype/[root@gamejzy gd-2.0.35]# Make & & Make Install

Description of the parameters in./configure:

--with-jpeg=/usr/local/jpeg6/specify where to find the JPEG library file
--with-png=/usr/local/libpng/specify where to find the PNG library file
--with-freetype=/usr/local/freetype/specify where to find the location of the FreeType 2.x font library

Note The following error may occur when you install this package, as shown in:

If this error occurs, the workaround:

[Root@gamejzy gd-2.0.35]# VI gd_png.c

Find the keyword "png.h" command:/png.h Enter

To be replaced by:/usr/local/libpng/include/png.h

The effect is as follows:

Save to exit and proceed with "make && make install" to perform the installation successfully.

Nine, install Apache (key)

[Root@gamejzy lamp]# cd Httpd-2.2.9/[root@gamejzy httpd-2.2.9]#./configure--prefix=/usr/local/apache2--sysconfdir= /ETC/HTTPD--with-included-apr--enable-so--enable-deflate=shared--enable-expires=shared--enable-rewrite=shared- -enable-static-support[root@gamejzy httpd-2.2.9]# make && make install

Description of the parameters in./configure:

--SYSCONFDIR=/ETC/HTTPD Specify the location of the Apache server configuration file (httpd.conf, etc.)
--with-included-apr using a copy of bundled Apr/apr-util
--enable-so compiled with dynamic shared object (DSO)
--enable-deflate=shared reduction of transmission encoding support
--enable-expires=shared Expiry Head Control
--enable-rewrite=shared rule-based URL manipulation
--enable-static-support creating a statically linked version of support

Test Apache Server

1, check whether the/usr/local/appears apache2 directory;

2, check the/etc/directory below whether there is httpd directory, that is, there are httpd.conf files, extra directory and other content

3. Open Apache Server

[Root@gamejzy httpd]#/usr/local/apache2/bin/apachectl start

Stop (off), restart (restart)

4, check whether the Apache server is started, that is, to see whether Port 80 is started

[Root@gamejzy httpd]# Netstat-tnl|grep 80

After executing the command, the following appears, indicating that it has started

TCP 0 0::: +:::* LISTEN

5. Access in the browser

If you are on this computer, enter: localhost or 127.0.0.1 in the browser address bar

If it is a remote connection, such as SSH connection, please enter the IP address of Linux in the browser address bar. For example: 192.168.1.233

If the page appears in a large font "

It works!

"Indicates that Apache installation was successful.

Test finished!

Add Apache to boot automatically every time you boot

[Root@gamejzy/]# echo "/usr/local/apache2/bin/apachectl start" >>/etc/rc.d/rc.local

Ten, install MySQL (important)

Create a MySQL-specific group and user name before installing MySQL

Set up a group called "MySQL"

[Root@gamejzy/]# Groupadd MySQL

Create a user named "MySQL" and let him belong to the "MySQL" group

[Root@gamejzy/]# useradd-g MySQL MySQL
[Root@gamejzy lamp]# cd Mysql-5.0.41/[root@gamejzy mysql-5.0.41]#./configure--prefix=/usr/local/mysql-- With-extra-charsets=all[root@gamejzy mysql-5.0.41]# make && make install

The./configure parameter Description:

--with-extra-charsets=all install all the MySQL character sets

Note that the following error occurs when the./configure

Cause: The ncurses installation package is missing.

Workaround: Download and install the appropriate package

Yum list|grep ncursesyum-y Install Ncurses-devel

Ncurses after the installation is complete, then proceed with the./configure Configuration!

After MySQL installation is complete, set up some content, these content is very cumbersome, but very critical, I hope you will be patient to learn.

1, set the configuration file my.cnf, placed in the/etc/directory

[Root@gamejzy mysql-5.0.41]# CP support-files/my-medium.cnf/etc/my.cnf

2, initialize the database files, after the installation of MySQL, and will not appear MySQL data files and data storage location

First switch to the MySQL installation directory

[Root@gamejzy mysql-5.0.41]# cd/usr/local/mysql/

Initialize the database file using the mysql_install_db in the bin directory and use the MySQL user built above

[Root@gamejzy mysql]# bin/mysql_install_db--user=mysql

After running, you will find that the MySQL installation directory will be more than a var directory, which is placed in the database files, including our built database will be placed in this directory.

3. Set MySQL installation directory permissions

Change the owner of all files and directories under directory root

[Root@gamejzy mysql]# chown-r root.

Change the owner of the Var directory to the MySQL user

[Root@gamejzy mysql]# chown-r MySQL./var/

Change all directories and files of the user group to MySQL group

[Root@gamejzy mysql]# chgrp-r MySQL.

4. Start MySQL

[Root@gamejzy mysql]#/usr/local/mysql/bin/mysqld_safe--user=mysql &

& indicates startup in background

At this point, using NETSTAT-TNL, if you see Port 3306, then the boot success

TCP 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN

5, set permissions, if we now directly use the bin directory under the MySQL command, then you can log in

[Root@gamejzy mysql]# Bin/mysql

It's too dangerous! Therefore, you need to set permissions.

Log in to MySQL first, use the SQL command to delete the host is not "localhost" user name (MySQL users in MySQL library user table), only allow the native login account.

Mysql> Delete from Mysql.user where Host! = ' localhost ';

Refresh Authorization Table

mysql> flush Privileges;

Set the password for the root user that allows this computer to enter MySQL

mysql> set password for ' root ' @ ' localhost ' =password (' 123456 ');

Note: The password you set must be remembered, or you will not be in the MySQL database.

At this point, our root user has set the password (password is "123456"), we can test, type "Exit" to exit MySQL

The command to log in to the MySQL database at this point cannot be as simple as bin/mysql.

[Root@gamejzy mysql]# bin/mysql-h 127.0.0.1-u root-p123456

-H Specify Host name

-U user Name

-p password

6. Close MySQL Database server

[Root@gamejzy mysql]# bin/mysqladmin-u root-p shutdown

Here is the root user is the user in MySQL, after execution will prompt you to enter the password, enter password:

Enter the password, and enter to close the database.

To start the command, see this section 4

7. Add to boot default boot

[Root@gamejzy mysql]# echo "/usr/local/mysql/bin/mysqld_safe--user=mysql &" >>/etc/rc.d/rc.local

Xi. Installation of PHP (important)

Here we install the high version of PHP php-5.3.19, installation parameters are more, please be careful.

[Root@gamejzy lamp]# cd Php-5.3.19/[root@gamejzy php-5.3.19]#./configure \>--prefix=/usr/local/php \>-- With-config-file-path=/usr/local/php/etc \>--with-apxs2=/usr/local/apache2/bin/apxs \>--with-mysql=/usr/ local/mysql/\>--with-libxml-dir=/usr/local/libxml2/\>--with-png-dir=/usr/local/libpng/\>-- with-jpeg-dir=/usr/local/jpeg6/\>--with-freetype-dir=/usr/local/freetype/\>--with-gd=/usr/local/gd2/\ >--with-mcrypt=/usr/local/libmcrypt/\>--with-mysqli=/usr/local/mysql/bin/mysql_config \>--enable-soap \ >--enable-mbstring=all \>--enable-sockets

The./configure parameter Description:

--with-config-file-path=/usr/local/php/etc specify the path to the PHP5 configuration file
--with-apxs2=/usr/local/apache2/bin/apxs tells PHP where to find Apache 2
--with-mysql=/usr/local/mysql/specifying the installation directory for MySQL
--with-libxml-dir=/usr/local/libxml2/tells PHP where to place the LIBXML2 library
--with-png-dir=/usr/local/libpng/tells PHP where to place the libpng library
--with-jpeg-dir=/usr/local/jpeg6/tell PHP where to place the JPEG library
--with-freetype-dir=/usr/local/freetype/tells PHP where to place the FreeType library
--with-gd=/usr/local/gd2/tell PHP where to place the GD library
--with-mcrypt=/usr/local/libmcrypt/tells PHP where to place the Libmcrypt library
--with-mysqli=/usr/local/mysql/bin/mysql_config variable activates the newly added mysqli function
--ENABLE-SOAP variable activation soap and Web services support
--enable-mbstring=all enables multibyte string support
--enable-sockets variable activation socket communication feature

Problems with compiling may occur:

The following error occurred:

Workaround:

Cd/usr/local/mysql/lib/mysql/ln-s libmysqlclient.so.15.0.0 libmysqlclient_r.so

After compiling OK, the "Thank for using PHP." appears, stating that the configuration was successful.

[Root@gamejzy php-5.3.19]# make && make install

Compile and install, time will be longer, wait patiently!

After the compilation is complete, the following configuration is required

1. setting php.ini configuration file

[Root@gamejzy php-5.3.19]# CP Php.ini-development/usr/local/php/etc/php.ini

Note:/USR/LOCAL/PHP/ETC is the location specified at the time of configuration

2. Integration with Apache

Open the Apache configuration file First httpd.conf

[Root@gamejzy php-5.3.19]# vi/etc/httpd/httpd.conf

You'll find something like this in the file.

LoadModule Php5_module        modules/libphp5.so

This means that PHP has been loaded into the Apache server, what we have to do is to tell the Apache server, which suffixes use PHP parsing

Search for "AddType application/x-compress" in the VI editor. Z

Add one at a later: AddType application/x-httpd-php. php

The modified effect is as follows

Save and exit, restart Apache

[Root@gamejzy php-5.3.19]#/usr/local/apache2/bin/apachectl stop[root@gamejzy php-5.3.19]#/usr/local/apache2/bin/ Apachectl start

3. Test whether the Apache server can parse PHP

To add a phpinfo.php file to the/usr/local/apache2/htdocs directory, type the following code:

<?phpheader ("content-type:text/html; Charset=utf-8 ");p hpinfo ();? >

Open the browser, access the file, see as shown, the PHP installation is successful and the integration with Apache server is successful.


To this, CentOS under the LAMP environment is set up, although the steps cumbersome, but "工欲善其事, its prerequisite", spend some time, build a perfect environment is worthwhile.

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.