Lamp Environment Construction Notes

Source: Internet
Author: User
Tags install openssl zts

I. Introduction to Lamp

LAMP is linux apache MySQL php shorthand, in fact, is the Apache, MySQL and PHP installed on the Linux system, to form an environment to run the PHP scripting language. Lamp is the world's first Web server, very popular.

Two. System environment and software version

1. System: CentOS-6.5 32-bit minimal under virtual machine

[Email protected] ~]# cat/etc/issue

CentOS Release 6.5 (Final)

Kernel \ r on an \m

[Email protected] ~]# uname-a

Linux localhost.localdomain 2.6.32-431.el6.i686 #1 SMP Fri Nov 00:26:36 UTC i686 i686 i386 gnu/linux

2.iptables off, SELinux closed (temporarily closed, can also be permanently closed);

[Email protected] ~]# iptables-f

[Email protected] ~]# Setenforce 0

Third, the installation process

(i). Install MySQL

1. Prepare the data storage disk space, if you want to store a lot of data, you can prepare a large hard disk to mount to a directory, here we add a 5G hard disk, mounted to the root directory of/mysqldata

[[email protected]/]# DF

Filesystem 1k-blocks used Available use% mounted on

/dev/sda3 18423556 1016440 16471232 6%/

Tmpfs 515264 0 515264 0%/dev/shm

/DEV/SDA1 198337 24976 163121 14%/boot

/DEV/SDB1 5154852 141304 4751692 3%/mysqldata

2. Create MySQL user mysql using the system

[Email protected]/]# useradd-r-s/sbin/nologin-m-d/mysqldata/mydata/mysql

[Email protected]/]# chown-r mysql:mysql/mysqldata

3. Install and initialize the mysql-5.5.28

[email protected] ~]# Yum install-y wget #安装wget

[Email protected] ~]# cd/usr/local/src/

[Email protected] src]# wget

[Email protected] src]# TAR-ZXVF mysql-5.1.40-linux-i686-icc-glibc23.tar.gz

[Email protected] src]# mv Mysql-5.1.40-linux-i686-icc-glibc23. /mysql

[Email protected] src]# CD. /mysql/

[Email protected] mysql]# chown-r mysql:mysql.

[Email protected] mysql]#/scripts/mysql_install_db--user=mysql--datadir=/mysqldata/mydata/

Installing MySQL system tables ...

Ok

Filling Help Tables ...

Ok

... #看到两个OK即成功初始化

[Email protected] mysql]# chown-r root.

4. Copy the configuration file

[email protected] mysql]# CP support-files/my-large.cnf/etc/my.cnf

CP: Do you want to overwrite "/etc/my.cnf"? Y

[email protected] mysql]# Yum install-y vim-enhanced #安装vim文本编辑器

VIM/ETC/MY.CNF and modify the value of thread_concurrency in this file to multiply your number of CPUs by 2, for example using the following line:

Thread_concurrency = 2

Also add the following line to specify where the MySQL data file will be stored:

DataDir =/mysqldata/mydata

5. Provide SYSV service script for MySQL

[email protected] mysql]# CP support-files/mysql.server/etc/init.d/mysqld

[Email protected] mysql]# chmod 755/etc/init.d/mysqld

[Email protected] mysql]# Vim/etc/init.d/mysqld

Need to modify "Datadir=/mysqldata/mydata"

[Email protected] mysql]# chkconfig--add mysqld

[Email protected] mysql]# chkconfig mysqld on

[[Email protected] mysql]# service mysqld start

[[Email protected] mysql]# PS aux |grep mysqld #查看是否启动

Root 1321 0.0 0.1 3044 1312 pts/0 S 22:02 0:00/bin/sh./bin/mysqld_safe--datadir=/mysqldata/mydata--p Id-file=/mysqldata/mydata/localhost.localdomain.pid

MySQL 1433 1.1 4.2 381608 43512 pts/0 Sl 22:02 0:00/usr/local/mysql/bin/mysqld--basedir=/usr/local/mysql-- Datadir=/mysqldata/mydata--user=mysql--log-error=/mysqldata/mydata/localhost.localdomain.err--pid-file=/ Mysqldata/mydata/localhost.localdomain.pid--socket=/tmp/mysql.sock--port=3306

