linux单机LAMP环境搭建
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux单机LAMP环境搭建相关的知识,希望对你有一定的参考价值。
LAMP单机环境搭建
一.系统环境准备。
1.系统环境:CentOS_6.5,32位
[[email protected] ~]# cat /etc/redhat-release
CentOS release 6.5 (Final)
[[email protected] ~]# 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
[[email protected] tools]# chkconfig --level 2345iptables off
[[email protected] tools]# chkconfig --listiptables
iptables 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[[email protected] tools]# service iptables stop
[[email protected] tools]# service iptablesstatus
iptables: Firewall is not running.
3.2关闭selinux
[[email protected] tools]# vim/etc/selinux/config #修改配置如下图所示
4.新建软件管理文件夹及上传相关软件
4.1创建软件管理文件夹
[[email protected] tools]# mkdir -p/home/jeff/tools/
[[email protected] tools]# ll /home/jeff/
total 4
drwxr-xr-x. 5 root root 4096 May 16 10:16tools
4.2上传相关软件
[[email protected] /]# cd /home/jeff/tools/
利用rz命令上传相关软件。如果无法使用该命令,请安装lrzsz软件。
二.安装相关软件
1.安装apache软件
1.1解压apache
[email protected] tools]# tar -zxvf httpd-2.2.31.tar.gz
[[email protected] 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++)
[[email protected] tools]# cd httpd-2.2.31
[[email protected] 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编译安装
[[email protected] httpd-2.2.31]# make & makeinstall
1.4启动及检查apache安装情况
1.4.1启动apache
[[email protected] bin]# ./apachectl start #启动apache
httpd: Could not reliably determine theserver‘s fully qualified domain name, using ::1 for ServerName
1.4.2检查apache启动情况
[[email protected] 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
[[email protected] bin]# netstat -lntp | grep 80 #查看apache监听端口
tcp 0 0 :::80 :::* LISTEN 17464/httpd
用浏览器检查:
http://localhost,如出现如下页面,则说明apache安装成功。
2.安装mysql软件
2.1解压mysql
[[email protected] tools]# tar -zxvfmysql-5.1.72.tar.gz
[[email protected] 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相应的用户的用户组
[[email protected] mysql-5.1.72]# groupadd -g 800mysql #创建mysql用户组
[[email protected] mysql-5.1.72]# useradd -gmysql -u 800 -M -s /sbin/nologin mysql #创建mysql用户
[[email protected] mysql-5.1.72]# cat /etc/group| grep mysql #检查mysql组创建情况
mysql:x:800:
[[email protected] 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软件目录
[[email protected] tools]# cd mysql-5.1.72 #进入mysql安装目录
2.3.2配置mysql(配置前安装ncurses-devel先)
[[email protected] 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编译安装
[[email protected] mysql-5.1.72] #make & makeinstall
2.4获取mysql配置文件
[[email protected] mysql-5.1.72]# cdsupport-files
[[email protected] support-files]# cp -amy-small.cnf /etc/my.cnf
2.5创建软连接,方便维护及升级
[[email protected] local]# ln -s /usr/local/mysql5.1.72//usr/local/mysql
2.6创建mysql数据库文件
[[email protected] local]# mkdir -p/usr/local/mysql/data #建立mysql数据文件目录
[[email protected] local]# chown -R mysql:mysql/usr/local/mysql5.1.72 #授权mysql用户访问mysql的安装目录
[[email protected] local]#/usr/local/mysql/bin/mysql_install_db --user=mysql #安装mysql数据库文件
2.7启动mysql数据库
[[email protected] bin]# cp /home/jeff/tools/mysql-5.1.72/support-files/mysql.server/usr/local/mysql/bin/
#拷贝mysql启动脚本到mysql的命令路径
[[email protected] bin]# chmod 700/usr/local/mysql/bin/mysql.server #使脚本可执行
[[email protected] bin]#/usr/local/mysql/bin/mysql.server start #启动数据库
Starting MySQL. SUCCESS!
2.8检查mysql数据库启动情况
[[email protected] bin]# netstat -lnt | grep 3306 #检查mysql监听端口
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
[[email protected] 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*
[[email protected] 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命令的全局路径
[[email protected] bin]# echo ‘exportPATH=$PATH:/usr/local/mysql/bin‘ >> /etc/profile
[[email protected] bin]# tail -1 /etc/profile #检查
export PATH=$PATH:/usr/local/mysql/bin
source /etc/profile #使生效
2.10配置/etc/init.d/mysqldstart 方式启动数据库
[[email protected] bin]# cp/usr/local/mysql/bin/mysql.server /etc/init.d/mysqld
#拷贝mysql启动脚本到/etc/init.d/下
chmod 700 /etc/init.d/mysqld #授权700权限,即脚本可执行
[[email protected] bin]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!
2.11设置开机自启动
[[email protected] bin]# chkconfig --add mysqld
[[email protected] bin]# chkconfig mysqld on
[[email protected] bin]# chkconfig --list mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
2.12 mysql安全配置,设置登录密码
[[email protected] bin]# mysqladmin -urootpassword ‘123456‘ #设置密码:123456
3.安装PHP软件
3.1检查安装PHP所需lib库
[[email protected] 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库
[[email protected] 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库
[[email protected] tools]# wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
[[email protected] tools]# tar -zxvflibiconv-1.14.tar.gz
[[email protected] tools]#cd libiconv-1.14.tar.gz
[[email protected] libiconv-1.14]#./configure --prefix=/usr/local/libiconv
[[email protected] libiconv-1.14]#make
[[email protected] libiconv-1.14]#make install
3.2解压php软件
[[email protected] tools]# tar -zxvfphp-5.5.32.tar.gz
[[email protected] 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编译安装
[[email protected] php-5.5.32]#make
Build complete.
Don‘t forget to run ‘make test‘.
[[email protected] php-5.5.32]#make install
3.5生成配置文件
[[email protected] php-5.5.32]# ls php.ini*
php.ini-development php.ini-production
[[email protected] php-5.5.32]# ln -s/usr/local/php5.5.32 /usr/local/php
[[email protected] php-5.5.32]# cpphp.ini-production /usr/local/php/lib/php.ini
3.6配置apache支持php
3.6.1修改apache配置文件
执行如下命令编辑apache的主配置文件httpd.conf:
[[email protected] /]# cd /usr/local/apache/conf
[[email protected] conf]# cp httpd.confhttpd.conf.20160516.bak
[[email protected] 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配置文件的语法
[[email protected] conf]#/usr/local/apache/bin/apachectl -t
Syntax OK
重启apache服务
[[email protected] conf]#/usr/local/apache/bin/apachectl graceful
[[email protected] conf]# netstat -lntp | grep 80
tcp 0 0 :::80 :::* LISTEN 8989/httpd
#查看httpd服务的80端口是否开启
3.8测试php环境
进入默认的apache站点目录
[[email protected] conf]# cd/usr/local/apache/htdocs/
[[email protected] conf]#vimindex.php
<?php
Phpinfo();
?>
#注以上代码为显示php配置信息的简单php
以上是关于linux单机LAMP环境搭建的主要内容,如果未能解决你的问题,请参考以下文章