Author | JackTian
Micro-channel public number | IT's Jiege trip (ID: Jake_Internet)
Reprint please contact an authorized (micro letter ID: Hc220066) Note: The blog from the garden
1. What is the LAMP architecture?
LAMP architecture is one of the mature enterprise web application model that can work in a collaborative system and related software, provides dynamic Web site services and application development environment.
LAMP is an acronym L
: Linux操作系统
, A
: Apache网站服务器
, M
: MySQL数据库服务器
, P
: PHP、Python、Perl编程语言
;
2.LAMP architecture platform of the constituent components
-
Linux操作系统
: LAMP architecture is the basis for the operating system support Web site, has good stability, compatibility; -
Apache网站服务器
: LAMP is a front-end architecture, powerful, good stability Web server program, providing user-oriented site visits, send web pages, documents, pictures and other content; -
MySQL数据库服务器
: LAMP back-end architecture, open source relational database system for storing data in a MySQL database, can be queried via SQL statements; -
PHP、Python、Perl编程语言
: Dynamic web programming language used to explain the dynamic page document that provides development and runtime environment Web applications. PHP is an open-source general-purpose scripting language is a widely used, and can be embedded into HTML for Web application development.
Application advantages 3.LAMP architecture platform
-
成本低
: Open source software, freely available and free to use, not too strict limitations on technology and licenses, greatly reducing implementation costs. -
可定制
: Has a large number of additional components and can be extended with modules, customized to meet the needs of enterprise applications, self-development, adding new features. -
易开发
: Dynamic website LAMP platform-based page code is simple binding of HTML markup language very well, and can easily read and modify the page code. -
方便易用
: PHP programming language interpretative language, development of various Web programs do not need to compile, easy to use portable, the entire website project program, can be copied to the site directory, you can access. -
安全稳定
: Thanks to the open source strengths;
4. Building the PHP runtime environment
PHP:Hypertext Preprocessor,超文本预处理器的字母缩写
, Is a versatile open source scripting language is a widely used, and can be embedded into HTML for Web application development, and has better page execution speed, supports most popular databases and a variety of operating systems .
PHP 4.1 installation package
Ready to work
To avoid conflicting program and so on, first to rpm
install manner php
and related dependencies.
If already exists, can be based on the actual situation 卸载 php php-cli php-ldap php-common php-mysql
, etc. In addition, the need to install zlib-devel
and libxml2-devel
packages.
1 [root@localhost lamp]# rpm -e php php-cli php-ldap php-common php-mysql --nodeps 2 [root@localhost lamp]# rpm -ivh /mnt/Packages/zlib-devel-1.2.3-29.el6.x86_64.rpm 3 [root@localhost lamp]# rpm -ivh /mnt/Packages/libxml2-devel-2.7.6-14.el6.x86_64.rpm
4.2 Installing an expansion tool library
In practice, companies, based in part on PHP
the development Web
will require an additional extension tool applications.
For example: 数据加密工具:libmcrypt、mhash、mcrypt
and so, this article involved in the installation package will be packaged together 公众号后台
, we can by the end of the text 获取
were acquired way 或
through 站点:http://sourceforge.net
downloading, installing PHP
before the packages, you must first install the extensions of these tools.
Installation libmcrypt
1 [root@localhost lamp]# tar zxf libmcrypt-2.5.8.tar.gz -C /usr/src/ 2 [root@localhost lamp]# cd /usr/src/libmcrypt-2.5.8/ 3 [root@localhost libmcrypt-2.5.8]# ./configure 4 [root@localhost libmcrypt-2.5.8]# make && make install 5 [root@localhost libmcrypt-2.5.8]# ln -s /usr/local/lib/libmcrypt.* /usr/lib/
Installation mhash
1 [root@localhost lamp]# tar zxf mhash-0.9.9.9.tar.gz -C /usr/src/ 2 [root@localhost lamp]# cd /usr/src/mhash-0.9.9.9/ 3 [root@localhost mhash-0.9.9.9]# ./configure 4 [root@localhost mhash-0.9.9.9]# make && make install 5 [root@localhost mhash-0.9.9.9]# ln -s /usr/local/lib/libmhash* /usr/lib/
Install mcrypt
1 [root@localhost lamp]# tar zxf mcrypt-2.6.8.tar.gz -C /usr/src/ 2 [root@localhost lamp]# cd /usr/src/mcrypt-2.6.8/ 3 [root@localhost mcrypt-2.6.8]# ./configure 4 [root@localhost mcrypt-2.6.8]# ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config 5 [root@localhost mcrypt-2.6.8]# export LD_LIBRARY_PATH=/usr/local/lib: LD_LIBRARY_PATH # 解决 configure 配置报错的现象 6 [root@localhost mcrypt-2.6.8]# ./configure 7 [root@localhost mcrypt-2.6.8]# make && make install
4.3 Compile and install PHP
Unpack
The download PHP
source package and released to extract the /usr/src
directory, and the switching to the directory.
1 [root@localhost lamp]# tar zxf php-5.3.28.tar.gz -C /usr/src/ 2 [root@localhost lamp]# cd /usr/src/php-5.3.28/
Configuration
Custom PHP
when configuration options are required httpd
and mysqld
the installation path, easy to add support related settings so that LAMP
the components work together. Also specify 安装路径
, 启用多字节支持
, 加密扩展支持
and so on.
1 [root@localhost php-5.3.28]# ./configure --prefix=/usr/local/php5 --with-mcrypt --with-apxs2=/usr/local/httpd/bin/apxs --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php5 --enable-mbstring
The parameters included in the meaning of the options:
-
--prefix: Specifies the
PHP
install program to which directory; -
--with-mcrypt:
加载数据加密等扩展工具
; -
--with-apxs2: Set
apache http server
apxs file location module provides support process; -
--with-mysql: setting
MySQL 数据库
the installation location of the service program; -
--with-config-file-path: Set
PHP
the configuration filephp.ini
will be stored position; -
--enable-mbstring:
启用多字节字符串功能,支持中文等代码
;
If, during configuration, the following error appears, it has led to compile unsuccessful phenomenon;
1 configure: error: Cannot find libmysqlclient under /usr. 2 Note that the MySQL client library is not bundled anymore!
By looking libmysqlclient, libmysqlclient.so.16.0.0 found in / usr / lib64 / mysql / directory to make soft links, PHP by default to the / usr / lib / search, did not find it, find the problem just fine solved.
Solution
Run the following commands to;
1 cp-Rp /usr/lib64/mysql/libmysqlclient.so.15.0.0 /usr/lib/libmysqlclient.so
Compile and install
No error occurred during compilation longer period, then the PHP
installation program is basically complete.
1 [root@localhost php-5.3.28]# make && make install
The components of the environment setting LAMP
mainly includes
-
PHP 的配置文件 php.ini
: PHP determining operating parameters; -
Apache 的配置文件 httpd.conf
: Libphp5.so load module, easy to support PHP pages;
php.ini configuration adjustments
php.ini and set up the basic settings, PHP packages installed, the server does not automatically create php.ini file, but in the source directory has two respectively . php.ini 开头的样例配置文件,分别用于开发环境和生产环境
. 1 [the root @ localhost PHP-5.3.28] # LL php.ini- * 2 -rw-R & lt -. R-- games. 1 501 69606 dated 12 is the php.ini-Development, 2013. 11 # developed sample file . 3 -rw -r -. r-- 1 501 games 69627 12 2013 the php.ini-production's Yue 11 # production sample files
Select a sample file and copy it to PHP
the directory profile /usr/local/php5
under and renamed php.ini
.
1 [root@localhost php-5.3.28]# cp /usr/src/php-5.3.28/php.ini-development /usr/local/php5/php.ini
Modify php.ini
the configuration content file, you can control the PHP
execution characteristics of the web page.
Whether to allow users to upload files, set a size limit upload files, set the default character set used to load additional expansion modules such as;
. 1 [the root @ localhost PHP-5.3.28] # VI /usr/local/php5/php.ini 2 784 DEFAULT_CHARSET = " UFT-. 8 " # Set the default character set: UTF-. 8 . 3 882 = the On the file_uploads # allows PHP file upload page . 4 891 the upload_max_filesize = 2M # allowed to upload file size limit . 5 894 max_file_uploads = 20 is # files for each HTTP request to upload the maximum allowed . 6 740. post_max_size = 8M # data amount of each form submitted by limiting post . 7 226 the short_open_tag the On = # allowing identification labeling of PHP phrases
添加 ZendGuardLoader 优化模块
To improve PHP
the performance of programs, optimize page loading speed. This optimization module applies to PHP 5.3 series version, but also from 官方站点:http://www.zend.com 下载
.
First, download the ZendGuardLoader
package extract to /usr/src
a directory, and one of the php-5.3.x
replication module files in the directory to the PHP
module in folder.
1 [root@localhost lamp]# tar zxf ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz -C /usr/src/ 2 [root@localhost lamp]# cd /usr/src/ZendGuardLoader-php-5.3-linux-glibc23-x86_64/php-5.3.x/ 3 [root@localhost php-5.3.x]# cp ZendGuardLoader.so /usr/local/php5/lib/php
Modify php.ini
the configuration file, and add load to enable ZendGuardLoader.so
configuration statements modules.
1 [root@localhost php-5.3.x]# vi /usr/local/php5/php.ini 2 1919 zend_extension=/usr/local/php5/lib/php/ZendGuardLoader.so 3 1920 zend_loader.enable=1
httpd.conf configuration adjustments
The httpd服务器
support PHP
page analytic functions, through LoadModule
configuration item PHP
module file for the program, and then add AddType
configuration items and support for .php
web page file types, you also need to DirectoryIndex
add configuration items to configure lines index.php
and index.html
to identify common PHP
home page file.
Restart the httpd
service, and update the configuration item;
1 [root@localhost php-5.3.x]# vi /usr/local/httpd/conf/httpd.conf 2 53 LoadModule php5_module modules/libphp5.so 3 54 AddType application/x-httpd-php .php 4 170 DirectoryIndex index.php index.html 5 [root@localhost php-5.3.x]# /usr/local/httpd/bin/apachectl restart
Meaning of the above-mentioned configuration contains
LoadModule is installed PHP
automatically during added, AddType need to manually add, DirectoryIndex need to be modified on the basis of the original;
-
php5_module
: Module name; -
modules/libphp5.so
: Module file locations;
6. Is LAMP test has been set up successfully
Completed PHP
after installation and configuration-related extension tool, they can be tested to verify the correlation function LAMP架构平台
and the root directory of websites /usr/local/httpd/htdocs/
created corresponding test PHP
page, accessed through a browser, to determine LAMP
whether to build a successful,
Be verified in two ways:
-
PHP 网页解析是否成功;
-
访问 MySQL 数据库系统进行验证;
PHP test page is normal
Write a suffix test1.php
format of the page file, combined with PHP
the built-in phpinfo( )
function to show server PHP
environment information, file code should be included <?php···?>
between the mark and the file in the root of the site /usr/local/httpd/htdocs/
.
1 [root@localhost php-5.3.x]# vi /usr/local/httpd/htdocs/test1.php 2 <?php 3 phpinfo( ); 4 ?>
Accessed through a browser called: test1.php
test page.
E.g:http://www.jacktiangjwan.com/test1.php
You can see the PHP
version number of the program, configuration commands, run variables;
Test whether PHP website can be accessed MySQL database
Write a suffix test2.php
page file format 添加数据库的操作命令
, and is used to verify MySQL 数据库
the connection, query and other operations.
-
mysql_connect()函数
: To connectMySQL数据库
, specify the destination host address, user name, password; -
mysql_close
: Disconnect from the database;
. 1 [@ localhost the root-MySQL 5.5.22] # VI /usr/local/httpd/htdocs/test2.php 2 < ? PHP . 3 $ Link = mysql_connect ( ' 127.0.0.1 ' , ' the root ' , ' 666666 ' ); # connect to the MySQL database 4 IF ($ Link) echo " Congratulations, successfully connect to the MySQL database! " ; # return information when a successful connection 5 mysql_close (); # disconnect from the database 6 >?
Restart Service
1 [root@localhost mysql-5.5.22]# /usr/local/httpd/bin/apachectl restart
Accessed through a browser called: test2.php
test page.
E.g:http://www.jacktiangjwan.com/test2.php
We can see a successful connection MySQL 数据库
message when you are wrong user name and password, or mysql_connect()函数
not running caused the database connection fails, you will be prompted an error page.