Root 1446 0.0 0.0 5980 748 pts/0 s+ 22:02 0:00 grep mysqld

6. Create a user and authorize

[Email protected] ~]# cd/etc/profile.d/

[Email protected] profile.d]# vim mysql.sh

Export echo path= $PATH:/usr/local/mysql/bin #增加一行并保存, then launch terminal to log in again to use MySQL command

[[email protected] ~]# MySQL

mysql> set password for ' root ' @ ' localhost ' = password (' 123456 '); #为root用户设置密码

mysql> use MySQL

Database changed

mysql> Delete from user where user= '; #删除匿名用户

Mysql> select Host,user from user;

+-----------------------+------+

| Host | user |

+-----------------------+------+

| 127.0.0.1 | Root |

| localhost | Root |

| Localhost.localdomain | Root |

+-----------------------+------+

3 Rows in Set (0.00 sec)

mysql> CREATE DATABASE lamp;

Mysql> grant all privileges on lamp.* to ' lamp ' @ ' percent ' identified by ' 123456 '; #创建lamp数据库并授权给用户lamp

mysql> flush Privileges;

Mysql> \q

[Email protected] ~]# mysql-ulamp-p123456 #测试刚刚创建的用户

Mysql>

MySQL Installation complete


(b). Install httpd

The APR version installed by CENTOS6 Yum is no longer available for the httpd-2.4 version. Therefore, the source code is required to compile APR and Apr-util

[email protected] ~]# Yum install-y gcc #安装编译器

[Email protected] src]# wget http://mirrors.cnnic.cn/apache/apr/apr-1.5.1.tar.bz2

[Email protected] src]# wget http://mirrors.cnnic.cn/apache/apr/apr-util-1.5.4.tar.gz

[Email protected] src]# tar jxvf apr-1.5.1.tar.bz2 #编译安装apr

[Email protected] src]# CD apr-1.5.1

[Email protected] apr-1.5.1]#/configure--PREFIX=/USR/LOCAL/APR

[[email protected] apr-1.5.1]# make && make install

[Email protected] src]# tar zxvf apr-util-1.5.4.tar.gz #编译安装apr-util

[Email protected] apr-util-1.5.4]# CD apr-util-1.5.4

[Email protected] apr-util-1.5.4]#/configure--prefix=/usr/local/apr-util--with-apr=/usr/local/apr/

[[email protected] apr-util-1.5.4]# make && make install

Download and install httpd-2.4.12

[email protected] ~]# Yum install pcre-devel-y

[email protected] ~]# Yum install openssl-devel-y

[Email protected] src]# wget

[Email protected] src]# CD httpd-2.4.12

[Email protected] httpd-2.4.12]#/configure--prefix=/usr/local/apache--enable-so--enable-ssl--enable-cgi-- Enable-rewrite--with-zlib--with-pcre--with-apr=/usr/local/apr--with-apr-util=/usr/local/apr-util-- Enable-modules=most--enable-mpms-shared=all--with-mpm=event

[[email protected] httpd-2.4.12] #make && make install

Start httpd

[Email protected] httpd-2.4.12]# vim/usr/local/apache/conf/httpd.conf

Modified ServerName to: ServerName localhost:80

[Email protected] httpd-2.4.12]#/usr/local/apache/bin/apachectl start #启动httpd

[Email protected] httpd-2.4.12]# Curl localhost #测试

To the other computer on the LAN, open the browser, enter the host's IP, display it Works! That is, the HTTPD is installed successfully!

(c). Install PHP


[Email protected] src]# wget http://us1.php.net/distributions/php-5.6.7.tar.bz2

[Email protected] src]# TAR-JXVF php-5.6.7.tar.bz2

[Email protected] src]# CD php-5.6.7

[email protected] php-5.6.7]# Yum install-y libxml2-devel

[Email protected]lhost php-5.6.7]# Yum install-y bzip2 bzip2-devel

[[email protected] php-5.6.7]# wget #这里需要安装第三方的yum源, there is no libmcrypt-devel in the default yum source, download it first

[Email protected] php-5.6.7]# RPM-IVH epel-release-6-8.noarch.rpm #安装

