Compile and install apache + php + mysql in CentOS

Source: Internet
Author: User
Tags curl ini mysql download mysql in openssl centos openldap zend

LAMP installation is often done by developers, and RPM installation is relatively easier. The installed rpm Package and dependent package can be found on the installation disc, of course, you can also download and install it online, such as in mirrors.sohu.com mirrors.163.com. In centos, yum is supported. Therefore, yum can be used to install yum. It is easy to install and install the dependency package automatically. Here we mainly introduce how to compile and install yum.

1. Obtain relevant open-source programs

[Applicable to CentOS Operating System] use the yum command provided by CentOS Linux to install and upgrade the required libraries (RedHat and other Linux distributions can find the RPM packages of these libraries from the installation CD, installation ):

The code is as follows: Copy code

Sudo-s
LANG = C
Yum-y install gcc-c ++ autoconf libjpeg-devel libpng-devel freetype-devel libxml2 libxml2-devel zlib-devel glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses- devel curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn-devel openssl-devel openldap-devel nss_ldap openldap-clients openldap-servers

II. Download and install apache

1. Check whether httpd has been installed.

The code is as follows: Copy code

Rpm-qa | grep httpd

Httpd-2.2.3-31.el5.centos.4

Httpd-manual-2.2.3-31.el5.centos.4

To uninstall the old installation package, run the following command:

Rpm-e httpd-2.2.3-43.el5.centos -- nodeps note: If you enter the rpm-e httpd-2.2.3-31.el5.centos.4 command, the system will prompt that you have a dependency and cannot uninstall. Therefore, add-nodeps to disable dependency checking and force delete. In this case, only httpd is deleted. Other software with dependency will not be deleted, however, these software cannot run because there is no httpd in the system. This is called "not deleted.

Yum-y remove httpd is used to delete all software dependent on httpd. Such as php and mod_ssl. This is clean. Haha.

2. Installation of related software packages

Package to be downloaded:
Apr: http://apr.apache.org/download.cgi
Apr-util: http://apr.apache.org/download.cgi
Pcre: http://pcre.org/http://sourceforge.net/projects/pcre/
---
If not installed, the following message is displayed:

./Configure -- prefix =/usr/local/apache2 -- with-ssl -- enable-so -- enable-rewrite
Checking for chosen layout... Apache
Checking for working mkdir-p... yes
Checking build system type... i686-pc-linux-gnu
Checking host system type... i686-pc-linux-gnu
Checking target system type... i686-pc-linux-gnu

Refreshing Apache Portable Runtime library...

Checking for APR... no
Configure: error: APR not found. Please read the documentation. If you are prompted that apr is missing, you need to download apr. After compiling and installing apr, continue to compile apache
Install apr:

Tar zxvf apr-1.4.2.tar.gz
Cd apr-1.4.2
./Configure -- prefix =/usr/local/apr
Make
Make install generally requires the installation of apr-util and pcre

Tar zxvf apr-util-1.3.10.tar.gz
Cd apr-util-1.3.10
./Configure -- prefix =/usr/local/apr-util -- with-apr =/usr/local/apr
Make
Make install

Tar zxvf pcre-8.11.tar.gz
Cd pcre-8.11
./Configure -- prefix =/usr/local/pcre
Make
Download the make install3 and httpd software packages

Address: http://www.apache.org/dyn/closer.cgi

Download Address: http://labs.renren.com/apache-mirror//httpd/

Wget http://labs.renren.com/apache-mirror//httpd/httpd-2.3.16-beta.tar.gz

(Latest version)

4. Installation

The code is as follows: Copy code
Tar zxvf httpd-2.3.16.tar.gz
Cd httpd-2.3.16
./Configure -- prefix =/usr/local/apache2 -- with-ssl -- enable-so -- enable-dav-fs -- enable-dav-lock
-- Enable-rewrite -- with-apr =/usr/local/apr -- with-apr-util =/usr/local/apr-util -- with-pcre =/usr/local/ pcre
Make

Make install note:

1. To enable all modules available: -- enable-MoD-shared = all
2. Be sure to add -- enable-so is the core capable of loading DSO
3. -- enable-dav installs mod_dav_svn.so and mod_authz_svn.so modules.

 

5. Set apache to boot automatically (two methods)

①,

