LAMP full function Compile installation CentOS6.3 Learn notes

Source: Internet
Author: User
Tags apache php install php openssl pack php error php error log iptables web hosting

Recently took time to test on the virtual machine. The latest version of the lamp of the consolidation of the installation, is to consolidate the previous blog, the following content in the CENTOS6.3 (Install minimal desktop and the default development package) under the test installation success, and do the corresponding optimization configuration, if omitted, Also please leave a message to advise.

Linux operating system: centOS6.3 64bit (Installation of the system default development package)

apache:httpd-2.4.4

mysql:mysql-5.6.10

php:php-5.4.13

Note: When installing the centos6.3 system, in the System Setup Wizard . hook up the default development package to avoid late-compilation errors

I. Installing the development pack (using the default CentOS update source):

# yum-y Install wget gcc-c++ ncurses ncurses-devel cmake make Perl bison OpenSSL openssl-devel gcc* libxml2 Curl-devel libjpeg* libpng* freetype*

Two. Close Iptables and SELinux

# Service Iptables Stop

# Setenforce 0

# Vi/etc/sysconfig/selinux

---------------

Selinux=disabled

---------------

Three. Install MySQL database

1. Download Compilation Package:

# wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.13.tar.gz/from/http://cdn.mysql.com/

2. Pre-installation Initial configuration work:

# useradd-d/usr/local/mysql/mysql #创建一个Mysql用户, specify the home directory to the/use/local directory.

# Mkdir/usr/local/mysql/data

# Mkdir/usr/local/mysql/log #新建mysql下data和log子目录

# Chown-r mysql:mysql/usr/local/mysql/data/

# Chown-r mysql:mysql/usr/local/mysql/log/

# chmod 750/usr/local/mysql/data

# chmod 750/usr/local/mysql/log #修改目录的所属者以及所属组

3. Unpack and compile the installation

# tar-zxv-f Mysql-5.6.10.tar.gz

# CD mysql-5.6.10

# Cmake-dcmake_install_prefix=/usr/local/mysql

-dmysql_unix_addr=/tmp/mysql.sock

-ddefault_charset=gbk

-ddefault_collation=gbk_chinese_ci

-dextra_charsets=all

-dwith_myisam_storage_engine=1

-dwith_innobase_storage_engine=1

-dwith_archive_storage_engine=1

-dwith_blackhole_storage_engine=1

-dwith_memory_storage_engine=1

-dwith_federated_storage_engine=1

-dwith_readline=1

-denabled_local_infile=1

-dmysql_datadir=/usr/local/mysql/data

-dmysql_user=mysql

-dmysql_tcp_port=3306

-dsysconfdir=/etc

-dwith_ssl=yes

# Make & make Install

Compile annotations:

-dcmake_install_prefix=/usr/local/mysql #安装目录

-dmysql_unix_addr=/tmp/mysql.sock #Unix Socket file path, customizing this path to prevent errors

-DDEFAULT_CHARSET=GBK #默认字符

-ddefault_collation=gbk_chinese_ci #校验字符

-dextra_charsets=all #安装所有扩展字符集

-dwith_myisam_storage_engine=1 #安装myisam存储引擎

-dwith_innobase_storage_engine=1 #安装innodb存储引擎

-dwith_archive_storage_engine=1 #安装archive存储引擎

-dwith_blackhole_storage_engine=1 #安装blackhole存储引擎

-dwith_memory_storage_engine=1 #安装memory存储引擎

-dwith_federated_storage_engine=1 #安装frderated存储引擎

-dwith_readline=1 #快捷键功能

-denabled_local_infile=1 #允许从本地导入数据

-dmysql_datadir=/usr/local/mysql/data #数据库存放目录

-dmysql_user=mysql #数据库属主

-dmysql_tcp_port=3306 #数据库端口

-dsysconfdir=/etc #MySQL配辑文件

-dwith_ssl=yes #数据库SSL

4. Write MySQL configuration entries:

# VI/ETC/MY.CNF

--------------------------------------------

[MySQL]

# CLIENT #

Port = 3306

Socket =/tmp/mysql.sock

[Mysqld]

# General #

user = MySQL

Default_storage_engine = InnoDB

Socket =/tmp/mysql.sock

Pid_file =/var/run/mysqld/mysqld.pid

# MyISAM #

Key_buffer_size = 32M

Myisam_recover = Force,backup

# SAFETY #

Max_allowed_packet = 16M

