linux单机LAMP环境搭建-成都快上网建站

linux单机LAMP环境搭建

LAMP单机环境搭建

十多年的绛县网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。网络营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整绛县建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联公司从事“绛县网站设计”,“绛县网站推广”以来,每个客户项目都认真落实执行。

一.系统环境准备。

1.系统环境:CentOS_6.5,32位

[root@localhost ~]# cat /etc/redhat-release      

CentOS release 6.5 (Final)

[root@localhost ~]# uname -r

2.6.32-431.el6.i686

2.软件版本

httpd-2.2.31

MySQL-5.1.72

php-5.5.32

3.关闭防火墙iptables和selinux

3.1关闭防火墙iptables

[root@localhost tools]# chkconfig --level 2345iptables off

[root@localhost tools]# chkconfig --listiptables

iptables       0:off   1:off   2:off  3:off   4:off   5:off  6:off

[root@localhost tools]# service iptables stop

[root@localhost tools]# service iptablesstatus

iptables: Firewall is not running.

3.2关闭selinux

[root@localhost tools]# vim/etc/selinux/config        #修改配置如下图所示

linux单机LAMP环境搭建

4.新建软件管理文件夹及上传相关软件

4.1创建软件管理文件夹

[root@localhost tools]# mkdir -p/home/jeff/tools/

[root@localhost tools]# ll /home/jeff/

total 4

drwxr-xr-x. 5 root root 4096 May 16 10:16tools

4.2上传相关软件

[root@localhost /]# cd /home/jeff/tools/

利用rz命令上传相关软件。如果无法使用该命令,请安装lrzsz软件。

二.安装相关软件

1.安装apache软件

1.1解压apache

root@localhost tools]# tar -zxvf httpd-2.2.31.tar.gz

[root@localhost tools]# ll

total 63248

-rw-r--r-- 1 root root 10364427 Feb 22 14:51 Discuz_X3.1_SC_GBK.zip

drwxr-xr-x 11 1000 1000     4096 Jul 16  2015 httpd-2.2.31

-rw-r--r--  1 root root 7583841 May 16 10:11 httpd-2.2.31.tar.gz

-rw-r--r-- 1 root root  4984397 Feb 22 13:52libiconv-1.14.tar.gz

-rw-r--r-- 1 root root 24044338 Feb 22 10:47 mysql-5.1.72.tar.gz

-rw-r--r-- 1 root root 17773092 Feb 22 11:22 php-5.5.32.tar.gz

1.2进入apache软件目录并进行配置(安装请先安装apr、apr-util、prce、gcc gcc-c++)

[root@localhost tools]# cd httpd-2.2.31

[root@localhost httpd-2.2.31]#./configure \

--prefix=/usr/local/apache2.2.31 \

--with-apr=/usr/local/apr \

--with-apr-util=/usr/local/apr-util \

--with-pcre=/usr/local/pcre \

--enable-deflate \

--enable-expires \

--enable-headers \

--enable-modules=most \

--enable-so \

--with-mpm=worker \

--enable-rewrite

1.3编译安装

[root@localhost httpd-2.2.31]# make & makeinstall

1.4启动及检查apache安装情况

1.4.1启动apache

[root@localhost bin]# ./apachectl start       #启动apache

httpd: Could not reliably determine theserver's fully qualified domain name, using ::1 for ServerName

1.4.2检查apache启动情况

[root@localhost bin]# ps -ef | grep http*     #查看apache进程

root    17464     1  0 11:45 ?        00:00:00/usr/local/apache2.2.31/bin/httpd -k start

daemon  17465 17464  0 11:45 ?        00:00:00/usr/local/apache2.2.31/bin/httpd -k start

daemon  17466 17464  0 11:45 ?        00:00:00/usr/local/apache2.2.31/bin/httpd -k start

daemon  17467 17464  0 11:45 ?        00:00:00/usr/local/apache2.2.31/bin/httpd -k start

daemon  17468 17464  0 11:45 ?        00:00:00 /usr/local/apache2.2.31/bin/httpd-k start

root    17552  3284  0 11:45 pts/1    00:00:00 grep httpd

[root@localhost bin]# netstat -lntp | grep 80   #查看apache监听端口

tcp       0      0 :::80                       :::*                        LISTEN      17464/httpd

用浏览器检查:

http://localhost,如出现如下页面,则说明apache安装成功。

linux单机LAMP环境搭建

2.安装mysql软件

2.1解压mysql

[root@localhost tools]# tar -zxvfmysql-5.1.72.tar.gz

[root@localhost tools]# ll

total 67372

drwxr-xr-x 12 1000  1000    4096 May 16 11:42 httpd-2.2.31

-rw-r--r-- 1 root root   7583841 May 16 10:11httpd-2.2.31.tar.gz

drwxrwxrwx 32 7155 wheel     4096 Sep 10  2013 mysql-5.1.72

-rw-r--r-- 1 root root  24044338 Feb 22 10:47mysql-5.1.72.tar.gz

