LAMP(Apache+Nginx+Php)

A, LAMP Application Platform Overview:

1. Overview: LAMP is the most mature application mode of a corporate Web site can provide dynamic web site and application development environment, which constitutes linux, apache, mysql, php or python or perl language and other advantages: low cost, ease of development , easy to use, security and stability;
2. Category:
static: there are pages written in plain language html tags made, no matter what environment, in what capacity have access not change;
dynamic: Prepared by the web programming language, for example, : java, php, .net, python languages, dynamic pages, dynamic pages is a dynamic html pages and consists of a web page, you can interact with the database, the server may constitute operating through dynamic pages;
3.php (hypertext pretreatment language): embedded html is a server-side language, support windows, linux, unix and other platforms;

Two, LAMP works:

1.LAMP processing flow:
Apache: transfer web page provides access between the client and server;
PHP: .php page providing operating environment;
MySQL: providing .php page or the user data storage and writing position;

Third, the case: the deployment of LAMP application platform;

Case line environment

1.apache installation

apache Package
httpd-2.4.29.tar.gzt apr-1.6.2.tar.gz apr-util-1.6.0.tar.gz (cross-platform tools Package)

1. Prepare the installation package apache

tar xf /mnt/apr-1.6.2.tar.gz -C /opt #将跨平台组件包解压到/opt目录下
tar xf /mnt/apr-util-1.6.0.tar.gz -C /opt #将跨平台组件包解压到/opt目录下
tar xf /mnt/httpd-2.4.29.tar.bz2 -C /opt #解压apache安装包
mv /opt/apr-1.6.2 /opt/httpd-2.4.29/srclib/apr #将跨平台组件包剪切到 /httpd-2.4.29/srclib目录并且更名为 apr
mv /opt/apr-util-1.6.0 /opt/httpd-2.4.29/srclib/apr-util 

2. Equipment Environmental Package

yum -y install \
gcc \  #C语言编译器
gcc-c++ \ #C++编译器
make \ #make工具(把源代码文件转换成二进制可执行文件)
pcre-devel \ #pcre语言的开发
expat-devel \  #解析html文件
perl #pace编辑器

3. Configure apache

cd /opt/httpd-2.4.29 #cd到httpd-2.4.29目录
./configure \
--prefix=/usr/local/httpd \ #--prefix 自定将httpd服务程序安装到哪个目录
--enable-so \  #--enable-so 启用动态模块支持,使httpd具备进一步扩展功能的能力
--enable-rewrite \ #--enable-rewrite 启用网页地址重写功能,用于网站优化及目录迁移维护
--enable-charset-lite \ #--enable-chaset-lite 启用字符支持 以便使用各种字符集编码的网页
--enable-cgi #启用CGI脚本程序支持,便于扩展网站的应的应用访问能力

4. Compile and install

[root@hui httpd-2.4.29]# make #将源代码转换为可执行的程序
[root@hui httpd-2.4.29]# make install #安装

5. Add httpd system services (configuration startup script, the script can control the establishment of service)

[root@hui ~]# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd  #将apachetcl(启动脚本)复制为/etc/init.d/httpd
`[root@hui ~]# sed -i -e '1 a# chkconfig: 35 85 21 ' -e '2 i # description: Apache is a World Wide Web server' /etc/init.d/httpd`  #在文件开头添加chkconfig 识别配置, chkconfig:35 85 21 //服务识别参数,在级别3,5中启动;启动和关闭的顺序分别85、21 
[root@hui ~]# chkconfig --add httpd  #将httpd添加为系统服务

6. Determine the Web site name, IP address, configure the httpd service

[root@hui ~]sed -i '/#ServerName www.example.com.com:80/s/example/yum/ '/usr/local/httpd/conf/httpd.conf #修改网站名称

[root@hui ~]sed -i -e '/Listen 80/s/^/#/' -e  '/#Listen 12.34.56.78:80/s/#Listen 12.34.56.78:80/Listen 192.168.242.157/' /usr/local/httpd/conf/httpd.conf #修改web主机的IP地址

7. optimize the execution path - source code compiled by the installation of httpd service, program path is not in the default search path, in order that the service is more convenient in use, what can I add a symbolic link to relevant procedures.

