linux lamp 搭建 lamp搭建和配置

很多朋友对于linux lamp 搭建和lamp搭建和配置不太懂,今天就由小编来为大家分享,希望可以帮助到大家,下面一起来看看吧!

如何搭建lamp环境

1、确认搭建LAMP所需的环境是否已经安装:

[root@localhost~]#rpm-q make gcc gcc-c++ zlib-devel libtool libtool-ltdl libtool-ltdl-devel bisonncurses-devel

备注:安装libpng时需要zlib-devel

安装php时需要libtool、libtool-ltdl、libtool-ltdl-devel

安装mysql时需要bison、ncurses-devel

2、如果没安装则yum安装:

[root@localhost~]#yum-y install make gcc gcc-c++ zlib-devel libtool libtool-ltdllibtool-ltdl-devel bison ncurses-devel

3、由于要使用编译安装,所以查看httpd、mysql、php是否安装:

[root@localhost~]#rpm-q httpd mysql php

如果安装则卸载:

[root@localhost~]#rpm-e httpd--nodeps

[root@localhost~]#rpm-e mysql--nodeps

[root@localhost~]#rpm-e php--nodeps

编译安装过程介绍:

1)解压tar.gz为后缀的压缩软件包:LAMP环境搭建所需要的每个软件的软代码文件,都是以tar.gz或.tgz提供给我们的打包压缩文件,所以我们必须将其解压再解包。命令如下:

tar–zxvf*.tar.gz

2)在linux系统中源代码包安装过程:LAMP环境搭建所需要的软件都是使用C语言开发的,所以安装源代码文件最少需要配置、编译和安装三个步骤

配置(configure)、编译(make)、安装(makeinstall)

4、编译安装libxml2

[root@localhostlinux]# tar-zxvf libxml2-2.6.30.tar.gz

[root@localhostlinux]# cd libxml2-2.6.30

[root@localhostlibxml2-2.6.30]#./configure--prefix=/usr/local/libxml2

[root@localhostlibxml2-2.6.30]# make

[root@localhostlibxml2-2.6.30]# make install

5、编译安装libmcrypt

[root@localhostlinux]# tar-zxvf libmcrypt-2.5.8.tar.gz

[root@localhostlinux]# cd libmcrypt-2.5.8

[root@localhostlibmcrypt-2.5.8]#./configure--prefix=/usr/local/libmcrypt

[root@localhostlibmcrypt-2.5.8]# make

[root@localhostlibmcrypt-2.5.8]# make install

6、编译安装zlib

[root@localhostlinux]# tar-zxvf zlib-1.2.3.tar.gz

[root@localhostlinux]# cd zlib-1.2.3

[root@localhostzlib-1.2.3]# CFLAGS="-O3-fPIC"./configure--prefix=/usr/local/zlib/

(用64位元的方法进行编译)

[root@localhostzlib-1.2.3]# make

[root@localhostzlib-1.2.3]# make install

7、编译安装libpng

[root@localhostlinux]# tar-zxvf libpng-1.2.31.tar.gz

[root@localhostlinux]# cd libpng-1.2.31

[root@localhostlibpng-1.2.31]#./configure--prefix=/usr/local/libpng\

>--enable-shared(建立共享库使用的GNU的libtool)

[root@localhostlibpng-1.2.31]# make

[root@localhostlibpng-1.2.31]# make install

8、编译安装jpeg

[root@localhostlinux]# tar-zxvf jpegsrc.v6b.tar.gz

[root@localhostlinux]# cd jpeg-6b

[root@localhostjpeg-6b]# mkdir/usr/local/jpeg(创建jpeg软件的安装目录)

[root@localhostjpeg-6b]# mkdir/usr/local/jpeg/bin(创建存放命令的目录)

[root@localhostjpeg-6b]# mkdir/usr/local/jpeg/lib(创建jpeg库文件所在目录)

[root@localhostjpeg-6b]# mkdir/usr/local/jpeg/include(创建存放头文件目录)

[root@localhostjpeg-6b]# mkdir-p/usr/local/jpeg/man/man1(建立存放手册的目录)

[root@localhostjpeg-6b]#./configure--prefix=/usr/local/jpeg\

>--enable-shared\(建立共享库使用的GUN的libtool)

>--enable-static(建立静态库使用的GUN的libtool)

[root@localhostjpeg-6b]# make

[root@localhostjpeg-6b]# make install

执行make时如果出现如下错误:

./libtool--mode=compile gcc-O2-I.-c./jcapimin.c

make:./libtool: Command notfound

make:*** [jcapimin.lo] Error 127

解决方法:

默认已安装libtool及libtool-ltdl-devel(如需帮助请看过程2)

[root@localhostjpeg-6b]# find/-name config.sub

/usr/share/libtool/config/config.sub

