Manually build a lamp server

Source: Internet
Author: User
Tags configuration php install openssl mcrypt openssl version zts

I use the environment is Centos6.6 x86-64 Mini version of the system, the minimum version of the installation of a lot of software is not available, we can install through the Yum Software Library, to the current lamp server "L" (Linux) we are ready, So next we need to download Apache httpd software, is httpd.apache.org, now Apache maintenance httpd has 2.0,, 2.2, 2.4 several branch versions, each version of the function of the official website written very clearly, I do not repeat here, I chose the latest version of HTTPd 2.4.10, the following we do httpd compilation process to explain;

Because httpd can run on a variety of operating systems and hardware architectures, httpd runs on the APR (Apache Portable runtime) virtual machine, developing APR for different platforms and operating systems. All first we should install APR before we follow httpd, we do not use the software package comes with APR, as if the version is a little low, httpd2.4.10 need the APR version of the minimum is 1.4, we go to the official website to download the latest version of Apr and Apr-util, is apr.apache.org;

# wget HTTP://APACHE.FAYEA.COM//HTTPD/HTTPD-2.4.10.TAR.BZ2

# wget HTTP://MIRRORS.CNNIC.CN/APACHE//APR/APR-1.5.1.TAR.BZ2

# wget HTTP://MIRRORS.CNNIC.CN/APACHE//APR/APR-UTIL-1.5.4.TAR.BZ2

# TAR-XF HTTPD-2.4.10.TAR.BZ2

# TAR-XF APR-1.5.1.TAR.BZ2

# TAR-XF APR-UTIL-1.5.4.TAR.BZ2


Install the Development library

# yum Install Gcc-y

To compile the software

# CD apr-1.5.1

#./configure--PREFIX=/USR/LOCAL/APR

# make

# make Install


# CD apr-util-1.5.4

#./configure--prefix=/usr/local/apr-util--WITH-APR=/USR/LOCAL/APR

# make

# make Install


Because httpd needs to rewrite the functionality, all the Pcre libraries need to be installed

# yum Install-y pcre-devel

However I appeared in the compile time checking for OpenSSL version >= 0.9.8a ... FAILED

It is because our mini version does not have the OpenSSL development library installed, all the development libraries must be installed first

# yum Install Openssl-devel.x86_64-y


# CD httpd-2.4.10

#./configure--prefix=/usr/local/apache--sysconfdir=/etc/httpd--enable-so--enable-rewirte--enable-ssl-- enable-cgi--enable-cgid--enable-modules=most--enable-mods-shared=most--enable-mpms-shared=all--with-apr=/usr/ LOCAL/APR--with-apr-util=/usr/local/apr-util

# make

# make Install


Turn off SELinux

# Setenforce 0


Add the httpd binary execution file to the environment variable

# vim/etc/profile.d/httpd.sh

Add the following export path= $PATH:/usr/local/apache/bin


Add the httpd man file to the system, first install the man tool

# yum Install Man-y

# Vim/etc/man.config

Add the following content Manpath/usr/local/apache/man

Add a SYSV-style footstep to httpd below the/etc/init.d/directory, and the httpd installation is complete;


MySQL installation can be RPM installation, you can use the common binary package installation, you can also use the source code compiled installation, because the source code compiled too time-consuming, we use the Universal Binary format package installation, the software package can be downloaded to the MySQL website, The version we are using now is mysql-5.5.20-linux2.6-x86_64.tar.gz

# Tar XF mysql-5.5.20-linux2.6-x86_64.tar.gz-c/usr/local

# cd/usr/local

# ln-s mysql-5.5.20-linux2.6-x86_64 MySQL

# groupadd-r MySQL

# useradd-g Mysql-r-s/sbin/nologin MySQL

# CD MySQL

# chown-r Mysql:mysql *

Create a logical volume for MySQL data storage location

# PVCREATE/DEV/SDA5

# vgcreate Myvg/dev/sda5

# lvcreate-n Mysql-l 5G MYVG

# Mkfs.ext4/dev/myvg/mysql

# Vim/etc/fstab

# Mkdir/data

Add/dev/myvg/mysql/data ext4 Defaults 0 0

# mount-a

# Mkdir/data/mysql

# chown Mysql.mysql/data/mysql

# chmod O-x/data/mysql

# Cd/usr/local/mysql

#./scripts/mysql_install_db--user=mysql--datadir=/data/mysql/

# chown-r Root *


Adding binary environment variables

# vim/etc/profile.d/mysql.sh

Add the following export path= $PATH:/usr/local/mysql/bin


Add a Help file

# Vim/etc/man.config

Add the following content Manpath/usr/local/mysql/man


Add the MySQL library file to the system library file directory search

# vim/etc/ld.so.conf.d/mysql.conf

Add the following content/usr/local/mysql/lib


Add header File

# ln-s/usr/local/mysql/include/usr/include/mysql


To add a startup script

# CP Support-files/mysql.server/etc/init.d/mysqld

