• 幕客老师召集小伙伴
  • 运维高手36项修炼
  • python自动化运维项目实战
  • nginx从入门到实战
  • 阿里云与Centos7实战

Apache-LAMP环境搭建

LAMP环境

作用: 支持PHP站点
示例: Discuz!(php)
========================================================

基本步骤:
1. 搭建LAMP,测试  (源码安装,rpm包安装)
2. 上传网站代码
3. 创建数据库,并导入网站的表结构*.sql
   ==手动创建数据库,导入表结构
   ==网站的脚本自动创建数据库,导入表结构
4. 配置网站(php程序)连接数据库(数据库服务器IP,数据库名,用户名,密码)

一. 搭建LAMP环境
1. 安装软件包
[root@jeson ~]# yum -y install httpd mysql-server mysql php php-zts php-mysql gd
[root@jeson ~]# service httpd restart
[root@jeson ~]# service mysqld start
[root@jeson ~]# chkconfig mysqld on
[root@jeson ~]# chkconfig httpd on

2. 检查MySQL
[root@jeson ~]# mysql -uroot //不需要密码
[root@jeson ~]# mysqladmin -uroot password ‘123456’   //设置密码(原密码为空)
[root@jeson ~]# mysql -uroot -p123456
mysql> show databases; //查看当前的数据库
+——————–+
| Database           |
+——————–+
| information_schema | 
| mysql              | 
| test               | 
+——————–+
3 rows in set (0.01 sec)

3. 检查Apache和php
[root@jeson ~]# ll /etc/httpd/modules/ |grep php
-rwxr-xr-x 1 root root 3023292 2012-02-02 libphp5.so
-rwxr-xr-x 1 root root 3023292 2012-02-02 libphp5-zts.so

[root@jeson ~]# grep php /etc/httpd/conf.d/php.conf 
  LoadModule php5_module modules/libphp5.so
  LoadModule php5_module modules/libphp5-zts.so
DirectoryIndex index.php

4. 测试php程序能否正常运行
[root@jeson ~]# vim /var/www/html/index.php //测试页面
<?php
phpinfo();
?>
[root@jeson ~]# firefox http://192.168.5.242/

[root@jeson ~]# vim /var/www/html/index2.php
<?php
$link=mysql_connect(‘www.iaskjob.com′,’root’,’123′);
if ($link)
              echo “Successfuly”;
else
              echo “Faile”;
mysql_close();
?>

二. 部署网站
1. 上传网站程序
[root@jeson ~]# rm -rf /var/www/html/*
[root@jeson ~]# unzip Discuz_X2.5_SC_UTF8.zip
[root@jeson ~]# cd upload/
[root@jeson upload]# cp -rf * /var/www/html
[root@jeson upload]# chmod -R 777 /var/www/html/*

2.安装网站(创建数据库,连接数据库)
http://192.168.2.240
注意连接mysql服务器:IP,username,password,database

3. 检查MySQL
[root@jeson ~]# mysql -uroot -p123456
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 35
Server version: 5.0.77 Source distribution

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql> show databases;
+——————–+
| Database           |
+——————–+
| information_schema | 
| mysql              | 
| test               | 
| ultrax             | 
+——————–+
4 rows in set (0.00 sec)

mysql> use ultrax
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> 
mysql> 
mysql> 
mysql> show tables; 

===================================================================
NameVirtualHost *:80
#
# NOTE: NameVirtualHost cannot be used without a port specifier 
# (e.g. :80) if mod_ssl is being used, due to the nature of the
# SSL protocol.
#

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#

//用户登录验证
<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot /opt/www1
    <Directory “/opt/www1″>
        Options Indexes FollowSymLinks
        Order deny,allow
        Allow from all
        AuthType basic
        AuthName “Input your passwd (test)”
        AuthUserFile /etc/httpd/conf/webpasswd
        Require valid-user
    </Directory>
    ServerName www1.uplooking.com
    ErrorLog logs/www1-error_log
    CustomLog logs/www1-access_log common
</VirtualHost>

//访问控制
<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot /opt/www2
    <Directory “/opt/www2″>
        Options Indexes FollowSymLinks
        Order deny,allow
        Deny from all
        Allow  from  192.168.1.253
    </Directory>
    ServerName www2.uplooking.com
    ErrorLog logs/www2-error_log
    CustomLog logs/www2-access_log common
</VirtualHost>

//基于文件的访问控制
<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot /opt/www3
    <Directory “/opt/www3″>
        Options Indexes FollowSymLinks
        Order deny,allow
        Allow from all
        <Files ~ “\.php$”>
           Order allow,deny
           Deny from all
        </Files>
    </Directory>
    ServerName www3.uplooking.com
    ErrorLog logs/www2-error_log
    CustomLog logs/www2-access_log common
</VirtualHost>

//别名的方式,Alias
#http://www4.uplooking.com/test/test.php=http://www3.uplooking.com/test.php
<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot /opt
    Alias /test/test.php  “/opt/www3/test.php”
    <Directory “/opt/www4″>
        Options Indexes FollowSymLinks
        Order deny,allow
        Allow from all
    </Directory>
    ServerName www4.uplooking.com
    ErrorLog logs/www4-error_log
    CustomLog logs/www4-access_log common
</VirtualHost>

//LANMP配置。
<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot /opt/lamp
    <Directory “/opt/lamp”>
        Options Indexes FollowSymLinks
        Order deny,allow
        Allow from all
    </Directory>
    ServerName lamp.uplooking.com
    ErrorLog logs/lamp-error_log
    CustomLog logs/lamp-access_log common
</VirtualHost>

Apache-LAMP环境搭建

Pingbacks已打开。

引用地址

暂无评论

发表评论