[root@localhostjpeg-6b]# find/-name config.guess

/usr/share/libtool/config/config.guess

[root@localhostjpeg-6b]# cp-vRp/usr/share/libtool/config/config.sub.

[root@localhostjpeg-6b]# cp-vRp/usr/share/libtool/config/config.guess.

也就是把libtool里面的两个配置文件拿来覆盖掉jpeg-6b目录下的对应文件

make clean再重新configure

9、编译安装freetype

[root@localhostlinux]# tar-zxvf freetype-2.3.5.tar.gz

[root@localhostlinux]# cd freetype-2.3.5

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

>--enable-shared(建立共享库使用的GUN的libtool)

[root@localhostfreetype-2.3.5]# make

[root@localhostfreetype-2.3.5]# make install

10、编译安装autoconf

[root@localhostlinux]# tar-zxvf autoconf-2.61.tar.gz

[root@localhostlinux]# cd autoconf-2.61

[root@localhostautoconf-2.61]#./configure

[root@localhostautoconf-2.61]# make

[root@localhostautoconf-2.61]# make install

11、编译安装GD

[root@localhostlinux]# tar-zxvf gd-2.0.35.tar.gz

[root@localhostlinux]# cd gd-2.0.35

[root@localhostgd-2.0.35]#./configure--prefix=/usr/local/gd\

>--with-zlib=/usr/local/zlib/\(指定zlib库文件的位置)

>--with-jpeg=/usr/local/jpeg/\(指定jpeg库文件的位置)

>--with-png=/usr/local/libpng/\(指定png库文件的位置)

>--with-freetype=/usr/local/freetype/(指定freetype字体库的位置)

[root@localhostgd-2.0.35]# make

[root@localhostgd-2.0.35]# make install

执行make时如果出现如下错误:

make[2]:*** [gd_png.lo] Error 1

make[2]: Leaving directory`/usr/src/linux/gd-2.0.35'

make[1]:*** [all-recursive]Error 1

make[1]: Leaving directory`/usr/src/linux/gd-2.0.35'

make:*** [all] Error 2

解决方法:

[root@localhostgd-2.0.35]# find/-name gd_png.c

/usr/src/linux/gd-2.0.35/gd_png.c

[root@localhostgd-2.0.35]# find/-name png.h

/usr/local/libpng/include/png.h

[root@localhostgd-2.0.35]# vi/usr/src/linux/gd-2.0.35/gd_png.c

将#include"png.h"

改为#include"/usr/local/libpng/include/png.h"

12、编译安装apache

[root@localhostlinux]# tar-zxvf httpd-2.2.9.tar.gz

[root@localhostlinux]# cd httpd-2.2.9

[root@localhosthttpd-2.2.9]#./configure--prefix=/usr/local/apache\

>--enable-so\(以动态共享对象编译)

>--enable-rewrite(基于规则的URL操控)

[root@localhosthttpd-2.2.9]# make

[root@localhosthttpd-2.2.9]# make install

将apache加入开机启动↓

[root@localhosthttpd-2.2.9]# cp-vRp/usr/local/apache/bin/apachectl/etc/init.d/httpd

[root@localhosthttpd-2.2.9]# chmod+x/etc/init.d/httpd

添加apache服务↓

[root@localhosthttpd-2.2.9]# chkconfig--add httpd

[root@localhosthttpd-2.2.9]# chkconfig--level 2345 httpd on

[root@localhosthttpd-2.2.9]# service httpd start

启动服务时,如果出现如下错误:

httpd: Could not reliablydetermine the server's fully qualified domain name, using localhost.localdomainfor ServerName

解决方法:

[root@localhosthttpd-2.2.9]# vi/usr/local/apache/conf/httpd.conf

添加上:ServerName localhost:80

执行chkconfig时,如果出现如下错误:

service httpd does not supportchkconfig

解决方法:

[root@localhosthttpd-2.2.9]# vi/etc/rc.d/init.d/httpd

在文件第二行加入

#chkconfig:2345 10 90

#description:Activates/DeactivatesApache Web Server

保存后再执行chkconfig

13、编译安装mysql(最新版本都需要cmake编译安装)

编译安装 cmake

[root@localhostlinux]# tar-zxvf cmake-2.8.7.tar.gz

[root@localhostlinux]# cd cmake-2.8.7

[root@localhostcmake-2.8.7]#./bootstrap

[root@localhostcmake-2.8.7]# gmake

[root@localhostcmake-2.8.7]# gmake install

编译安装 MySQL5.5.20

[root@localhostcmake-2.8.7]# groupadd mysql

[root@localhostcmake-2.8.7]# useradd-g mysql mysql

[root@localhostlinux]# tar-zxvf mysql-5.5.15.tar.gz

