linux- Lamp搭建记录

Lamp搭建记录

准备工作

安装编译环境:

yum -y install gcc*

安装好后记得关闭防火墙和selinux

准备软件包


把这些安装包都放入虚拟机自定义的路径,等待使用。

shell脚本批量解包

#!/bin/bash
/bin/ls *tar.gz > ls.list
/bin/ls *tgz >> ls.list
for a in `cat ls.list`
do
        /bin/tar -zxf $a
done
rm -rf ls.list


然后开始一一的装包,注意需要按照一定的顺序来装的。

python-devel

yum -y install python-devel

安装python的底层环境。

[root@localhost lamp1]# cd libxml2-2.9.1/
[root@localhost libxml2-2.9.1]# ./configure --prefix=/usr/local/libxml2/
[root@localhost libxml2-2.9.1]# make
[root@localhost libxml2-2.9.1]# make install

libmcrypt

提供一些加密算法:

[root@localhost lamp1]# cd libmcrypt-2.5.8/
[root@localhost libmcrypt-2.5.8]# ./configure --prefix=/usr/local/libmcrypt/
[root@localhost libmcrypt-2.5.8]# make
[root@localhost libmcrypt-2.5.8]# make install

libltdl

[root@localhost lamp1]# cd libmcrypt-2.5.8/libltdl/
[root@localhost libltdl]# ./configure --enable-ltdl-install
[root@localhost libltdl]# make
[root@localhost libltdl]# make install

mhash

提供加密方式的扩展

[root@localhost lamp1]# cd mhash-0.9.9.9/
[root@localhost mhash-0.9.9.9]# ./configure

mcrypt

提供php相关的加密支持拓展库

[root@localhost mcrypt-2.6.8]# LD_LIBRARY_PATH=/usr/local/libmcrypt/lib:/usr/local/lib \./configure --with-libmcrypt-prefix=/usr/local/libmcrypt
[root@localhost mcrypt-2.6.8]# make
[root@localhost mcrypt-2.6.8]# make install

zlib

提供压缩用途的函数库

[roott@localhost lamp1]# cd zlib-1.2.3/
[root@localhost zlib-1.2.3]# ./configure
[root@localhost zlib-1.2.3]# make
[root@localhost zlib-1.2.3]# make install

libpng

[root@localhost zlib-1.2.3]# cd ../
[root@localhost lamp1]# cd libpng-1.2.31/
[root@localhost libpng-1.2.31]# ./configure --prefix=/usr/local/libpng
[root@localhost libpng-1.2.31]# make 
[root@localhost libpng-1.2.31]# make install

如果出现:

/usr/bin/ld: //usr/local/lib/libz.a(crc32.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC

解决办法 :

[root@localhost lamp1]# cd zlib-1.2.3 //进入zlib目录
[root@localhost zlib-1.2.3]# ./configure

[root@localhost zlib-1.2.3]# CFLAGS="-O3 -fPIC" ./configure   --prefix=/usr/local/zlib/ #使用64位元的方法进行编译

[root@localhost zlib-1.2.3]# make

[root@localhost zlib-1.2.3]# make install

[root@localhost zlib-1.2.3]# make clean

然后在重新来安装libpng即可。

jpeg6

提供jpeg格式的图片

[root@localhost libpng-1.2.31]# mkdir /usr/local/jpeg6
[root@localhost libpng-1.2.31]# mkdir /usr/local/jpeg6/bin
[root@localhost libpng-1.2.31]# mkdir /usr/local/jpeg6/lib
[root@localhost libpng-1.2.31]# mkdir /usr/local/jpeg6/include
[root@localhost libpng-1.2.31]# mkdir -p /usr/local/jpeg6/man/man1
root@localhost lamp]# cd jpeg-6b/
[root@localhost jpeg-6b]# ./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static

如果发生这样的报错:

[root@localhost jpeg-6b]# make
./libtool --mode=compile gcc -O2  -I. -c ./jcapimin.c
make: ./libtool:命令未找到
make: *** [jcapimin.lo] 错误 127

需要:

[root@localhost jpeg-6b]# yum -y install libtool
[root@localhost jpeg-6b]# cp /usr/share/libtool/config/config.guess .
cp:是否覆盖"./config.guess"? yes
[root@localhost jpeg-6b]# make clean

重新再来就好。

freetype

字体库。

[root@localhost freetype-2.3.5]# ./configure --prefix=/usr/local/freetype

GD

给php提供图形拓展的库

[root@localhost lamp]# mkdir /usr/local/gd2
[root@localhost lamp]# cd /usr/src/lamp/gd-2.0.35/
[root@localhost gd-2.0.35]# ./configure --prefix=/usr/local/gd2/ --with-jpeg=/usr/local/jpeg6/ --with-freetype=/usr/local/freetype/ --with-png=/usr/local/libpng/

这样会爆一个错,然后需要改一下源码:

[root@localhost gd-2.0.35]# vim gd_png.c


需要指定一下路径即可,这个刚刚是已经安装过的。

httped

先装两个工具包:

cp -r apr-1.4.6 httpd-2.4.7/srclib/apr

cp -r apr-util-1.4.1 httpd-2.4.7/srclib/apr-util

开始装httped:

先进入装一下pcre:

./configure
make
make install

进入httped:
先对配置进行设置:

./configure --prefix=/usr/local/apache2/ --sysconfdir=/usr/local/apache2/etc --with-include-apr --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared
make
make install

开服务:

/usr/local/apache2/bin/apachectl start

自启动

[root@localhost httpd-2.4.7]# vim /etc/rc.d/rc.local

设置开机时自动启动这个服务。

mysql

准备工作

装两个工具:

[root@localhost local]# yum -y install cmake
[root@localhost local]# yum -y install bison
[root@localhost local]# yum -y install ncurses-devel

建立一个用户:

[root@localhost local]# useradd mysql
[root@localhost local]# id mysql
uid=1001(mysql) gid=1001(mysql) 组=1001(mysql)

安装ncurses:

[root@localhost ncurses-5.9]# ./configure --with-shared --without-debug --with-ada --enable-overwrite
[root@localhost ncurses-5.9]# make
[root@localhost ncurses-5.9]# make install

开始安装


[root@localhost mysql-5.5.23]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
> -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DEXTRA_CHARSET=all -DDEFAULT_CHARSET=utf8 \
> -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 \
> -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 \
> -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_USER=mysql \
> -DMYSQL_TCP_PORT=3306

[root@localhost  mysql-5.5.23]# make
[root@localhost  mysql-5.5.23]# make install

简单设置

初始化mysql:

[root@localhost mysql]# chown -R mysql:mysql .
[root@localhost mysql]# /usr/local/mysql/scripts/mysql_install_db --user=mysql


设置权限:

[root@localhost mysql]# chown -R root .
[root@localhost mysql]# chown -R mysql data/

覆盖一下配置文件:

[root@localhost mysql]# cp support-files/my-medium.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? yes

接着初始化:

[root@localhost mysql]# /usr/local/mysql/bin/mysqld_safe --user=mysql
200408 03:38:45 mysqld_safe Logging to '/usr/local/mysql/data/localhost.localdomain.err'.
200408 03:38:45 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
200408 03:38:47 mysqld_safe mysqld from pid file /usr/local/mysql/data/localhost.localdomain.pid ended

[root@localhost mysql]# /usr/local/mysql/scripts/mysql_install_db --user=mysql
[root@localhost mysql]# /usr/local/mysql/bin/mysqld_safe --user=mysql

发现卡死了:

[root@localhost mysql-5.5.23]# ps aux | grep mysql

[root@localhost mysql-5.5.23]# kill -9 102872
[root@localhost mysql-5.5.23]# ps aux | grep mysql
mysql    103111  0.0  4.9 727288 49260 pts/3    Sl   03:39   0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/localhost.localdomain.err --pid-file=/usr/local/mysql/data/localhost.localdomain.pid --socket=/tmp/mysql.sock --port=3306
root     103201  0.0  0.0 112728   972 pts/2    S+   03:46   0:00 grep --color=auto mysql

杀掉重新来。

[root@localhost mysql]# /usr/local/mysql/scripts/mysql_install_db --user=mysql
[root@localhost mysql]# /usr/local/mysql/bin/mysqld_safe --user=mysql


成功了。

自启动

[root@localhost mysql-5.5.23]# vim /etc/rc.d/rc.local

设置mysql密码

[root@localhost mysql-5.5.23]# /usr/local/mysql/bin/mysqladmin -u root password "123456"
[root@localhost mysql-5.5.23]# /usr/local/mysql/bin/mysql -u root -p


成功了。注意 history -c 清楚历史记录命令。

服务都正常,字符集格式也在。

php

准备工作

[root@localhost mysql]# yum -y install libtool*
[root@localhost local]# yum -y install libpng-devel

让php支持数据库的内容:

[root@localhost mysql]# vim /usr/local/gd2/include/gd_io.h

开始安装

[root@localhost php-5.4.25]# ./configure --prefix=/usr/local/php/ --with-config-file-path=/usr/local/php/etc/ --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql --with-libxml-dir=/usr/local/libxml2 --with-jpeg-dir=/usr/local/jpeg6/ --with-png-dir=/usr/local/libpng/ --with-freetype-dir=/usr/local/freetype/ --with-gd=/usr/local/gd2/ --with-mcrypt=/usr/local/libmcrypt/ --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-soap --enable-mbstring=all --enable-sockets --with-pdo-mysql=/usr/local/mysql --without-pear

[root@localhost php-5.4.25]# make

[root@localhost php-5.4.25]# make install

配置

[root@localhost php-5.4.25]# mkdir /usr/local/php/etc
[root@localhost php-5.4.25]# cp php.ini-production /usr/local/php/etc/php.ini

复制主配置文件到/usr/local/php/etc

[root@localhost php-5.4.25]# vi /usr/local/apache2/etc/httpd.conf


修改apache2配置,让其也可以支持php

重启apache2:

[root@localhost php-5.4.25]# /usr/local/apache2/bin/apachectl stop
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
[root@localhost php-5.4.25]# /usr/local/apache2/bin/apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message

restart 可能是无效的。

验证

apache与php

[root@localhost htdocs]# vi index.php

写一个php探针:

<?php
        phpinfo();
?>

apache与MySQL

<?php
$link=mysql_connect('localhost','root','123456');
if($link) echo "Congratulations!!!!!!";
mysql_close();
?>

phpadmin搭建

[root@localhost lamp1]# cp -r phpMyAdmin-4.1.4-all-languages /usr/local/apache2/htdocs/phpmyadmin

配置文件

[root@localhost phpmyadmin]# cp config.sample.inc.php config.inc.php
[root@localhost phpmyadmin]# vi config.inc.php


访问测试:


本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!