[root@hui ~]ln -s /usr/local/httpd/conf/httpd.conf /etc/  #
[root@hui ~]ln -s /usr/local/httpd/bin/* /usr/local/bin/

8. Turn off the firewall, start the service
systemctl STOP firewalld.service
setenforce 0
Service Start httpd

II. Installation Mysql

1. Installation Environment package
[root@hui ~]# yum install -y ncurses-devel autoconf cmake
2. Compile the source code and a mounting
(1) unpacking

[root@hui mnt]# tar /mnt/mysql-5.6.26.tar.gz -C /opt

(2) Configuration
[root@hui mysql-5.6.26]# cd /opt/mysql-5.6.26/

[root@hui mysql-5.6.26]cmake  \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ #指定将mysql数据库程序安装到目录下
-DDEFAULT_CHARSET=utf8 \  #指定默认使用的字符集编码
-DDEFAULT_COLLATION=utf8_general_ci \ #指定默认使用的字符集校验对规则
-DEXTRA_CHARSETS=all \ #拓展字符集
-DSYSCONFIDIR=/etc \ #指定初始化参数文件目录
-DMYSQL_DATADIR=/home/mysql/ \
-DMYSQL_UNIX_ADDR=/home/mysql/mysql.sock  #连接数据库文件

(3) compile and install
<br/>[root@hui mysql-5.6.26]# make && make install

3 . Adding system services and creating the configuration file (add mysql service system, for management by chkconfig, you can use the script source package of direct services provided. Find mysql.server script file support-files folder, copy it to under /etc/init.d/ directory, changed its name to mysqld)

[root@hui mysql-5.6.26]#cp -f support-files/my-default.cnf /etc/my.cnf # 把配置文件复制到/etc/目录下,并且改名为my.cnf
[root@hui mysql-5.6.26]# cp support-files/mysql.server /etc/init.d/mysqld #把启动文件复制到/etc/init.d/目录下 ,并且改名为mysqld。
[root@hui mysql-5.6.26]# chmod 755 /etc/init.d/mysqld     #设置可执行权限
[root@hui mysql-5.6.26]# chkconfig --add /etc/init.d/mysqld #通过chkconfig命令将其添加为mysqld系统服务,这样可以用service工具控制mysql数据库服务
[root@hui mysql-5.6.26]#chkconfig  mysqld --level 235 on

4. setting environment variables - for convenience mysql command in any directory, needs / etc / profile set environment variables.

[root@hui mysql-5.6.26]#echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile #设置mysql命令的环境变量
[root@hui mysql-5.6.26]#source /etc/profile #立即执行

5. The key operational users - in order to strengthen the access control database services, it is recommended to use a dedicated user to run, such as mysql. The user does not need to log in directly to the system
[root @ hui mysql-5.6.26] # useradd -s / sbin / nologin mysql # Create mysql user
[root @ hui mysql-5.6.26] # chown -R mysql: mysql / usr / local / mysq database directory permissions
6. initialize the database - in order to be able to normal, they should perform the initialization script mysql_install_db to run as user mysql with mysql database system, specified data storage directory, etc.

/usr/local/mysql/scripts/mysql_install_db \
--user=mysql \
--ldata=/var/lib/mysql \
--basedir=/usr/local/mysql \
--datadir=/home/mysql

7.

[root@hui mysql-5.6.26]# ln -s /var/lib/mysql/mysql.sock  /home/mysql/mysql.sock
[root@hui mysql-5.6.26]# sed -i -e '/basedir=/c basedir=/usr/local/mysql' -e 'datadir=/c datadir=/home/mysql' /etc/init.d/mysqld

[root@hui mysql-5.6.26]#service mysqld start
[root@hui mysql-5.6.26]#mysqladmin -u root -p password "abc123" //给root账号设置密码

III. Installing PHP

1. Equipment Environmental

[root@localhost ~]yum -y install \
gd \   #图像化处理库
libpng \ #支持png图片
libpng-devel \
pcre \ #支持正则表达式
pcre-devel \ #支持正则表达式
libxml2-devel \ #支持解析html语言
libjpeg-devel #支持jpeg图片

2. compile and install PHP
(1). Unpack


[root@localhost ~]tar xf php-5.6.11.tar.bz2 -C /opt
[root@localhost opt]# cd /opt/php-5.6.11/

(2) Configuration

[root@localhost php-5.6.11]#./configure \
--prefix=/usr/local/php5 \ #指定安装路径
--with-gd \ #gd库
--with-zlib \ #压缩
--with-apxs2=/usr/local/httpd/bin/apxs \ #设置Apache HTTPServer 提供的apxs模块支持程序的文件位置
--with-mysql=/usr/local/mysql \ #设置Mysql数据库服务程序的安装位置
--with-config-file-path=/usr/local/php5 \ #设置PHP的配置文件php.ini将要存放的位置
--enable-mbstring #启用多字节字符串功能,以便支持中文代码

(3) compile and install

[root@localhost php-5.6.11]# make
[root@localhost php-5.6.11]# make install

3. Set the LAMP components of the environment
set LAMP environment components, including PHP's configuration file to the php.ini , Apche configuration file httpd.conf adjustment. The former is used to determine the operating parameters of PHP, which is used to load libphp5.so module to support php page.
(1) adjust the configuration file

[root@localhost php-5.6.11]# cp php.ini-development /usr/local/php5/php.ini #复制配置文件到 /usr/local/php5/ 目录下并且取名为:php.ini
[root@localhost php-5.6.11]# ln -s /usr/local/php5/bin/* /usr/local/bin/  #对/usr/local/php5/bin/*  命令做软连接,便于系统识别

(2). Adjustment httpd.conf configuration
to make the httpd web server that supports PHP parsing function, you need to load module file PHP program through LoadModule configuration, and add support for the ".php" file type page by AddType configuration items.

[root@localhost ~]#sed -i '/DirectoryIndex index.html/ c  DirectoryIndex index.html index.php' /etc/httpd.conf # 修改**DirectroryIndex**配置行 ,添加index.php,来识别常见的PHP首页文件
[root@localhost ~]# sed -i '393 a AddType application/x-httpd-php .php' /etc/httpd.conf  #设置对.PHP文件的支持

[root@localhost ~]# sed -i '394 a AddType application/x-httpd-php-source .phps' /etc/httpd.conf #
[root@localhost ~]cat >>/usr/local/httpd/htdocs/index.php <<-EOF
> <?php
> phpinfo();
> ?>
> EOF

[root@localhost ~]# sed -i '394 a AddType application/x-httpd-php-source .phps' /etc/httpd.conf #
[root@localhost ~]cat >>/usr/local/httpd/htdocs/index.php <<-EOF

<?php
phpinfo();
?>
EOF

Guess you like

Origin blog.51cto.com/14307755/2449705