1232121 发表于 2016-5-9 10:53:12

搭建lnmp环境

本次实验中搭建lnmp环境所使用的软件下载http://链接:http://pan.baidu.com/s/1hsCqI5u 密码:ndsy

1:首先要安装的mysql:一般我们把下载的安装包放在/usr/local/src下面:
    首先解压安装包:

1
# tar zvxf mysql-5.1.73-linux-i686-glibc23.tar.gz




    把解压后的文件移至/usr/local/下:

1
# mv mysql-5.1.73-linux-i686-glibc23 /usr/local/mysql




    建立mysql用户,但是用户不能在终端登录(不创建家目录):

1
# useradd -s /sbin/nologin -M mysql




   创建数据库文件并且,修改数据库文件权限为mysql!

1
2
3
# cd /usr/local/mysql/
# mkdir -p /data/mysql
# chown -R mysql:mysql /data/mysql




    初始化数据库:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
WARNING: The host 'master' could not be looked up with resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MySQL version. The MySQL daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MySQL privileges !
Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

./bin/mysqladmin -u root password 'new-password'
./bin/mysqladmin -u root -h master password 'new-password'

Alternatively you can run:
./bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd . ; ./bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd ./mysql-test ; perl mysql-test-run.pl

Please report any problems with the ./bin/mysqlbug script!   

/出现两个ok说明,初始化完成!




    拷贝配置文件,如果配置文件已经存在,直接覆盖即可:

1
2
# cp support-files/my-large.cnf /etc/my.cnf
cp: overwrite `/etc/my.cnf'? y




    拷贝启动脚本,并且修改启动脚步文件权限为755

1
2
3
# cp support-files/mysql.server /etc/init.d/mysqld
# chmod 755 !$
chmod 755 /etc/init.d/mysqld




    修改启动脚步,把启动脚本中的“datadir=”修改为“datedir = /data/mysql”


1
# vim /etc/init.d/mysqld




    加入开机启动:

1
2
3
4
5
# chkconfig --list |grep mysqld
# chkconfig --add mysqld
# chkconfig --list |grep mysqld
mysqld             0:off   1:off   2:on    3:on    4:on    5:on    6:off
# chkconfig mysqld on




    启动mysql:

1
2
3
# service mysqld start
Starting MySQL.                                          
# ps aux |grep mysqld





    安装apache:
    首先解压:


1
# tar zxvf httpd-2.2.31.tar.gz




    配置编译参数:


1
2
3
4
5
6
7
8
9
# cd httpd-2.2.31
# ./configure\
> --prefix=/usr/local/apache2\
> --with-included-apr\
> --enable-so\
> --enable-deflate=shared\
> --enable-expires=shared\
> --enable-rewrite=shared\
> --with-pcre




    上一步编译可能会发生如下错误(如果系统是最小化安装,就会出错)

1
2
3
4
5
6
configure: error: in `/usr/local/src/httpd-2.2.31/srclib/apr':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details

解决办法:
# yum install -y gcc




    接下来是编译和安装,在进行这一步之前,首先安装几个包:


1
# yum install -y pcre pcre-devel apr apr-devel




    然后在进行:

1
2
# make
# make install




上述两个步骤都可以特殊变量"echo $?"查看返回值是否为0,来确定上一步只执行是否正确。

    安装php:

1
# tar jxvf php-5.4.45.tar.bz2




    编译:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# cd php-5.4.45
#./configure \
> --prefix=/usr/local/php \
> --with-apxs2=/usr/local/apache2/bin/apxs \
> --with-config-file-path=/usr/local/php/etc\
> --with-mysql=/usr/local/mysql \
> --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 \
> --disable-ipv6




    编译这一步会出现许多错误,这些错误只是因为某些包缺少的缘故,安装上即可:这一步需要安装的包如下:

1
yum install -y libxml2-devel openssl openssl-devel bzip2 bzip2-devel libpng libpng-devel freetype freetype-devel libjpeg-devel




    安装epel源:

1
2
yum install -y epel-release
yum install -y libmcrypt-devel




    然后运行make && make install 来完成安装:
拷贝配置文件:

1
# cp php.ini-production /usr/local/php/etc/php.ini




    至此一个lnmp的环境搭建完成,然后就是修改参数,使其能够解析php!
页: [1]
查看完整版本: 搭建lnmp环境