Max_connect_errors = 1000000

Skip_name_resolve

Sql_mode = Strict_trans_tables,error_for_division_by_zero,no_auto_create_user,no_auto_value_on_zero, No_engine_substitution,no_zero_date,no_zero_in_date,only_full_group_by

Sysdate_is_now = 1

InnoDB = FORCE

Innodb_strict_mode = 1

# DATA STORAGE #

DataDir =/usr/local/mysql/data

# BINARY LOGGING #

Log-bin =/usr/local/mysql/log/bin.log

Expire_logs_days = 30

Sync_binlog = 1

# Caches and LIMITS #

Key_buffer = 256M

Max_allowed_packet = 32M

Sort_buffer_size = 16M

Read_buffer_size = 4M

Read_rnd_buffer_size = 16M

Thread_stack = 8M

Tmp_table_size = 32M

Max_heap_table_size = 32M

Query_cache_type = 1

Query_cache_size = 128M

Query_cache_limit = 2M

Max_connections = 2048

Thread_cache_size = 512

Open_files_limit = 65535

Table_definition_cache = 1024

Table_open_cache = 2048

# INNODB #

Innodb_log_files_in_group = 2

Innodb_log_file_size = 64M

Innodb_flush_log_at_trx_commit = 1

innodb_file_per_table = 1

# 2G This value is low, the recommended change is small

Innodb_buffer_pool_size = 2G

# LOGGING #

Log-error=/usr/local/mysql/log/error.log

General_log=1

General_log_file=/usr/local/mysql/log/mysql.log

Slow_query_log=1

Slow_query_log_file=/usr/local/mysql/log/slowquery.log

Log-output=file

# avoid MySQL external locking, reduce error probability enhance stability #

Skip-external-locking

# Prevent SQL from reading local file #

Local-infile=0

----------------------------------------

5. Add MySQL library file path to the system's library file search path

Method One: Make soft link directly

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

Method Two: Use Ldconfig to import System library (recommended)

# echo "/usr/local/mysql/lib" >>/etc/ld.so.conf.d/mysql.conf

# Ldconfig

6. Output MySQL header file to system header file

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

7. Enter installation path, initialize configuration script

# Cd/usr/local/mysql

# scripts/mysql_install_db--user=mysql--datadir=/usr/local/mysql/data

8. Copy MySQL boot script to system services directory

# Cp/usr/local/mysql/support-files/mysql.server/etc/init.d/mysqld

9. System Startup Item related configuration

# chkconfig--add mysqld #添加开机启动服务

# chkconfig--level mysqld on #设置mysql启动

10. Start MySQL

# service Mysqld Start

Note: If the socket path is customized as/var/lib/mysql/mysql.sock at compile time, here you need to create a soft link to the MySQL interface to prevent errors from landing in the background or installation forum.

# ln-s/var/lib/mysql/mysql.sock/tmp/mysql.sock

11. Set up the initial account, and login backstage:

#/usr/local/mysql/bin/mysqladmin-u root password 123456 #设置密码

#/usr/local/mysql/bin/mysql-u root-p123456 #连接数据库

-----------------------------------

mysql> CREATE DATABASE Phpwind; #创建数据库

Mysql> grant all privileges in *.* to root@ '% ' identified by ' 123456 ' with GRANT option; #给root用户非本地链接所有权限, and change the password and give it to others to distribute permissions.

Mysql> Show variables; #查看mysql设置.

-----------------------------------

Note: You can also use the following command to open this service from the MySQL

#/usr/local/mysql/bin/safe_mysqld

If you do not set the Chkconfig startup entry, you can also add the following command under/etc/rc.local to enable the MySQL service to run with the system startup script.

# echo "/usr/local/mysql/bin/safe_mysqld--user=mysql &" >>/etc/rc.local

Four. Install Apache website Service

1.pcre Dependency Pack Installation

# wget Http://sourceforge.net/projects/pcre/files/pcre/8.32/pcre-8.32.tar.gz/download

# TAR-XZVF Pcre-8.32.tar.gz

# CD pcre-8.32

#./configure--prefix=/usr/local/pcre

# Make && make install

2. Download Apache

In fact, here in the Apache official website can not find httpd-2.4.4-deps.tar.bz2 compiled package, do not know how the official think, and finally studied the next recent 2.43deps version, decompression the compilation package, Found inside is actually the APR and Apr-util two Apache dependency package, now the method is directly to the 2.43 of the package to the Apache installation root directory can be compiled with Apache installation, and finally normal installation, is a helpless move, However, it is easier to install a dependency pack than to compile it separately on the web.