-rw-r--r-- 1 root root  17773092 Feb 22 11:22php-5.5.32.tar.gz

2.2建立mysql相应的用户的用户组

[root@localhost mysql-5.1.72]# groupadd -g 800mysql         #创建mysql用户组

[root@localhost mysql-5.1.72]# useradd -gmysql -u 800 -M -s /sbin/nologin mysql       #创建mysql用户

[root@localhost mysql-5.1.72]# cat /etc/group| grep mysql      #检查mysql组创建情况

mysql:x:800:

[root@localhost mysql-5.1.72]# cat /etc/passwd| grep mysql    #检查mysql用户创建情况

mysql:x:800:800::/home/mysql:/sbin/nologin

#-s /sbin/nologin表示禁止该用户登录,加强安全。

#-g mysql指定属于mysql组。

#-M表示不创建用户家目录。

2.3进入mysql软件目录并进行编译安装

2.3.1进入mysql软件目录

[root@localhost tools]# cd mysql-5.1.72                #进入mysql安装目录

2.3.2配置mysql(配置前安装ncurses-devel先)

[root@localhost mysql-5.1.72]#./configure \

--prefix=/usr/local/mysql5.1.72 \

--with-unix-socket-path=/usr/local/mysql5.1.72/tmp/mysql.sock\

--localstatedir=/usr/local/mysql5.1.72/data \

--enable-assembler \

--enable-thread-safe-client \

--with-mysqld-user=mysql \

--with-big-tables \

--without-debug \

--with-pthread \

--enable-assembler \

--with-extra-charsets=complex \

--with-readline \

--with-ssl \

--with-embedded-server \

--enable-local-infile \

--with-plugins=partition,innobase \

--with-plugin-PLUGIN \

--with-mysqld-ldflags=-all-static \

--with-client-ldflags=-all-static

2.3.3编译安装

[root@localhost mysql-5.1.72] #make & makeinstall

2.4获取mysql配置文件

[root@localhost mysql-5.1.72]# cdsupport-files

[root@localhost support-files]# cp -amy-small.cnf /etc/my.cnf

2.5创建软连接,方便维护及升级

[root@localhost local]# ln -s /usr/local/mysql5.1.72//usr/local/mysql

2.6创建mysql数据库文件

[root@localhost local]# mkdir -p/usr/local/mysql/data          #建立mysql数据文件目录

[root@localhost local]# chown -R mysql:mysql/usr/local/mysql5.1.72 #授权mysql用户访问mysql的安装目录

[root@localhost local]#/usr/local/mysql/bin/mysql_install_db --user=mysql  #安装mysql数据库文件

2.7启动mysql数据库

[root@localhost bin]# cp /home/jeff/tools/mysql-5.1.72/support-files/mysql.server/usr/local/mysql/bin/

#拷贝mysql启动脚本到mysql的命令路径

[root@localhost bin]# chmod 700/usr/local/mysql/bin/mysql.server    #使脚本可执行

[root@localhost bin]#/usr/local/mysql/bin/mysql.server start         #启动数据库

Starting MySQL. SUCCESS!

2.8检查mysql数据库启动情况

[root@localhost bin]# netstat -lnt | grep 3306         #检查mysql监听端口

tcp       0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN 

[root@localhost bin]# ps -ef | grep"mysql*"            #检查mysql进程

root     3085     1  0 14:43 pts/3    00:00:00 /bin/sh/usr/local/mysql5.1.72/bin/mysqld_safe --datadir=/usr/local/mysql5.1.72/data--pid-file=/usr/local/mysql5.1.72/data/localhost.pid

mysql    3200  3085  0 14:43 pts/3    00:00:00 /usr/local/mysql5.1.72/libexec/mysqld--basedir=/usr/local/mysql5.1.72 --datadir=/usr/local/mysql5.1.72/data--user=mysql --log-error=/usr/local/mysql5.1.72/data/localhost.err--pid-file=/usr/local/mysql5.1.72/data/localhost.pid --socket=/usr/local/mysql5.1.72/tmp/mysql.sock--port=3306

root     3239 18040  0 14:47 pts/3    00:00:00 grep mysql*

[root@localhost bin]#/usr/local/mysql/bin/mysql -uroot          #进入mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.1.72 Source distribution

Copyright (c) 2000, 2013, Oracle and/or itsaffiliates. All rights reserved.

Oracle is a registered trademark of OracleCorporation and/or its

affiliates. Other names may be trademarks oftheir respective

owners.

Type 'help;' or '\h' for help. Type '\c' toclear the current input statement.

mysql>

2.9配置mysql命令的全局路径

[root@localhost bin]# echo 'exportPATH=$PATH:/usr/local/mysql/bin' >> /etc/profile  

[root@localhost bin]# tail -1 /etc/profile            #检查

export PATH=$PATH:/usr/local/mysql/bin

source /etc/profile    #使生效