[root@localhostlinux]# cd mysql-5.5.15

[root@localhostmysql-5.5.15]#

cmake-DCMAKE_INSTALL_PREFIX=/usr/local/mysql\(安装根目录)

>-DMYSQL_UNIX_ADDR=/usr/local/mysql/data/mysql.sock\(UNIX socket文件)

>-DDEFAULT_CHARSET=utf8\(默认字符集)

>-DDEFAULT_COLLATION=utf8_general_ci\(默认编码)

>-DWITH_EXTRA_CHARSETS=utf8,gbk\(额外的编码)

>-DWITH_PERFSCHEMA_STORAGE_ENGINE=1\(启用PERFSCHEMA引擎支持)

>-DWITH_FEDERATED_STORAGE_ENGINE=1\(启用FEDERATED引擎支持)

>-DWITH_PARTITION_STORAGE_ENGINE=1\(启用PARTITION引擎支持)

>-DWITH_ARCHIVE_STORAGE_ENGINE=1\(启用ARCHIVE引擎支持)

>-DWITH_READLINE=1\(使用readline功能)

>-DMYSQL_DATADIR=/usr/local/mysql/data\(数据库数据目录)

>-DMYSQL_TCP_PORT=3306(TCP/IP端口)

[root@localhostmysql-5.5.15]# make

[root@localhostmysql-5.5.15]# make install

[root@localhostmysql-5.5.15]# cp-vRp/usr/local/mysql/support-files/my-medium.cnf/etc/my.cnf

修改配置文件↓

[root@localhostmysql-5.5.15]# vi/etc/my.cnf

basedir=/usr/local/mysql

datadir=/usr/local/mysql/data

log-error=/usr/local/mysql/data/error.log

pid-file=/usr/local/mysql/data/mysql.pid

初始化数据库文件↓

[root@localhostmysql-5.5.15]#/usr/local/mysql/scripts/mysql_install_db\

>--defaults-flie=/etc/my.cnf\

>--basedir=/usr/local/mysql/\

>--datadir=/usr/local/mysql/data\

>--pid-file=/usr/local/mysql/data/mysql.pid\

>--user=mysql

权限设置↓

[root@localhostmysql]# chown-R root.

[root@localhostmysql]# chown-R mysql data

[root@localhostmysql]# chgrp-R mysql.

将mysql加入开机启动↓

[root@localhostmysql]# cp-vRp support-files/mysql.server/etc/init.d/mysqld

[root@localhostmysql]# chmod+x/etc/init.d/mysqld

添加mysql服务↓

[root@localhostmysql]# chkconfig--add mysqld

[root@localhostmysql]# chkconfig--level 345 mysqld on

[root@localhostmysql]# service mysqld start

配置mysql↓

[root@localhostmysql]# bin/mysql

mysql> deletefrom mysql.user where Host!='localhost';(只留允许本机登录的帐号)

mysql> flushprivileges;(刷新授权表)

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

mysql> exit

[root@localhostmysql]# bin/mysql-h localhost-u root-p123456(登录mysql)

14、编译安装php

[root@localhostlinux]# tar-zxvf php-5.3.19.tar.gz

[root@localhostlinux]# cd php-5.3.19

[root@localhostphp-5.3.19]#./configure--prefix=/usr/local/php\

>--with-apxs2=/usr/local/apache/bin/apxs\

>--with-mysql=/usr/local/mysql/\

>--with-libxml-dir=/usr/local/libxml2/\

>--with-png-dir=/usr/local/libpng/\

>--with-jpeg-dir=/usr/local/jpeg/\

>--with-freetype-dir=/usr/local/freetype/\

>--with-gd=/usr/local/gd/\

>--with-mcrypt=/usr/local/libmcrypt/\

>--with-mysqli=/usr/local/mysql/bin/mysql_config\

>--enable-soap\(变量激活SOAP和web services支持)

>--enable-mbstring=all\(使多字节字符串支持)

>--enable-sockets(变量激活socket通讯特性)

[root@localhostphp-5.3.19]# make

[root@localhostphp-5.3.19]# make install

[root@localhostphp-5.3.19]# cp-vRp php.ini-development/etc/php.ini

[root@localhostphp-5.3.19]# vi/usr/local/apache/conf/httpd.conf

添加上:

AddType application/x-httpd-php.php

[root@localhostphp-5.3.19]# service httpd stop

[root@localhostphp-5.3.19]# service httpd start

[root@localhostphp-5.3.19]# vi/usr/local/apache/htdocs/phpinfo.php

添加内容为:

<?php

phpinfo();

?>

打开浏览器进行访问,如果出现PHP版本界面,及安装成功。

如何在windows上搭建LAMP环境

Linux+Apache+Mysql+Perl/PHP/Python是目前最流行的开源web组件。

