Centos + apache + mysql + php LAMP source code compilation and Installation

Source: Internet
Author: User

WEB Server linux + apache + mysql + php LAMP source code environment setup

Linux + Apache + Mysql + Perl/PHP/Python is a group of open-source software commonly used to build dynamic websites or servers. They are independent programs, but they are often used together, having higher and higher compatibility

A powerful web application platform. In terms of website traffic, more than 70% of the access traffic is provided by LAMP, which is the most powerful website solution.

The following describes how to build the LAMP environment.

Preparation tools:

Apr-1.4.6.tar.gz apr-util-1.5.1.tar.gz

Httpd-2.4.4.tar.bz2

Mysql-5.6.10.tar.gz cmake-2.8.10.2.tar.gz

Php-5.4.3.tar.gz

I. Prepare the environment:

I am using Red Hat Enterprise Linux 5.4 eth0 192.168.126.129

[Root @ lly ~] # Mount/dev/cdrom/mnt/cdrom

Use yum to detect the development environment

[Root @ lly ~] # Vim/etc/yum. repos. d/rhel-debuginfo.repo edit yum Client

[Root @ lly ~] # Yum grouplist check the development environment

Note: These development environments are required here. I already have these environments. If you do not have these development environments, you can use yum groupinstall "Development Environment name,

Note: When installing the software package group in yum, you must add ""

Ii. Installation

Install mysql php in sequence

1. install apache

In fact, I have introduced the installation of apache in my previous blog.

[Root @ lly ~] # Tar-zxvf apr-1.4.6.tar.gz-C/usr/local/src/

[Root @ lly ~] # Tar-zxvf apr-util-1.5.1.tar.gz-C/usr/local/src/

[Root @ lly src] # cd/usr/local/src/apr-1.4.6/

[Root @ lly apr-1.4.6] #./configure -- prefix =/usr/local/apr install apr to the/usr/local/apr directory

[Root @ lly apr-1.4.6] # make

[Root @ Lili apr-1.4.6] # make install

[Root @ lly apr-1.4.6] # cd ..

[Root @ lly src] # cd apr-util-1.5.1/

[Root @ lly apr-util-1.5.1] #./configure -- with-apr =/usr/local/apr/bin/apr-1-config

[Root @ lly apr-util-1.5.1] # make

[Root @ lly apr-util-1.5.1] # cd

[Root @ lly ~] # Tar-jxvf httpd-2.4.4.tar.bz2-C/usr/local/src/

[Root @ lly ~] # Cd/usr/local/src/httpd-2.4.4/

[Root @ lly httpd-2.4.4] #. /configure -- prefix =/usr/local/apache -- sysconfdir =/etc/httpd -- enable-so -- enable-ssl -- enable-rewrite -- with-apr =/usr/local/ apr/bin/apr-1-config -- with-apr-util =/usr/local/apr/bin/apu-1-config -- with-pcre-with-z -- enable-mpms-shared = all

[Root @ lly httpd-2.4.4] # make

[Root @ Lili httpd-2.4.4] # make install

[Root @ lly httpd-2.4.4] #/usr/local/apache/man

[Root @ lly man] # vim/etc/man. config

Add the man manual of apache to the man path to view the man manual of apache.

To prevent the system from finding the path when calling the apache header file include, you can establish a connection.

[Root @ lly apache] # ln-s/usr/local/apache/include // usr/include/apache

To better manage httpd, edit a STARTUP script for it.

[Root @ lly ~] # Cd/etc/init. d/

[Root @ lly init. d] # vim httpd

The script is as follows:

#! /Bin/sh

# Set-x

HTTPD = '/usr/local/apache/bin/httpd'

CONFFILE = '/etc/httpd. conf'

# Description: http server

# Chkconfig: 2345 88 60

Start (){

[-F/var/lock/subsys/httpd] & echo "apache is started" & exit

Echo-n "starting apache ......"

Sleep 1

}

