Detailed CentOS5.5 to build PHP environment (best lamp environment) _linux

Source: Internet
Author: User
Tags soap mcrypt mkdir php software phpinfo web services

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 the Linux is the PHP best environment.

For the software used in this article, please click on this link to download.

CentOS5.5 is now officially no longer available, recommend the use of CENTOS6 above version:

centos6.8 Download Address: http://www.jb51.net/softs/499124.html

centos7.2 Download Address: http://www.jb51.net/softs/499109.html

>>> "Click to download"

The author of this article is experimenting with CentOS 5.5, which is installed by virtual machine (VMware). The following installation detailed

1. Preparation work

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

See whether to install (Apache as an example)

 
 

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

If null occurs after the command has been executed, the Apache software is not installed in the machine, if a scenario such as the following is installed.

If, as shown in the above illustration, you need to uninstall all three of these software.

The uninstall command is as follows:

 
 

Note:--nodeps is forced uninstall

Please ensure that GCC and g++ compilers are installed in your Linux system

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

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

Install GCC:

 
 

Install g++:

 
 

Copy all the software (most of which are tar packets) to the bottom of the/tmp/lamp and unzip

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

When this command is executed, a php-5.2.6 folder is created in the current directory, and all the 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. gz files

Introduction of compiling and installing package

The process of installing each source code package on a Linux system is as follows:
Configuration (Configure)
Compile (make)
Install (make install)

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

All the software here is installed under/usr/local
I. Installation of Libxml

Installation order: 1, enter the Libxml directory, 2, configuration parameters (including installation path, dependent software, installation functions, etc.); 3, compile; 4, install. Note: All package installations are similar

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

/configure for the package configuration parameter command,--prefix indicates the specified installation directory, most directories are not created automatically, individual does not need us to manually create

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

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

Second, install Libmcrypt

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

Iii. installation of Zlib

[Root@gamejzy lamp]# cd zlib-1.2.3/ 
[Root@gamejzy zlib-1.2.3]#./configure 

After/configure, do not follow the--prefix parameter 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 

Build directory Complete!

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

./configure parameter Description:
--enable-shared build a shared library using the GNU Libtool
--enable-static build 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 

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 usr/local/jpeg6/--with-png=/usr/local/libpng/--with-freetype=/usr/local/freetype/ 

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

Note Installing this package may cause the following error, as shown in the following illustration:

If this error occurs, workaround:

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

Find the keyword "png.h" command:/png.h carriage return

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

The effect is shown in the following illustration:

Save exit and continue with make && make install execution to install 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 

The parameter description in the./configure:
--SYSCONFDIR=/ETC/HTTPD Specify the location of the Apache server's configuration file (httpd.conf, etc. files)
--WITH-INCLUDED-APR uses a copy of the bundle Apr/apr-util
--enable-so is compiled with dynamic shared objects (DSO)
--enable-deflate=shared support for narrowing transmission coding
--enable-expires=shared Expiration Head Control
--enable-rewrite=shared URL manipulation based on rules
--enable-static-support to establish a static link version of the support

Test Apache Server

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

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

3, open the Apache server

 
 

Stop (off), restart (reboot)

4, see if the Apache server is started, that is, to see if the 80 port is started

 
 

After the command has been executed, it appears as follows, indicating that it has started
TCP 0 0:: £ º::* LISTEN

5, access in the browser
If you are on this computer, enter the address bar of the browser: http://localhost or http://127.0.0.1

If it's a remote connection, such as an SSH connection, enter the IP address of the Linux in the browser's address bar. For example: http://192.168.1.233

If the page appears in large characters "
It works!
"Indicates that Apache installation was successful.
Test completed!

Add Apache to start automatically on every boot

 
 

X. Installation of MySQL (important)

Before installing MySQL, create a group and user name that specifically manages MySQL

Set up a group called "MySQL"

 
 

Set up a user named "MySQL", so that he belongs to the "MySQL" group

 
 
[Root@gamejzy lamp]# cd mysql-5.0.41/ 
[Root@gamejzy mysql-5.0.41]#./configure--prefix=/usr/local/mysql-- With-extra-charsets=all 

./configure parameter Description:
--with-extra-charsets=all install MySQL all the character sets
Note that if the following error occurs in the./configure

Reason: Missing ncurses installation package.

Workaround: Download and install the appropriate package

Yum list|grep ncurses 
yum-y Install Ncurses-devel 

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

MySQL installed after the completion of a number of content, these content is very cumbersome, but very critical, I hope you learn patience.

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

 
 

2, initialization of the database files, installed after MySQL, and will not appear MySQL data files and data storage location

First switch to MySQL's installation directory

 
 

Initializes the database file using the mysql_install_db in the Bin directory and uses the MySQL user built above

 
 

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

3, set the MySQL installation directory permissions

Change the owner of all files and directories under the directory as root

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

Change the owner of the Var directory to be a MySQL user

 
 

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

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

4. Start MySQL

 
 

& means start in background
At this point, using NETSTAT-TNL, if you see Port 3306, then start successfully
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

 
 

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

First login into MySQL, use SQL command to delete the host is not "localhost" username (MySQL users are in the MySQL library of the user table), leaving only allow the local login account.

 
 

Refresh Authorization Table

 
 

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

 
 

Note: The password must be set to remember, or you can not go into the MySQL database.

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

The command to log in to MySQL database at this time cannot be bin/mysql so simple, should be as follows:

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

-H Specify Host name
-U user Name
-p password

6. Shut down MySQL database server

 
 

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

Enter a password and return to close the database.

To start the command, see this section 4

7. Join to boot by default

 
 

Xi. Installation of PHP (important)

Here we install a high version of PHP php-5.3.19, installation parameters are more, please be sure to pay attention.

[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 \ 

./configure parameter Description:
--WITH-CONFIG-FILE-PATH=/USR/LOCAL/PHP/ETC specifies the path to which the PHP5 configuration file is stored
--with-apxs2=/usr/local/apache2/bin/apxs told PHP to find out where Apache 2
--with-mysql=/usr/local/mysql/Specifies the MySQL installation directory
--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/tells 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/tells PHP where to put 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 feature
--enable-soap variable activates SOAP and Web services support
--enable-mbstring=all enables multibyte string support
--enable-sockets variable activates socket communication characteristics

Problems that may occur with compilation:

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.

 
 

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

After the compilation is complete, the following configuration is required

1, set php.ini configuration file

 
 

Note:/USR/LOCAL/PHP/ETC is the location specified at the time of configuration
2, and Apache integration

Open the Apache configuration file First httpd.conf

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

You'll find that there's something in the file.

LoadModule Php5_module  

This means that PHP has been loaded into the Apache server, all we have to do is tell the Apache server which suffix names use PHP to parse

In the VI editor, search for "AddType application/x-compress. Z

Add one later: AddType application/x-httpd-php. php
The modified effect is shown below

Save and exit, restart Apache

[Root@gamejzy php-5.3.19]#/usr/local/apache2/bin/apachectl Stop 

3, test the Apache server can parse PHP

Add a phpinfo.php file to the/usr/local/apache2/htdocs directory and type the following code:

<?php 
Header ("content-type:text/html; Charset=utf-8 "); 
Phpinfo (); 

Open the browser, access the file, see the following figure shows that the PHP installation was successful, and the Apache server consolidation success.

To this end, CentOS under the LAMP environment has been built, although the steps are cumbersome, but "工欲善其事, its prerequisite", spend some time to 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.