1、下载Xampp For Windows的安装包,点击安装,这个时候,会弹出几个安全提示,点击“OK”继续,

2、进入到Xampp安装步骤,点击“Next”,

3、这一步时让选择需要安装的组件,可以根据需要进行勾选。

4、输入Xampp的安装路径。

5、Xampp的最新安装包有集成Wordpress等流行的开源软件,如果有需要的话,可以勾选这个选项。

6、开始进入到Xampp的安装过程,期间不要关闭弹出来的窗口,至此,全部安装结束。

7、打开Xampp的面板,选择启动Apache服务,点击后面的“start”按钮就可以了。

8、此时可能提示防火墙的警告,选择“允许访问网络”。

10、当然如果web端口80或443被其他应用程序占用时,在下方会输出相应的错误信息,就可以很快找到占用的程序。

11、启动成功后,在浏览器内输入这时Xampp的安装已经没有问题了

如果需要放入我们的程序,可以进入到Xampp的安装目录下的htdocs的文件夹,放入web项目,例如,在htdocs目录下新建一个test目录,例如放入一个index.php文件,输入一些内容

<?php

echo"Hello XAMPP!!!!";

?>

12、此时,在浏览器访问,看到下面的页面说明PHP组件安装也没有问题,同样,如果需要测试Mysql环境的话,可以进入里创建数据库和表,然后写代码进行验证。

如何搭建lamp(CentOS7+Apache+MySQL+PHP)环境

在网上搜资料,自己在本地虚拟机上尝试搭建,弄了整整一天一夜,终于弄好了.网上的资料,虽然很多,但大多都是重复的,拿去试了之后,又很多都不能得到正确的结果.最终找到了适合我的linux环境的搭建方式;在这里贴出来:度娘真不给力啊,没搜出来靠谱的方法。最后用喜乐搜找到的靠谱的教程。

这里还是要总结一下我的LAMP环境的搭建步骤。我先在电脑里装了虚拟机,在虚拟机中测试了数次之后,再在服务器上搭建的。说说我的环境:虚拟机是:VMware® Workstation 12.1.1 Pro;Linux系统用的是:CentOS-7-x86_64-DVD-1511.iso;(阿里云上也是用的CentOS7-64bit)准备好这两个之后,就开始一步一步搭建我们的LAMP环境了。

一、安装虚拟机

二、安装CentOS7

注意:以下安装,我都是用的root权限。

三、安装Apache1.安装yum-y install httpd2.开启apache服务systemctl start httpd.service3.设置apache服务开机启动systemctl enable httpd.service4.验证apache服务是否安装成功在本机浏览器中输入虚拟机的ip地址,CentOS7查看ip地址的方式为:ip addr(阿里云不需要用这种方式查看,外网ip已经在你主机列表那里给你写出来了的;)这里是访问不成功的(阿里云用外网访问,能成功,不需要做以下步骤)查了资料,说法是,CentOS7用的是Firewall-cmd,CentOS7之前用的是iptables防火墙;要想让外网能访问到apache主目录,就需要做以下的操作:firewall-cmd--permanent--zone=public--add-service=httpfirewall-cmd--permanent--zone=public--add-service=httpsfirewall-cmd--reload然后再访问外网ip,如果看到apache默认的页面--有Testing 123...字样,便是成功安装了apache服务了;

四、安装PHP1.安装yum-y install php2.重启apache服务systemctl restart httpd或者systemctl restart httpd.service然后,你可以写一个php文件在浏览器中运行一下了;eg:vi/var/www/html/info.phpi<?php phpinfo();?>Esc:wq然后,在自己电脑浏览器输入 192.168.1.1/info.php运行,会出现php的一些信息

五、安装MySQL我这里根据所学的那个教程,也安装了MariaDB1.安装

yum-y install mariadb*

2.开启MySQL服务systemctl start mariadb.service3.设置开机启动MySQL服务systemctl enable mariadb.service4.设置root帐户的密码mysql_secure_installation然后会出现一串东西,可以仔细读一下,如果你懒得读,就在提示出来的时候,按Enter就好了,让你设置密码的时候,你就输入你想要的密码就行,然后继续在让你选择y/n是,Enter就好了;当一切结束的时候,你可以输入mysql-uroot-p的方式,验证一下;

六、将PHP和MySQL关联起来yum search php,选择你需要的安装:yum-y install php-mysql

七、安装常用的PHP模块例如,GD库,curl,mbstring,...1.安装:yum-y install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel2.重启apache服务systemctl restart httpd.service然后,再次在浏览器中运行info.php,你会看到安装的模块的信息;

至此,LAMP环境就搭建好了。

如何搭建lamp(CentOS7+Apache+MySQL+PHP)环境

标签:

阅读剩余
THE END