CentOS 6.3 Compile Installation lamp environment notes _linux

Source: Internet
Author: User
Tags apache php install php mysql client openssl pack php error 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, it is recommended 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):

Copy Code code as follows:

# 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

Copy Code code as follows:

# Service Iptables Stop
# Setenforce 0
# Vi/etc/sysconfig/selinux
---------------
Selinux=disabled
---------------

Three. Install MySQL database

1. Download Compilation Package:

Copy Code code as follows:

# 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:


Copy Code code as follows:

# 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


Copy Code code as follows:

# 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:


Copy Code code as follows:



-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


Copy Code code as follows:



[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

Copy Code code as follows:

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



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


Copy Code code as follows:

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

6. Output MySQL header file to system header file

Copy Code code as follows:

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

7. Enter installation path, initialize configuration script

Copy Code code as follows:
# Cd/usr/local/mysql
# scripts/mysql_install_db--user=mysql--datadir=/usr/local/mysql/data

8. Copy MySQL boot script to system services directory

Copy Code code as follows:
# Cp/usr/local/mysql/support-files/mysql.server/etc/init.d/mysqld

9. System Startup Item related configuration

Copy Code code as follows:
# chkconfig--add mysqld #添加开机启动服务
# chkconfig--level mysqld on #设置mysql启动

10. Start MySQL

Copy Code code as follows:

# 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.


Copy Code code as follows:

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

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

Copy Code code as follows:

#/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


Copy Code code as follows:

#/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.


Copy Code code as follows:

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

12 add MySQL command set to system global variable

Note: If the MySQL client is not installed before the system, you can import the compiled MySQL command set into the system global variable
You can then use the MySQL command set directly, without the need to use absolute path access.

Copy Code code as follows:
# echo "path= $PATH:/usr/local/mysql/bin;export PATH" >>/etc/profile
# Source/etc/profile

Four. Install Apache website Service

1.pcre Dependency Pack Installation

Copy Code code as follows:

# 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.

Copy Code code as follows:

# 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.

Copy Code code as follows:

# 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"

Copy Code code as follows:

# CD httpd-2.4.4
# VI Include/ap_release.h
#define AP_SERVER_BASEPRODUCT "Apache"



To


Copy Code code as follows:

#define AP_SERVER_BASEPRODUCT "microsoft-iis/5.0"

# VI Os/unix/os.h
#define PLATFORM "Unix"



Change into


Copy Code code as follows:

#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


Copy Code code as follows:
#/usr/local/apache2/bin/apachectl-l



The results returned are as follows:


Copy Code code 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


Copy Code code as follows:
#/usr/local/apache2/bin/apachectl-l



Return:


Copy Code code as follows:

Core.c
Mod_so.c
Http_core.c
Event.c



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


Copy Code code as follows:

<ifmodule mpm_event_module>
Startservers 3
Minsparethreads 75
Maxsparethreads 250
Threadsperchild 25
Maxrequestworkers 400
Maxconnectionsperchild 0
</IfModule>



Modify the Startservers parameter to 10


Copy Code code as follows:
# 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)

Copy Code code as follows:
#./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 related website test, do not recommend to use in the production environment)


Copy Code code as follows:
#./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

Copy Code code as follows:
#/usr/local/apache2/bin/apachectl Start



Setting up Boot


Copy Code code as follows:
# echo "/usr/local/apache2/bin/apachectl start" >>/etc/rc.local



7. Configure Apache:

1. Prohibit address Directory access and indexing:

Copy Code code as follows:
#vi/usr/local/apache2/conf/httpd.conf



Search Options Indexes FollowSymLinks


Add a # comment before it


Copy Code code as follows:
-----------------
# Options Indexes followsymlinks
-----------------

2). Hide Version Number:

Copy Code code as follows:
#vi/usr/local/apache2/conf/httpd.conf



Add the following two lines:


Copy Code code as follows:
------------------
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:

Copy Code code as follows:
#vi/usr/local/apache2/conf/httpd.conf



Locate the following line and remove the comment.


Copy Code code as follows:
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:

Copy Code code as follows:
#vi/usr/local/apache2/conf/extra/httpd-mpm.conf



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


Copy Code code as follows:
# event MPM Configuration:


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


&lt;ifmodule mpm_event_module&gt;


Startservers 5


Serverlimit 5000


MaxClients 4000


Minsparethreads 100


Maxsparethreads 400


Threadlimit 200


Threadsperchild 100


Maxrequestworkers 400


Maxrequestsperchild 100


&lt;/IfModule&gt;


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


# Worker MPM Configuration:


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


&lt;ifmodule mpm_event_module&gt;


Startservers 5


Serverlimit 5000


MaxClients 4000


Minsparethreads 100


Maxsparethreads 400


Threadlimit 200


Threadsperchild 100


Maxrequestworkers 400


Maxrequestsperchild 100


&lt;/IfModule&gt;


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


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


The most important of these parameters are Threadsperchild and maxclients:

Copy Code code as follows:

#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.

Copy Code code as follows:
#vi/usr/local/apache2/conf/httpd.conf
-----------------------
Traceenable off
-----------------------

5. Implement service and Chkconfig system control httpd turn off

Copy Code code as follows:

# 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:


Copy Code code as follows:
----------------
#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

Copy Code code as follows:
--------------------------------
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:

Copy Code code as follows:
# 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

Copy Code code as follows:
# 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.

Copy Code code as follows:
#./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, the default does not add non thread safe, Open the Apache service will be an error .... (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

Copy Code code as follows:
#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,

Copy Code code as follows:
# vi/usr/local/apache2/conf/httpd.conf



and add the following line:


Copy Code code as follows:
--------------------------------------------
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)


Copy Code code as follows:
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.

Copy Code code as follows:
# vi/usr/local/apache2/htdocs/info.php
---------------
<?php
Echo Phpinfo ();
?>
---------------



Check if port 80 is open


Copy Code code as follows:
# 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

Copy Code code as follows:
# 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)

Copy Code code as follows:
# 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~-----------------

Related Article

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.