Stop (){

[! -F/var/lock/subsys/httpd] & echo "httpd is stoped..." & exit

Echo-n "stoping httpd ........"

Sleep 1

/Bin/rm-rf/var/lock/subsys/httpd

$ HTTPD-k stop & RETVAL = 0 | RETVAL = 1

}

Case $1 in

Stop (){

[! -F/var/lock/subsys/httpd] & echo "httpd is stoped..." & exit

Echo-n "stoping httpd ........"

Sleep 1

/Bin/rm-rf/var/lock/subsys/httpd

$ HTTPD-k stop & RETVAL = 0 | RETVAL = 1

[$ RETVAL-eq 0] & rm-rf/var/lock/subsys/httpd & echo "OK" | echo "fail"

}

Case $1 in

Start)

Start

;;

Stop)

Stop

;;

Restart)

Stop

Start

;;

*)

Echo "start | stop | restart"

;;

Esac

[Root @ lly init. d] # chmod a + x/etc/init. d/httpd

[Root @ lly init. d] # service httpd start

[Root @ lly init. d] # netstat-tupln | grep http

Tcp 0 0: 80 :::*

[Root @ lly init. d] # chkconfig -- add httpd add auto-start

[Root @ lly init. d] # chkconfig -- list | grep http

Httpd 0: off 1: off 2: on 3: on 4: on 5: on 6: off

2. Install mysql cmake

[Root @ lly ~] # Tar zxvf mysql-5.6.10.tar.gz-C/usr/local/src/

[Root @ lly ~] # Cd/usr/local/src/mysql-5.6.10/

[Root @ Lili mysql-5.6.10] # less INSTALL-SOURCE

Mysql instructions

The cmake tool is required for mysql installation.

Install cmake

[Root @ lly ~] # Tar-zxvf cmake-2.8.10.2.tar.gz-C/usr/local/src/

[Root @ lly ~] # Cd/usr/local/src/cmake-2.8.10.2/

[Root @ lly cmake-2.8.10.2] #./configure -- prefix =/usr/local/cmake

[Root @ lly cmake-2.8.10.2] # make & make install

Waiting .......................

[Root @ lly cmake-2.8.10.2] # cd/usr/local/cmake/

To quickly access the bin under cmake in the future, add the bin under cmke to the path

[Root @ lly cmake] # vim/etc/profile

Note: the path will be successfully added only after the next entry.

[Root @ lly ~] # Cd/usr/local/src/mysql-5.6.10/

86: 36

[Root @ lly mysql-5.6.10] # cmake.

[Root @ lly mysql-5.6.10] # make & make install

Please waiting for a long time ..........................

[Root @ lly ~] # Cd/usr/local/src/mysql-5.6.10/

[Root @ Lili mysql-5.6.10] # less INSTALL-SOURCE

Steps for configuring Mysql installation instructions

[Root @ lly mysql-5.6.10] # cd/usr/local/mysql/

Create account information

[Root @ lly mysql] # groupadd mysql

[Root @ lly mysql] # useradd-r-g mysql

[Root @ lly mysql] # chown-R mysql.

Initialize

[Root @ lly mysql] # scripts/mysql_install_db -- user = mysql

[Root @ lly mysql] # chown-R root.

[Root @ lly mysql] # chown-R mysql data

[Root @ lly mysql] # cd support-files/

[Root @ lly support-files] # cp my-default.cnf/etc/my. cnf

[Root @ lly support-files] # cp mysql. server/etc/init. d/mysqld

[Root @ lly support-files] # chmod a + x/etc/init. d/mysqld

[Root @ lly support-files] # service mysqld start

Starting MySQL... [OK]

Mysqld service started successfully

[Root @ lly support-files] # netstat-tupln | grep mysqld

Tcp 0 0: 3306 :::*

[Root @ lly support-files] # cd ..

[Root @ lly mysql] # pwd

/Usr/local/mysql