[email protected] php-5.6.7]# Yum install-y libmcrypt-devel

[Email protected] php-5.6.7]#/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

[[email protected] httpd-2.4.12] #make && make install

[email protected] php-5.6.7]# CP Php.ini-production/usr/local/php/etc/php.ini

(d). Apache Combined with PHP

[Email protected] php-5.6.7]# vim/usr/local/apache/conf/httpd.conf

#1, add the following two lines

AddType application/x-httpd-php. php

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

#2, positioning to DirectoryIndex index.html

# Modified to:

DirectoryIndex index.php index.html

#而后重新启动httpd, or let it reload the configuration file to test if PHP is already working.

[Email protected] php-5.6.7]#/usr/local/apache/bin/apachectl restart

[Email protected] php-5.6.7]# NETSTAT-LNPT |grep httpd

TCP 0 0::: +:::* LISTEN 18316/httpd

[Email protected] ~]# vim/usr/local/apache/htdocs/1.php

#添加如下内容, save

<?php

Phpinfo ();

?>

#到其他电脑上打开, enter ip/1.php and you can see a page of information about PHP.

[Email protected] htdocs]# vim 2.php #自定义一个关于php连接mysql是否成功的测试页面;

<?php

$link = mysql_connect (' 127.0.0.1 ', ' lamp ', ' password ');

if ($link)

echo "Success!!!"

Else

echo "Failure ..."

Mysql_close ();

?>

#到其他电脑上打开, enter ip/2.php, and note that the MYSQLD service is enabled first.

(v). Install Phpmysqladmin

Phpmysqladmin website Address: http://www.phpmyadmin.net/home_page/downloads.php

[Email protected] src]# wget

[Email protected] src]# Unzip Phpmyadmin-4.4.1.1-all-languages.zip

[Email protected] src]# MV PHPMYADMIN-4.4.1.1-ALL-LANGUAGES/USR/LOCAL/APACHE/HTDOCS/PMA

#浏览器输入IP/PMA to access the admin page

(vi). Install Xchche for PHP acceleration

[Email protected] xcache-3.2.0]# yum-y install M4 autoconf #安装编译环境

[Email protected] src]# wget

[Email protected] src]# TAR-ZXVF xcache-3.2.0.tar.gz

[Email protected] src]# CD xcache-3.2.0

[Email protected] xcache-3.2.0]#/usr/local/php/bin/phpize #执行后会生成configure文件

[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 && make install

#编辑php. ini, integrating PHP and XCache:

#首先将xcache提供的样例配置导入php. ini

[Email protected] xcache-3.2.0]# cd/etc/

[Email protected] etc]# mkdir PHP.D

[Email protected] etc]# cp/usr/local/src/xcache-3.2.0/xcache.ini/etc/php.d #说明: Xcache.ini file in the source directory of XCache.

Next edit Php.d/xcache.ini, locate the line that begins with extension, and modify it to the following line:

Extension =/usr/local/php/lib/php/extensions/no-debug-zts-20131226/xcache.so

Note: If you have more than one zend_extension line in the php.ini file, make sure that this new row is ranked first.

#到其他电脑上打开, enter ip/1.php and you can see a page of information about PHP. The installation is successful with XCache related information on the page.

(vii). Enable Server state

The Mod_status module allows the administrator to view the server's execution status, which shows the current server's statistics through an HTML page. These data typically include, but are not limited to:

(1) Number of worker processes in working condition;

(2) Number of worker processes in idle state;

(3) The state of each worker, including the number of requests that the worker has responded to, and the number of bytes of content sent by the worker;

(4) The total number of bytes sent by the current server;

(5) The current length of the server since it was last started or rebooted;

(6) The average number of requests per second, the average number of bytes sent per second, and the average number of bytes of content requested by each request;

The way to enable the status page is simple, just add the following to the main configuration file:

<Location/server-status>

SetHandler Server-status

Require all granted

</Location>

It should be recalled that the status information here should not be accessed by everyone at will, so you should restrict the only clients that are allowed to be viewed by certain addresses. For example, use require IP 192.168.16.0/24 to restrict only hosts that specify network segments from viewing this page.

Browser input: Ip/server-status can see the information page.


Lamp Environment Construction Notes

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.