2.10配置/etc/init.d/mysqldstart 方式启动数据库

[root@localhost bin]# cp/usr/local/mysql/bin/mysql.server /etc/init.d/mysqld      

#拷贝mysql启动脚本到/etc/init.d/下

chmod 700 /etc/init.d/mysqld       #授权700权限,即脚本可执行

[root@localhost bin]# /etc/init.d/mysqld start 

Starting MySQL. SUCCESS!

2.11设置开机自启动

[root@localhost bin]# chkconfig --add mysqld

[root@localhost bin]# chkconfig mysqld on

[root@localhost bin]# chkconfig --list mysqld

mysqld         0:off   1:off   2:on   3:on    4:on    5:on   6:off

2.12 mysql安全配置,设置登录密码

[root@localhost bin]# mysqladmin -urootpassword '123456'    #设置密码:123456

3.安装PHP软件

3.1检查安装PHP所需lib库

[root@localhost tools]# rpm -qa zlib libxmllibjpeg freetype libpng gd curl libiconv zlib-devel libxml2-devel libjpeg-develfreetype-devel libpng-devel gd-devel curl-devel     #检查lib库安装情况

安装所需lib库

[root@localhost tools]# yum install zliblibxml libjpeg freetype libpng gd curl libiconv zlib-devel libxml2-devellibjpeg-devel freetype-devel libpng-devel gd-devel curl-devel –y

安装libiconv库

[root@localhost tools]# wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz

[root@localhost tools]# tar -zxvflibiconv-1.14.tar.gz

[root@localhost tools]#cd libiconv-1.14.tar.gz

[root@localhost libiconv-1.14]#./configure --prefix=/usr/local/libiconv

[root@localhost libiconv-1.14]#make

[root@localhost libiconv-1.14]#make install

3.2解压php软件

[root@localhost tools]# tar -zxvfphp-5.5.32.tar.gz

[root@localhost tools]# ll

total 67376

drwxr-xr-x 14 1001  1001    4096 Feb  2 21:36 php-5.5.32

-rw-r--r-- 1 root root  17773092 Feb 22 11:22php-5.5.32.tar.gz

3.3配置

./configure \

--prefix=/usr/local/php5.5.32 \

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

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

--with-xmlrpc \

--with-openssl \

--with-zlib \

--with-freetype-dir \

--with-gd \

--with-jpeg-dir \

--with-png-dir \

--with-iconv=/usr/local/libiconv \

--enable-short-tags \

--enable-sockets \

--enable-soap \

--enable-mbstring \

--enable-static \

--enable-gd-native-ttf \

--with-curl \

--with-xsl \

--enable-ftp \

--with-libxml-dir

3.4编译安装

[root@localhost php-5.5.32]#make

Build complete.

Don't forget to run 'make test'.

[root@localhost php-5.5.32]#make install

3.5生成配置文件

[root@localhost php-5.5.32]# ls php.ini*

php.ini-development  php.ini-production

[root@localhost php-5.5.32]# ln -s/usr/local/php5.5.32 /usr/local/php

[root@localhost php-5.5.32]# cpphp.ini-production /usr/local/php/lib/php.ini

3.6配置apache支持php

3.6.1修改apache配置文件

执行如下命令编辑apache的主配置文件httpd.conf:

[root@localhost /]#  cd /usr/local/apache/conf

[root@localhost conf]# cp httpd.confhttpd.conf.20160516.bak

[root@localhost conf]# vim httpd.conf

#增加如下内容:

ServerName 127.0.0.1:80

转到311行即#AddTypeapplication/x-gzip .tgz行的下一行加两行对PHP的解析支持内容:

#AddType application/x-httpd-php .php .php3

AddType application/x-httpd-php .php .phtml

AddType application/x-httpd-php-source .phps

修改默认的首页文件,本例中增加一个index.php:

DirectoryIndex index.php index.html

3.7检查并启动apache

检查apache配置文件的语法

[root@localhost conf]#/usr/local/apache/bin/apachectl -t

Syntax OK

重启apache服务

[root@localhost conf]#/usr/local/apache/bin/apachectl graceful

[root@localhost conf]# netstat -lntp | grep 80

tcp       0      0 :::80                       :::*                        LISTEN      8989/httpd 

#查看httpd服务的80端口是否开启

3.8测试php环境

进入指定的默认站点目录后,编辑index.php添加:

进入默认的apache站点目录

[root@localhost conf]# cd/usr/local/apache/htdocs/

[root@localhost conf]#vimindex.php

Phpinfo();

?>

#注以上代码为显示php配置信息的简单php文件代码,最好手工敲,以防出错;

#通过访问并刷新浏览器http://ip,如可以看到phpinfo信息,如下图,说明php环境配置ok;

 

至此LAMP单机环境搭建完成!

附件:http://down.51cto.com/data/2367706

文章题目:linux单机LAMP环境搭建
标题网址:http://kswjz.com/article/jcgoji.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流