# wget HTTP://ARCHIVE.APACHE.ORG/DIST/HTTPD/HTTPD-2.4.3-DEPS.TAR.BZ2

# wget HTTP://ARCHIVE.APACHE.ORG/DIST/HTTPD/HTTPD-2.4.4.TAR.BZ2

3. Solution Package

Note: HTTPD-2.4.3-DEPS.TAR.BZ2 has integrated APR to check pcre for successful installation before installing Apache.

# tar JXVF httpd-2.4.4.tar.bz2

# tar JXVF httpd-2.4.3-deps.tar.bz2

# CP-RF httpd-2.4.3/* httpd-2.4.4

# CD httpd-2.4.4

4. Camouflage Apache Version Information

---------------

Modify Include/ap_release.h file "Apache" parameter is "microsoft-iis/5.0"

Modify os/unix/os.h File "Unix" parameter is "Win32"

# CD httpd-2.4.4

# VI Include/ap_release.h

#define AP_SERVER_BASEPRODUCT "Apache"

To

#define AP_SERVER_BASEPRODUCT "microsoft-iis/5.0"

# VI Os/unix/os.h

#define PLATFORM "Unix"

Change into

#define PLATFORM "Win32"

----------------

--------------essay-----------------

Here a number of detours, a lot of data on the Internet to write to the apache2.4 version of the default multithreaded mode, are in the modified conf/extra/httpd-mpm.conf under the Prefork mpm parameters, but when I actually operation found, The modified system's Apache process did not increase, but there was no problem modifying this parameter under 2.2, and it was only recently discovered in the worker mode that you actually enabled worker mode to execute this command

#/usr/local/apache2/bin/apachectl-l

The results returned are as follows:

Core.c

Mod_so.c

Http_core.c

Worker.c

See WORKER.C, here is the idea is not using the default threading mode to display the *.C this * is the Apache root directory conf/extra/httpd-mpm.conf The corresponding parameters, think of this question and then use the default threading mode to recompile the next Apache , execute the command

#/usr/local/apache2/bin/apachectl-l

Return:

Core.c

Mod_so.c

Http_core.c

Event.c

OK, under Conf/extra/httpd-mpm.conf, see the following line of parameters

<ifmodule mpm_event_module>

Startservers 3

Minsparethreads 75

Maxsparethreads 250

Threadsperchild 25

Maxrequestworkers 400

Maxconnectionsperchild 0

</IfModule>

Modify the Startservers parameter to 10

# lsof-i:80

[Root@lamp apache2]# lsof-i:80

COMMAND PID USER FD TYPE DEVICE size/off NODE NAME

httpd 1302 Root 4u IPv6 106523 0t0 TCP *:http (LISTEN)

httpd 21852 Daemon 4u IPv6 106523 0t0 TCP *:http (LISTEN)

httpd 21854 Daemon 4u IPv6 106523 0t0 TCP *:http (LISTEN)

httpd 21855 Daemon 4u IPv6 106523 0t0 TCP *:http (LISTEN)

httpd 21856 Daemon 4u IPv6 106523 0t0 TCP *:http (LISTEN)

httpd 21857 Daemon 4u IPv6 106523 0t0 TCP *:http (LISTEN)

httpd 21858 Daemon 4u IPv6 106523 0t0 TCP *:http (LISTEN)

httpd 21859 Daemon 4u IPv6 106523 0t0 TCP *:http (LISTEN)

httpd 21860 Daemon 4u IPv6 106523 0t0 TCP *:http (LISTEN)

httpd 21936 Daemon 4u IPv6 106523 0t0 TCP *:http (LISTEN)

httpd 21937 Daemon 4u IPv6 106523 0t0 TCP *:http (LISTEN)

Problem solved, it appears that the 2.4 version of the Apache default thread is required to modify the event parameters, please note here.

-----------------------------------------------------

5. Compile and install:

Compile default event MPM mode (recommended)

#./configure--prefix=/usr/local/apache2--enable-so--enable-rewrite--with-pcre=/usr/local/pcre/bin/pcre-config

compile worker mpm mode (optional, can open the service normally, but I did not do the relevant website test, does not recommend the production environment to use)

