设为首页 收藏本站
查看: 721|回复: 0

ubuntu下搭建lamp

[复制链接]

尚未签到

发表于 2015-8-20 07:46:00 | 显示全部楼层 |阅读模式
一、使用apt-get方式为Ubuntu安装PHP+MYSQL+Apache

分别执行如下命令:

(1)安装MYSQL

sudo apt-get install mysql-server

sudo apt-get install mysql-client

(2)安装Apache

sudo apt-get install apache2

(3)安装PHP
  www.iyunv.com  
sudo apt-get install php5

sudo apt-get install libapache2-mod-auth-mysql

sudo apt-get install php5-mysql

安装结束后,检测是否成功:

(1)检测Mysql是否正常

在终端中输入:mysql -uusername -ppassword (将username和password替换为你所设置的)看是否可以正常登陆

(2)检测Apache是否正常

在浏览器中打开:http://localhost/

如果出现如下信息,则表明正常。

It works!
This is the default web page for this server.
  www.iyunv.com  
The web server software is running but no content has been added, yet.

(3)检测PHP是否正常

Ubuntu下Apache的默认安装路径为/var/www/,到其目录下新建info.php文件,文件内容为:

<?php
phpinfo();
?>

然后在浏览器中打开:http://localhost/info.php 看是否正常。

注:在该目录直接新建文件是没有权限的,为其增加当前用户权限:

su root(用root用户)

chown username /var/www(将username替换为您当前用户的用户名)

exit(退出root)

如果,您的ubuntu系统root用户还不可用,那是因为ubuntu系统默认root密码为空,您可以通过如下命令设置密码:

sudo passwd -l root

二、手工编译为Ubuntu安装PHP+MYSQL+Apache
  www.iyunv.com  
1、下载软件

MySql:wget http://down1.chinaunix.net/distfiles/mysql-5.0.56.tar.gz

Apache:wget http://apache.freelamp.com/httpd/httpd-2.2.13.tar.gz

PHP:wgethttp://125.39.113.23:9203/CDE349DEF7D7A6AC19DE5771F752CA258C693F634815D4BE/cn.php.net/distributions/php-5.2.10.tar.bz2

2、安装MySql

安装步骤:

shell> groupadd mysql
  www.iyunv.com  
shell> useradd -g mysql mysql

shell> gunzip < mysql-VERSION.tar.gz | tar -xvf – 或 tar -zxvf  mysql-5.0.56.tar.gz(解压mysql源码包)

shell> cd mysql-VERSION(进入mysql源码文件夹)

shell> ./configure –prefix=/usr/local/mysql

shell> make

shell> make install

shell> cp support-files/my-medium.cnf /etc/my.cnf

shell> cd /usr/local/mysql

shell> bin/mysql_install_db –user=mysql
  www.iyunv.com  
shell> chown -R root  .

shell> chown -R mysql var

shell> chgrp -R mysql .

shell> bin/mysqld_safe –user=mysql &

修改mysql root 密码
$ mysqladmin -u root password newpass
添加服务项
cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
chkconfig –add mysqld

3、安装Apache

tar zvxf httpd-2.2.13.tar.gz
cd httpd-2.2.13
修改src/include/httpd.h 增大最大线程数

#define HARD_SERVER_LIMIT 256

改成

#define HARD_SERVER_LIMIT 2560
  www.iyunv.com  
保存退出编译apache
./configure –prefix=/usr/local/apache –enable-module=so –enable-module=rewrite –enable-shared=max –htdocsdir=/var/www &&
make
make install

#这里我们通过enable-module参数告诉设置脚本,我们需要启动so和rewrite模块,so模块是用来提DSO支持的 apache核 心模块,而rewrite模块则是用意实现地址重写的模块,由于rewrite模块需要DBM支持,如果在初次安装时没有编译进apache,以后需要用 到时需要重新编译整个apache才可以实现。为此除非你可以确定以后不会用到rewrite模块,否则还是建议你在第一次编译的时候把rewrite模 块编译好。

enable-shared=max 这个参数的作用时编译apache时,把除了so以外的所有apache的标准模块都编译成DSO模块。而不是编译进apache核心内。

好了安装apache很简单的哦,启动apache看看
  www.iyunv.com  
/usr/local/apache/bin/apachectl start
然后 通过浏览器查看http://youhost/,如果正常则说明安装成功。

apache设为linux服务

cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd
vi /etc/init.d/httpd

在在#!/bin/sh后面加入下面两行
#chkconfig:345 85 15
#description: Start and stops the Apache HTTP Server.

然后
chmod +x /etc/rc.d/init.d/httpd
chkconfig –add httpd
  www.iyunv.com  
4、安装PHP

(1)tar zvxf php-5.2.10.tar.bz2
(2)cd php-5.2.10

(3)./configure -prefix=/usr/local/php –with-config-file-path=/usr/local/php/etc -with-mysql=/usr/local/mysql –with-mysqli=/usr/local/mysql/bin/mysql_config –with-iconv-dir=/usr/local –with-freetype-dir –with-jpeg-dir –with-png-dir –with-zlib –with-libxml-dir=/usr –enable-xml –disable-rpath –enable-discard-path –enable-safe-mode –enable-bcmath –enable-shmop –enable-sysvsem –enable-inline-optimization –with-curl –with-curlwrappers –enable-mbregex –enable-fastcgi –enable-fpm –enable-force-cgi-redirect –enable-mbstring –with-mcrypt –with-gd –enable-gd-native-ttf –with-openssl –with-mhash –enable-pcntl –enable-sockets –with-ldap –with-ldap-sasl –-with-apxs2=/usr/local/apache/bin/apxs
  www.iyunv.com  
(4)make

(5)make install

最后一步重新启动apache报如下错误:
httpd: Syntax error on line 53 of /usr/local/apache/conf/httpd.conf: Cannot load /usr/local/apache/modules/libphp5.so into server: /usr/local/apache/modules/libphp5.so: cannot restore segment prot after reloc: Permission denied

原因:是Linux有一个SELinux保护模式引起的。

解决办法:
  www.iyunv.com  
1关闭SELINUX的方法:
vi /etc/selinux/config 将SELINUX=enforcing 改成SELINUX=disabled 需要重启
这个方法可能会对服务器带来风险。

2不关闭SELINUX的方法:
依次执行如下命令
# setenforce 0
# chcon -c -v -R -u system_u -r object_r -t textrel_shlib_t /usr/local/apache/modules/libphp5.so
# service httpd restart
# setenforce 1

vi /usr/local/apache/conf/httpd.conf

查找

在此范围添加

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

然CPOPY PHP的配置文件

cp ../php-5.2.10/php.ini.dist /usr/local/php/lib/php.ini
  www.iyunv.com  
修改php.ini文件
register_globals = On

ok!重新启动一下apache服务器
/usr/local/apache/bin/apachectl restart

然后写个php测试页info.php:内容如下

<?php
phpinfo();
?>
正常的话,应该能看到php的信息了,恭喜你的Apche+Mysql+PHP安装成功。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-101371-1-1.html 上篇帖子: LAMP 调优之:MySQL 服务器调优 下篇帖子: ubuntu lamp(apache+mysql+php) 环境搭建及相关扩展更新
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表