LAMP environment to build
A, MySQL deployment installation
1. MySQL download
Official Download: http: //dev.mysql.com/downloads/mysql/#downloads
Image for download: https: //downloads.mysql.com/archives/community/
Download the MySQL Installer 1.1
cd /usr/local/src/
wget ftp://ftp.stu.edu.tw/pub/Unix/Database/Mysql/Downloads/MySQL-5.1/mysql-5.1.73-linux-i686-glibc23.tar.gz
1.2 initial installation
#### 解压安装包
tar zxvf /usr/local/src/mysql-5.1.73-linux-i686-glibc23.tar.gz
#### 移动解压的安装文件到/usr/local 目录下,并修改名称为mysql
mv mysql-5.1.73-linux-i686-glibc23 /usr/local/mysql
#### 建立MySQL账户
useradd -s /sbin/nologin mysql
#### 创建数据存放目录
mkdir -p /data/mysql ; chown -R mysql:mysql /data/mysql
#### 初始化数据库
cd /usr/local/mysql
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
#### user 定义数据库的所属主,datadir 定义数据库数据存放位置,建议放到大空间的分区上,这个目录需要创建
#### 这一步骤很关键,出现两个“OK” 说明执行正确。
1.3 modify the configuration, startup files, etc.
#### 拷贝配置文件
cp support-files/my-large.cnf /etc/my.cnf
#### 拷贝启动脚本文件、并修改属性
cp support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
#### 修改启动脚本文件
vim /etc/init.d/mysqld
修改以下参数修("basedir"MySQL的安装程序目录;"datadir"MySQL数据存放目录,前面初始化数据库时定义的目录)
basedir=/usr/local/mysql
datadir=/data/mysql
1.4 start
The service item added to the system startup scripts, set the boot, and open the service
to add a service: chkconfig --add mysqld
setting boot: chkconfig mysqld on
Start MySQL:service mysqld start
If you can not start, please view the error log / data / mysql / down, this is usually the hostname .err log
Check whether the MySQL start:ps aux |grep mysqld
Two, Apache deployment installation
1. Apache Download
Apache official website to download the address: http: //httpd.apache.org/
Download Apache installer
cd /usr/local/src/
wget http://apache.fayea.com/httpd/httpd-2.4.37.tar.gz
Decompression:tar jvxf httpd-2.4.37.tar.bz2
2. compile and install
2.1 dependent libraries
yum install -y pcre pcre-devel apr apr-devel zlib-devel gcc
2.2 Configuring the Compile Options
cd httpd-2.4.37
./configure \
--prefix=/usr/local/httpd \
--with-included-apr \
--enable-so \
--enable-deflate=shared \
--enable-expires=shared \
--enable-rewrite=shared \
--with-pcre
--prefix
Specify the installation location;
--with-included-apr
the Apache httpd dependencies allow cross-platform operation;
--enable-so
represents enable DSO;
--enable-deflate=shared
representation Build shared deflate
, the latter parameter empathy;
--with-pcre
canonical correlation runtime.
Compile and install:make && make install
The above operation can be used to check whether echo $ correctly returns a value of "0" is normal;? Or need to solve the problem according to the error.
2.3 related error
Error:
configure: error: Bundled APR requested but not found at ./srclib/. Download and unpack the corresponding apr and apr-util packages to ./srclib/.
Solution:
cd /usr/local/src/httpd-2.4.37/srclib
#### 下载 apr
wget http://mirror.bit.edu.cn/apache/apr/apr-1.6.5.tar.gz
#### 解压、改名
tar -zxvf apr-1.6.5.tar.gz
mv apr-1.6.5 apr
#### 下载apr-util
wget http://mirror.bit.edu.cn/apache/apr/apr-util-1.6.1.tar.gz
#### 解压、改名
tar -zxvf apr-util-1.6.1.tar.gz
mv apr-util-1.6.1 apr-util
#### 参考网址:http://www.cnblogs.com/llius/p/5110628.html
3. Apache-related parameters
Apache module
/usr/local/apache/bin/apachectl -M
List the relevant module (-l lists the static module, -t check whether the file has a syntax error),Display module name (Shared) is a dynamic module, the display module name (static) static module;
Dynamic (Shared) file location module
/usr/local/apache/modules/
Dynamic module file for the green .so end of the module files (dynamic files are shared files)
such as:httpd.exp libphp5.so mod_deflate.so mod_expires.so mod_rewrite.so
Static (static) module compiled file location
/usr/local/apache/bin/httpd
4. Start Apache
Start: /usr/local/httpd/bin/apachectl start
restart: /usr/local/httpd/bin/apachectl restart
Stop: /usr/local/httpd/bin/apachectl stop
reload the configuration: /usr/local/httpd/bin/apachectl graceful
(reload the configuration, do not restart the process)
DSO: is an abbreviation Dynamic Shared Objects (dynamic shared objects), which provides a method of operating in a special format when the program code runs required, the necessary portion into memory from the external memory performed. Apache supports dynamic shared module, the module also supports static, static goal, then, we will need to be compiled directly into the executable file, apache, compared to dynamic, although eliminating the step of loading the shared module, but also increased the binary execution file space, becoming bloated.
Three, PHP installation deployment
1. Download php
PHP Official Download: http: //php.net/downloads.php
Download php installer
cd /usr/local/src
wget http://101.96.10.64/cn2.php.net/distributions/php-5.6.39.tar.gz
unpacked:tar zxf php-5.6.39.tar.gz
2. compile and install
2.1 dependent libraries
yum install -y libxml2-devel openssl openssl-devel bzip2 bzip2-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel
2.2 Configuring the Compile Options
cd php-5.6.39
./configure \
--prefix=/usr/local/php \
--with-apxs2=/usr/local/httpd/bin/apxs \
--with-config-file-path=/usr/local/php/etc \
--with-mysql=/usr/local/mysql \
--with-pdo-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-libxml-dir --with-gd --with-jpeg-dir \
--with-png-dir --with-freetype-dir \
--with-iconv-dir --with-zlib-dir \
--with-bz2 --with-openssl --with-mcrypt \
--enable-soap --enable-gd-native-ttf \
--enable-mbstring --enable-sockets --enable-exif
Compile and install:make && make install
2.3 related error
Error contents:configure: error: mcrypt.h not found. Please reinstall libmcrypt.
solve:
rpm -ivh "https://mirrors.tuna.tsinghua.edu.cn/epel/6/i386/epel-release-6-8.noarch.rpm"
yum install -y libmcrypt libmcrypt-devel
Because centos6.x default yum source does not libmcrypt-devel package, so the need to use third party yum source.
3. Profiles
PHP configuration file (the php.ini) in the
/usr/local/php/etc/
directory, the default configuration file is empty, the pre-configuration files need to copy the source file and then making configuration changes;- Pre-configuration file directory:
/usr/local/src/php-5.6.39
There are two pre-configuration files in this directory:- Developed using:
php.ini-development
- Is the production of use
php.ini-production
- Developed using:
Normal Web server using a direct copy:
php.ini-production
file namedphp.ini
cp /usr/local/src/php-5.6.39/php.ini-production /usr/local/php/etc/php.ini
Reload Apache after copy:
/usr/local/httpd/bin/apachectl graceful
Four, Apace combination of PHP, LAMP verification
1. Apache combined with PHP
- Edit the main Apache configuration file:
#### 修改主机名
#ServerName www.example.com:80 修改为:ServerName localhost:80
#### 添加PHP解析(AddType application/x-gzip .gz .tgz 在该行下面添加)
AddType application/x-httpd-php .php
#### 增加PHP默认页索引(增加index.php)
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
2. Test LAMP
Start Apache 2.1
Check the configuration file is correct:
/usr/local/httpd/bin/apachectl -t
If there are errors, continue to modify httpd.conf, if it is correct is displayed asSyntax OK
Start apache:
/usr/local/httpd/bin/apachectl start
Check whether to start:
netstat -lnp |grep httpd
If you have the following information is displayed, the successful start
tcp 0 0 :::80 :::* LISTEN 7667/httpd
2.2 Test WBE interface to parse
Use the curl command a simple test:
curl localhost
following words, configured correctly
<html><body><h1>It works!</h1></body></html>[root@CentOS-1 ~]#
Test whether the correct parse PHP, create the following PHP page content;
then use thecurl localhost/1.php
test; displayphp解析正常[root@localhost ~]#
configured correctly
#### 创建PHP页面
vim /usr/local/httpd/htdocs/1.php
#### PHP页面内容
<?php
echo "php解析正常";
?>
First use a browser to access our web service, you may not have access because of a firewall's sake. Run the following command:
[root@localhost ~]# iptables -F
This will clear the system default firewall rules, release 80 ports.
LAMP environment is set up well, this is actually just install the software, but rather the specific configuration still a lot of work to do it? That is, while you build up the environment, but if something does not configure the details, equivalent to no work experience, so it is still more than Configuration apache or php
V. Example: Installing Discuz forum
1. Download, install unzip
#### 创建安装目录
[root@CentOS-1 ~]#mkdir /data/www
[root@CentOS-1 ~]#cd /data/www
#### 下载Discuz安装程序包
[root@CentOS-1 www]#wget http://download.comsenz.com/DiscuzX/3.2/Discuz_X3.2_SC_GBK.zip
[root@CentOS-1 www]#upzip Discuz_X3.2_SC_GBK.zip
[root@CentOS-1 www]# mv upload/* ./
[root@CentOS-1 www]#rm -rf readme/ uploal/ utility/ Discuz_X3.2_SC_GBK.zip
编辑apache配置文件
[root@CentOS-1 www]# vim /usr/local/httpd/conf/httpd.conf
#### 启用(删除 # ) Include conf/extra/httpd-vhosts.conf
#### 修改配置参数
<Directory />
AllowOverride none
Require all denied #改为Require all granted
</Directory>
2. modify the configuration file
[root@CentOS-1 www]# vim /usr/local/httpd/conf/extra/httpd-vhosts.conf
#### 默认有两个样例,删除一个
<VirtualHost *:80>
ServerAdmin [email protected] #管理员邮箱,这里删除
DocumentRoot "/data/www" #创建的安装目录位置,这里修改成 /data/www
ServerName www.chenyue.com #域名地址
ServerAlias www.123qwe.com #别名(第二域名)
ErrorLog "logs/dummy-host.example.com-error_log" #错误日志
CustomLog "logs/dummy-host.example.com-access_log" common #访问日志(这里两个个日志线先用#注释掉,不用)
</VirtualHost>
#### 查看修改的配置是否有错误(Syntax OK 配置正确)
/usr/local/httpd/bin/apachectl -t
#### 启动、重新加载apache
/usr/local/httpd/bin/apachectl start
3. WEB installation interface
Browser access, www.chenyue.com / www.123qwe.com (premise need in the computer's host file, specify the domain name points to the server address)
Open your browser and follow the prompts to install, appear as shown prompt; editing the appropriate folder permissions to
Look at what user apache process
[root@CentOS-1 www]# ps aux |grep http
root 1444 0.0 1.5 30492 12096 ? Ss 21:49 0:00 /usr/local/apache/bin/httpd -k start
daemon 1511 0.0 1.3 30624 10312 ? S 22:05 0:00 /usr/local/apache/bin/httpd -k start
daemon 1512 0.0 1.4 31432 11160 ? S 22:05 0:00 /usr/local/apache/bin/httpd -k start
daemon 1513 0.0 1.3 30624 10312 ? S 22:05 0:00 /usr/local/apache/bin/httpd -k start
daemon 1514 0.0 1.4 31472 11224 ? S 22:05 0:00 /usr/local/apache/bin/httpd -k start
daemon 1515 0.0 1.3 30624 10312 ? S 22:05 0:00 /usr/local/apache/bin/httpd -k start
daemon 1516 0.0 1.2 30492 9784 ? S 22:05 0:00 /usr/local/apache/bin/httpd -k start
daemon 1517 0.0 1.2 30492 9784 ? S 22:05 0:00 /usr/local/apache/bin/httpd -k start
daemon 1518 0.0 1.2 30492 9784 ? S 22:05 0:00 /usr/local/apache/bin/httpd -k start
daemon 1519 0.0 1.2 30492 9784 ? S 22:05 0:00 /usr/local/apache/bin/httpd -k start
daemon 1520 0.0 1.2 30492 9784 ? S 22:05 0:00 /usr/local/apache/bin/httpd -k start
root 1522 0.0 0.0 5980 740 pts/0 S+ 22:27 0:00 grep http
Here is the daemon process apache user running; we need to figure above folder settings to prompt the user daemon (or modify folder permissions are possible, but the modified folder permissions greater insecurity; modify your master here)
[root@CentOS-1 www]# chown -R daemon config data uc_client/data uc_server/data
Refresh your browser, select a new installation
mysql configuration interface, let's not configured, the first server mysql configured in operation to the side;
Configuring Mysql
First set about Linux MySQL configuration commands mysql
(the original configuration command: /usr/local/mysql/bin/mysql
)
[root@CentOS-1 www]# which mysql //查看mysql绝对路径
/usr/bin/mysql //这里的mysql是系统自带的rpm包安装的
[root@CentOS-1 www]# rpm -qf /usr/bin/mysql //查看mysql安装包名
mysql-5.1.71-1.el6.i686
[root@CentOS-1 www]# yum remove mysql //卸载自带的mysql,自带与我们安装的会有冲突,
mysql被删除,配置的话;可以使用绝对路径/usr/local/mysql/bin/mysql
;
或重新指定mysql命令绝对路径,写一个path.sh文件
[root@CentOS-1 www]# vim /etc/profile.d/path.sh
#!/bin/bash
export PATH=$PATH:/usr/local/mysql/bin
~
~
~
[root@CentOS-1 www]# source /etc/profile.d/path.sh //或source !$
现在使用mysql
的配置文件,就是之前自己安装的mysql的配置
[root@CentOS-1 www]# which mysql
/usr/local/mysql/bin/mysql //现在的mysql的绝对路径,是之前自己安装的位置
创建一个库
[root@CentOS-1 www]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.1.73-log MySQL Community Server (GPL)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database discuz; //创建数据库的语句
Query OK, 1 row affected (0.00 sec)
mysql> grant all on discuz.* to 'discuz'@'localhost' identified by '1234qwer'; //创建用户名:discuz,密码:1234qwer
Query OK, 0 rows affected (0.00 sec)
mysql> Ctrl-C -- exit!
Aborted
WEB界面输入MySQL配置账户等信息,点击“下一步” 安装即可;