#./configure--prefix=/usr/local/apache2--enable-so--enable-rewrite-with-mpm=worker--with-pcre=/usr/local/pcre/ Bin/pcre-config

# Make && make install

# prevent Apache from starting an error.

# vi/usr/local/apache2/conf/httpd.conf

------------------------

ServerName localhost:80

------------------------

6. Start Apache

#/usr/local/apache2/bin/apachectl Start

Setting up Boot

# echo "/usr/local/apache2/bin/apachectl start" >>/etc/rc.local

7. Configure Apache:

1. Prohibit address Directory access and indexing:

#vi/usr/local/apache2/conf/httpd.conf

Search Options Indexes FollowSymLinks

Add a # comment before it

-----------------

# Options Indexes followsymlinks

-----------------

2). Hide Version Number:

#vi/usr/local/apache2/conf/httpd.conf

Add the following two lines:

------------------

Servertokens productonly

Serversignature off

------------------

3. Optimize the number of threads:

If the Apche traffic is too large, will cause the page to open slowly, download speed also reduced, if due to financial and environmental problems, can be optimized by adding module MPM to Apache2, here I choose thread type MPM to optimize:

Note: This method is valid only for compiling and installing Apache:

A. Open MPM:

#vi/usr/local/apache2/conf/httpd.conf

Locate the following line and remove the comment.

Include conf/extra/httpd-mpm.conf (if no such code can be added.) No this file httpd-mpm.conf can be new, or can be directly added to the code to)

B. Optimizing configuration:

#vi/usr/local/apache2/conf/extra/httpd-mpm.conf

Locate the following code and modify it to the following parameters.

# event MPM Configuration:

------------------------

<ifmodule mpm_event_module>

Startservers 5

Serverlimit 5000

MaxClients 4000

Minsparethreads 100

Maxsparethreads 400

Threadlimit 200

Threadsperchild 100

Maxrequestworkers 400

Maxrequestsperchild 100

</IfModule>

------------------------

# Worker MPM Configuration:

-----------------------

<ifmodule mpm_event_module>

Startservers 5

Serverlimit 5000

MaxClients 4000

Minsparethreads 100

Maxsparethreads 400

Threadlimit 200

Threadsperchild 100

Maxrequestworkers 400

Maxrequestsperchild 100

</IfModule>

-----------------------

------------------------------------------------------

The most important of these parameters are Threadsperchild and maxclients:

#ThreadsPerChild

The number of threads established by each child process, and the child process establishes these threads at startup and no longer creates new threads.

#MaxClients

Maximum number of access requests that allow simultaneous servos (maximum number of threads under worker)

#ServerLimit:

The upper bound of the maximum number of child processes, which must be greater than or equal to Maxclients/threadsperchild

#ThreadLimit:

For Threadsperchild, the value must be greater than or equal to Threadsperchild, and if the Threadlimit is set to a Threadsperchild value that is much higher than the actual need, there will be too much shared memory to be allocated. Should be consistent with the maximum value that threadsperchild can achieve.

#StartServers:

Number of service processes at server startup, which is definitely less than or equal to Serverlimit

#MinSpareThreads和MaxSpareThreads:

Keep the total number of idle threads in this range by creating or ending a child process

#MaxRequestsPerChild:

Used to control how often a server establishes a new process and ends an old process, and in fact is a parameter that, in order to prevent memory overflow, allows the maximum number of requests for the servo for each child during its lifetime. Once the Maxrequestsperchild limit is reached, the child process will end. For keepalive links, only the first request is counted. In fact, it changes the behavior of each child process limiting the maximum number of links.

You can check the Httpserver/logs/error_log log, to determine whether the maxclients need to increase, if there is an error, it shows that Apache since the last restart so far, has occurred to achieve the maxclients situation:

--------------------------------------------------

4). Close Trace method.

#vi/usr/local/apache2/conf/httpd.conf

-----------------------

Traceenable off

-----------------------

5. Implement service and Chkconfig system control httpd turn off

# vi/etc/ld.so.conf.d/apache2.4.4.conf

-----------

/usr/local/apache2/lib

------------

# Ldconfig

# CP/USR/LOCAL/APACHE2/BIN/APACHECTL/ETC/INIT.D/HTTPD

# VI/ETC/INIT.D/HTTPD

Add below the first line #!/bin/sh:

----------------

#chkconfig: 345 61 61

#description: Apache httpd

---------------

# chkconfig--add httpd

# Chkconfig httpd on