Add a line to the/etc/rc. d/rc. local file.

The code is as follows: Copy code

/Url/local/apache2/bin/apachectl start

②,
Install apache as a system service

The code is as follows: Copy code

Cp/usr/local/apache2/bin/apachectl/etc/rc. d/init. d/httpd

Vi/etc/rc. d/init. d/httpd

Add (#! /Bin/sh)

The code is as follows: Copy code

Chkconfig: 2345 10 90

Description: Activates/Deactivates Apache Web Server
Finally, run chkconfig to add apache to the startup service group of the system:

Chkconfig -- add httpd
Chkconfig httpd on 3. mysql download and installation

1. Download

Address: http://mirrors.sohu.com/mysql

Wget http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.60.tar.gz

2. Installation

The code is as follows: Copy code

Tar zxvf mysql-5.1.60.tar.gz

Cd mysql-5.1.60

./Configure -- prefix =/usr/local/mysql -- with-comment = Source -- with-server-suffix =-enterprise-gpl
-- With-mysqld-user = mysql -- with-debug -- with-big-tables -- with-charset = utf8
-- With-collation = utf8_general_ci -- with-extra-charsets = all
-- With-pthread -- enable-static -- enable-thread-safe-client -- with-client-ldflags =-all-static
-- With-mysqld-ldflags =-all-static -- enable-validator -- without-ndb-debug
-- Enable-local-infile -- with-readlinegroupadd mysql
Useradd-g mysql
Cd/usr/local/mysql
Chown-R msyql. (. Represents root)
Chgrp-R mysql.
Bin/mysql_install_db -- user = mysql
Chown-R root.
Chown-R mysql var
Cp share/mysql/my-medium.cnf/etc/my. cnf
Cp share/mysql. server/etc/rc. d/init. d/mysqld
Chmod 755/etc/rc. d/init. d/mysqld
Chkconfig -- add mysqld
Chkconfig -- level 3 mysqld on
/Etc/rc. d/init. d/mysqld start (because the mysql service has been added to the system service, you can also use service mysqld start) to initialize the root user password:

Bin/mysqladmin-uroot password 123456

OK. mysql is successfully installed.

 

4. Download and install PHP5

1. Download:

Wget requests

The code is as follows: Copy code

Tar zxvf php-5.3.3.tar.gz
Cd php-5.3.3
. /Configure -- prefix =/usr/local/php -- with-apxs2 =/usr/local/apache2/bin/apxs -- with-zlib -- with-bz2 -- with-gd -- enable-gd-native -ttf -- enable-gd-jis-conv -- enable-mbstring -- with-mysql =/usr/local/mysql -- with-iconv -- with-curl -- enable-static -- enable- zend-multibyte -- enable-inline-optimization -- enable-zend-multibyte -- enable-sockets -- enable-soap -- with-openssl -- with-gettext -- enable-ftp

Make
Make install
Cp/usr/local/src/php-5.3.3/php. ini-recommended/usr/local/php/lib/php. ini

3. Integrate apache and php

Search: AddType application adds the following content below it:

The code is as follows: Copy code

AddType application/x-httpd-php. php
AddType application/x-httpd-php-source. phps

4. Restart apache

The code is as follows: Copy code

/Usr/local/apache2/bin/apachetcl restart

If an error is reported:

Httpd: Syntax error on line 162 of/usr/local/apache2/conf/httpd. conf: Cannot load/usr/local/apache2/modules/libphp5.so into server:/usr/local/apache2/modules/libphp5.so: cannot restore segment prot after reloc: Permission denied solution:

Google's basic problem is caused by the SELinux protection mode. The following figure shows a buddy's blog:

① Method to disable SELINUX:
Vi/etc/selinux/config change SELINUX = enforcing to SELINUX = disabled and restart
② Do not disable SELINUX:
Shell> setenforce 0
Shell> chcon-c-v-R-u system_u-r object_r-t textrel_shlib_t shell>/usr/local/apache2/modules/libphp5.so
Shell>/usr/local/apache2/bin/apachectl restart
Shell> setenforce 1. After the experiment, apapche is started normally, and php is displayed normally.
5. Test
Vim test. php
Input:
<? Php echo phpinfo ();?>
OK. Now the setup of the AMP environment is complete. It's not too early. Wash and sleep!

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.