[Root @ lly mysql] # vim/etc/profile

Log on again

[Root @ lly ~] # Mysql

Mysql> show databases;

+ -------------------- +

| Database |

+ -------------------- +

| Information_schema |

| Mysql |

| Performance_schema |

| Test |

+ -------------------- +

4 rows in set (0.00 sec)

[Root @ lly ~] # Mysqladmin-u root-p password '000000' set an administrator account password 123

[Root @ lly ~] # Mysql-u root-p can log on to this account later

The/usr/local/mysql/lib library file generated by mysql is not recognized by the system in the standard path (/lib or/usr/lib is the standard path). Therefore, the following configuration is required:

[Root @ lly mysql] # vim/etc/ld. so. conf. d/mysql. conf

Write

/Usr/local/mysql/lib

Refresh ld. so. cache

[Root @ lly mysql] # ll/etc/ld. so. cache

-Rw-r -- 1 root 81871 Apr 13/etc/ld. so. cache

[Root @ lly mysql] # ldconfig

[Root @ lly mysql] # ll/etc/ld. so. cache

-Rw-r -- 1 root 82128 Apr 13/etc/ld. so. cache

Make a connection to the mysql header file include

[Root @ lly mysql] # ln-s/usr/local/mysql/include // usr/include/mysql

3. install php

[Root @ lly ~] # Tar-zxvf php-5.4.3.tar.gz-C/usr/local/src/

[Root @ lly ~] # Cd/usr/local/src/php-5.4.3/

[Root @ lly php-5.4.3] #. /configure -- prefix =/usr/local/php -- sysconfdir =/etc -- with-apxs2 =/usr/local/apache/bin/apxs -- with-zlib -- with-gd --- jpeg-dir -- with-png-dir -- enable-mbstring -- with-mysql =/usr/local/mysql -- with-mysqli =/usr/local/mysql/bin/mysql_config -- enable-xml -- with-freetype-dir

[Root @ lly php-5.4.3] # make & make install

[Root @ lly php-5.4.3] # cd/usr/local/php/

[Root @ lly php] # vim/etc/profile

[Root @ lly php] # vim/etc/ld. so. conf. d/php. conf

Write

/Usr/local/mysql/lib

[Root @ lly php] # ldconfig

[Root @ lly php] # ln-s include/usr/include/php

[Root @ lly php] # vim/etc/httpd. conf

The modules/libphp5.so module is automatically added to the apache configuration file.

[Root @ lly ~] # Service httpd restart apache

Note: The following error may be caused by a SELinux protection mode in Linux.

Starting apache ...... httpd: Syntax error on line 147 of/etc/httpd. conf: Cannot load modules/libphp5.so into server:/usr/local/apache/modules/libphp5.so: cannot restore segment prot after reloc: Permission denied

Fail

You can perform the following operations:

1. Method for disabling SELINUX:
Vi/etc/selinux/config change SELINUX = enforcing to SELINUX = disabled

Restart required
This method may cause risks to the server.

2. Do not disable SELINUX:
# Setenforce 0
# Chcon-c-v-R-u system_u-r object_r-t textrel_shlib_t/usr/local/apache/modules/libphp5.so
# Service httpd restart
# Setenforce 1

[Root @ lly ~] # Cd/usr/local/apache/htdocs default site directory of apache

Iii. Test

1. Test apache

Enter http: // 192.168.126.129 in the browser

2. Test php

[Root @ lly htdocs] # change apache test page to php in mv index.html index. php

[Root @ lly htdocs] # vim index. php

Refresh the following page in the browser:

So far, apache and php are perfectly combined...

3. Test whether php and mysql can be combined successfully.

[Root @ lly htdocs] # vim index. php

Refresh the browser

[Root @ lly htdocs] # service mysqld stop the mysqld service is also displayed as normal

Here, apache, mysql, and php have been perfectly integrated. The web environment architecture of linux + apache + mysql + php has been formed.


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.