# Service httpd Restart

6. Modify log log format to achieve daily save.

#vi/usr/local/apache2/conf/httpd.conf

Find the Customlog and errorlog lines, and comment out the changes to the following parameters

--------------------------------

Customlog "|/usr/local/apache2/bin/rotatelogs/usr/local/apache2/logs/%y_%m_%d.access_log 86400" combined

ErrorLog "|/usr/local/apache2/bin/rotatelogs/usr/local/apache2/logs/%y_%m_%d.error_log 86400 480"

---------------------------------

7). Modify Apache Permissions:

# vi/usr/local/apache2/conf/httpd.conf

------------------

User www

Group www

------------------

Note: This is actually the equivalent of the user to perform web browsing will trigger the HTTPD process, the process due to belong to the main group are WWW, so the main group for the WWW directory has read and write permissions, of course, the premise of your directory u=r+w+x, This ensures that developers in the execution of PHP statements can have read and write access to the files in the project directory, to avoid the operation of the Staff manual on the need to read and write subdirectories again set 777 permissions to ensure the smooth implementation of the project.


Five. Install PHP module

1. Processing of dependent packages

No, No.

2. Install PHP

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

# TAR-JXVF PHP-5.4.13.TAR.BZ2

# CD php-5.4.13

Here we compile the PHP module that is used frequently in our project, and if there are other needs, we can customize the addition.

#./configure--prefix=/usr/local/php5--with-apxs2=/usr/local/apache2/bin/apxs--with-libxml-dir=/usr/local/lib-- With-zlib-dir=/usr/local/lib--with-mysql=/usr/local/mysql--with-mysqli=/usr/local/mysql/bin/mysql_config-- WITH-GD--enable-soap--enable-sockets--enable-xml--enable-mbstring--with-png-dir=/usr/local /local--with-curl=/usr/lib--with-freetype-dir=/usr/include/freetype2/freetype/--enable-bcmath--enable-calendar --enable-zip--enable-maintainer-zts

# Note: The last parameter--enable-maintainer-zts must be added when installing the latest version of PHP5.4 (5.3 seemingly unwanted), means to open the PHP process security thread safe, default is not added as non thread Safe, open Apache service will complain ... (This is a hole in the afternoon ... #$%^&*)

# make

# make Install

After the installation is complete:

Add PHP configuration file, need CP one source inside php.ini-development or php.ini-production to/usr/local/php/lib for php.ini

#cd ~/php-5.4.13

#cp Php.ini-development/usr/local/php5/lib/php.ini

3. Configure the Apache PHP module:

Edit Apache configuration file,

# vi/usr/local/apache2/conf/httpd.conf

and add the following line:

--------------------------------------------

AddType application/x-httpd-php. php

--------------------------------------------

and add index.php behind the DirectoryIndex line.

If PHP fails to load, check the httpd.conf configuration for the row configuration (the line is automatically written when PHP is installed by default)

LoadModule Php5_module modules/libphp5.so

4. Test PHP Load:

Note: The installed Apache web hosting path is not the same as the RPM package installation. The path for compiling the installation is/usr/local/apache2/htdocs/

You can add the following content info.php to/usr/local/apache2/htdocs/to test whether the PHP module is loaded.

# vi/usr/local/apache2/htdocs/info.php

---------------

<?php

Echo Phpinfo ();

?>

---------------

Check if port 80 is open

# lsof-i:80

Browser input http://localhost/info.php

Display the following test page content, PHP module that is loaded under Apache success

  

  

Test whether local MySQL is connected properly

# vi/usr/local/apache2/htdocs/index.php

---------------------

<?php

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

if ($conn)

echo "

Else

echo "

?>

---------------------

Browser input http://localhost

Displays the following page, indicating successful connection.

5.PHP Configuration item: (Default path/usr/local/php5/lib/php.ini)

# Vi/usr/local/php5/lib/php.ini

-------------------------

# Hide PHP Version information:

expose_php = Off

# Turn off warnings and error messages, explode paths:

Display_errors = Off

# Adjust the time zone to prevent the phpinfo () function from error.

Date.timezone =PRC

# Open the PHP error log and set the path.

Log_errors = On

Error_log =/usr/local/apache2/logs/php_error.log

--------------is done O (∩_∩) o~-----------------

Feel good, please reply to support ....

All right, okay. About compiling and installing for CentOS6.3 method that's all, if you have any questions you can leave a message below.

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.