首页 / LINUX / linux单机LAMP环境搭建
linux单机LAMP环境搭建
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了linux单机LAMP环境搭建,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含10519字,纯文字阅读大概需要16分钟。
内容图文
LAMP 单机环境搭建
一.系统环境准备。
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 # 修改配置如下图所示
650) this.width=650;" width="555" height="163" src="/upload/getfiles/default/2022/11/9/20221109015916583.jpg" title="selinux.png" border="0" hspace="0" vspace="0" />
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 安装成功。
650) this.width=650;" border="0" width="721" height="200" src="/upload/getfiles/default/2022/11/9/20221109015916807.jpg" title="123.png" hspace="0" vspace="0" />
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环境
进入默认的 apache 站点目录
[root@localhost conf]# cd/usr/local/apache/htdocs/
[root@localhost conf]#vimindex.php
<?php
Phpinfo();
?>
# 注以上代码为显示 php 配置信息的简单 php 文件代码,最好手工敲,以防出错;
# 通过访问并刷新浏览器 http://ip ,如可以看到 phpinfo 信息,如下图,说明 php 环境配置 ok;
至此LAMP单机环境搭建完成!
本文出自 “jeff博客” 博客,请务必保留此出处http://jeff1.blog.51cto.com/4814928/1773968
原文:http://jeff1.blog.51cto.com/4814928/1773968
内容总结
以上是互联网集市为您收集整理的linux单机LAMP环境搭建全部内容,希望文章能够帮你解决linux单机LAMP环境搭建所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。