# chkconfig--add mysqld


Add a configuration file

# CP SUPPORT-FILES/MY-LARGE.CNF/ETC/MY.CNF

Add datadir =/data/mysql in config file

You can now start the MySQL service;


You can add a password to MySQL

# mysqladmin-uroot password ' 123456 '


Below we make the last PHP compilation installation, the PHP version we selected is 5.4.36

Download PHP Source Package

# wget HTTP://CN2.PHP.NET/DISTRIBUTIONS/PHP-5.4.36.TAR.BZ2

If you want the compiled PHP to support the mcrypt extension, here are the following two RPM packages to install:

libmcrypt-2.5.8-9.el6.rpm

libmcrypt-devel-2.5.8-9.el6.rpm

Since both packages have their own software library, all of our updates add Yum source

RPM-IVH http://download4.fedora.redhat.com/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

# yum Install-y libmcrypt Libmcrypt-devel


Description

These do not come with the package we can also go to the site to inquire, such as: Http://rpmfind.net, in which we can query to support a variety of hardware platform RPM package.


# CD php-5.4.36


Start the compilation below

#./configure--prefix=/usr/local/php--with-mysql=/usr/local/mysql--with-openssl--with-mysqli=/usr/local/mysql/ Bin/mysql_config--enable-mbstring--with-freetype-dir--with-jpeg-dir--with-png-dir--with-zlib--with-libxml-dir= /usr--enable-xml--enable-sockets--with-apxs2=/usr/local/apache/bin/apxs--with-mcrypt--with-config-file-path=/ etc--WITH-CONFIG-FILE-SCAN-DIR=/ETC/PHP.D--with-bz2--enable-maintainer-zts


Description

1. In order to support the two mpm of the Apache worker or event, the--ENABLE-MAINTAINER-ZTS option is used at compile time.

2 、--With-apxs2=/usr/local/apache/bin/apxs here is to let PHP run in httpd module mode, if you use fastcgi mode, you need to change--enable-fpm

3, if you use PHP5.3 or above, in order to link the MySQL database, you can specify MYSQLND, so you do not need to install the MySQL or MySQL development package. MYSQLND is available from PHP 5.3 and can be bound to it at compile time (instead of relying on the specific MySQL client library bindings), but it is the default setting starting with PHP 5.4.

#./configure--with-mysql=mysqlnd--with-pdo-mysql=mysqlnd--with-mysqli=mysqlnd


Attention:

I have an error configure:error:xml2-config not found in the compilation. Please check your LIBXML2 installation.

Here we should first submit the installation LIBXML2, and then compile;

# yum Install libxml2 libxml2-devel-y


Then there are errors, the reason for so many errors is because we installed Linux is the mini version, a lot of software is not pre-installed, we do not know what software exists before installation, which software does not exist, can only appear a problem solved a ask you

Error: Configure:error:Please Reinstall the BZIP2 distribution

# yum Install Bzip2-devel.x86_64-y


Everything goes well behind, directly to the end of the compilation configuration,

# make

# make Install


Provide a good configuration file for PHP, under the PHP source file directory

# CP Php.ini-production/etc/php.ini


Edit Apache config file httpd.conf to Apache support PHP

# vim/etc/httpd/httpd.conf

1, add the following two lines

AddType application/x-httpd-php. php

AddType Application/x-httpd-php-source. Phps


2. Locate to DirectoryIndex index.html

Modified to:

DirectoryIndex index.php index.html


Then restart httpd, or let it reload the configuration file to test if PHP is already working.


Specific Apache configuration we are not stating here, you can change the path of the central host, configure the virtual host, load the required modules, and so on;


So far the lamp environment is set up, let's test to see if our PHP can connect to the database, and fill in the index.php with the following content:

<?php

$conn =mysql_connect (' localhost ', ' root ', ' 123456 ');

if ($conn)

echo "Success ...";

Else

echo "Failure ...";

Phpinfo ();

?>

When the database is open display success ...., the database is closed when the display failure ....


Below we install XCache for PHP


XCache is an open source PHP opcode cache/optimizer, which means that he can improve PHP performance on your server. By buffering the compiled PHP data to shared memory to avoid a repetitive compilation process, he is able to use the buffer-compiled code directly to speed up. You can typically increase your page generation rate by 2 to 5 times times, reducing server load.


We download the latest version of XCache

# wget http://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz

# Tar XF xcache-3.2.0.tar.gz

# CD xcache-3.2.0

#/usr/local/php/bin/phpize

Then there was an error:

Cannot find autoconf. Please check your autoconf installation and the

$PHP _autoconf environment variable. Then, rerun the this script.


The reason is because I still have packages that are not installed


[email protected] xcache-3.2.0]# Yum install autoconf-y


[Email protected] xcache-3.2.0]#/configure--enable-xcache--with-php-config=/usr/local/php/bin/php-config


[[email protected] xcache-3.2.0]# make


[[email protected] xcache-3.2.0]# make install


Providing configuration files for XCache

[Email protected] xcache-3.2.0]# MKDIR/ETC/PHP.D

[email protected] xcache-3.2.0]# CP xcache.ini/etc/php.d/


So far XCache installation complete



The second part, configuration apache-2.4.10 and FPM mode php-5.4.36


First, the installation of Apache and MySQL is the same as the previous part; Please install it according to it;


Second, compile and install php-5.4.36


1, to resolve the dependency relationship:


If you want the compiled PHP to support the mcrypt extension, you will need to download the following two RPM packages and install them here:

libmcrypt-2.5.7-5.el5.i386.rpm

libmcrypt-devel-2.5.7-5.el5.i386.rpm

mhash-0.9.9-1.el5.centos.i386.rpm

mhash-devel-0.9.9-1.el5.centos.i386.rpm


2. Compile and install php-5.4.36


First download the source package to the local directory,


# Tar XF php-5.4.36.tar.bz2

# CD php-5.4.36

#./configure--prefix=/usr/local/php--with-mysql=/usr/local/mysql--with-openssl--with-mysqli=/usr/local/mysql/ Bin/mysql_config--enable-mbstring--with-freetype-dir--with-jpeg-dir--with-png-dir--with-zlib--with-libxml-dir= /usr--enable-xml--enable-sockets--enable-fpm--with-mcrypt--with-config-file-path=/etc-- WITH-CONFIG-FILE-SCAN-DIR=/ETC/PHP.D--with-bz2


# make

# Make Intall


To provide a configuration file for PHP:

# CP Php.ini-production/etc/php.ini


3, Configuration php-fpm

Provide the SYSV init script for php-fpm and add it to the list of services:

# CP SAPI/FPM/INIT.D.PHP-FPM/ETC/RC.D/INIT.D/PHP-FPM

# chmod +X/ETC/RC.D/INIT.D/PHP-FPM

# chkconfig--add php-fpm

# Chkconfig PHP-FPM on


To provide a configuration file for php-fpm:

# cp/usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/php-fpm.conf


To edit a php-fpm configuration file:

# vim/usr/local/php/etc/php-fpm.conf

Configure the relevant options for FPM to the value you need and enable the PID file (the last line below):

Pm.max_children = 50

Pm.start_servers = 5

Pm.min_spare_servers = 2

Pm.max_spare_servers = 8

PID =/usr/local/php/var/run/php-fpm.pid


The next step is to start php-fpm:

# service PHP-FPM Start


Use the following command to verify if the command output has several PHP-FPM processes that indicate that the boot was successful:

# PS aux | grep php-fpm


By default, FPM listens on port 9000 of 127.0.0.1, and can also use the following command to verify that it is already listening on the appropriate socket.

# NETSTAT-TNLP | grep php-fpm

TCP 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 689/php-fpm


Third, configuration httpd-2.4.10


1. Enable the relevant modules of httpd


After Apache HTTPD 2.4 has a module specifically for the implementation of the FASTCGI, this module is mod_proxy_fcgi.so, it is actually as an extension of the mod_proxy.so module, so the two modules are loaded

LoadModule Proxy_module modules/mod_proxy.so

LoadModule Proxy_fcgi_module modules/mod_proxy_fcgi.so



2. Configure the virtual host to support the use of fcgi


Add two lines similar to the following in the corresponding virtual host.

Proxyrequests OFF

Proxypassmatch ^/(. *\.php) $ fcgi://127.0.0.1:9000/path/to/document_root/$1


For example:

<virtualhost *:80>

DocumentRoot "/www/html"

ServerName hebrxz.com

Serveralias www.hebrxz.com


Proxyrequests OFF

Proxypassmatch ^/(. *\.php) $ fcgi://127.0.0.1:9000/www/html/$1


<directory "/www/html" >

Options None

allowoverride None

Require all granted

</Directory>

</VirtualHost>


Proxyrequests off: Turn off the forward proxy

Proxypassmatch: Send a file request ending in. php to the PHP-FPM process, php-fpm need to know at least the directory and URI that is running, so this is where the two parameters are indicated directly after the fcgi://127.0.0.1:9000. The delivery of other parameters has been encapsulated by mod_proxy_fcgi.so and does not need to be specified manually.


3, edit Apache configuration file httpd.conf, let Apache can recognize PHP format page, and support the PHP format of the home page

# vim/etc/httpd/httpd.conf

1, add the following two lines

AddType application/x-httpd-php. php

AddType Application/x-httpd-php-source. Phps


2. Locate to DirectoryIndex index.html

Modified to:

DirectoryIndex index.php index.html


Add: Apache httpd 2.4 Previous versions, either run PHP as an Apache module or add a third-party module to support the PHP-FPM implementation.

This article is from the "Water Drop Blog" blog, please be sure to keep this source http://wangzan18.blog.51cto.com/8021085/1605480

Manually build a lamp server

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.