Linux_LAMP 最强大的动态网站解决方案

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,高可用系列 2核4GB
简介:

LAMP

Linux+Apache+MySQL/MariaDB+Perl/PHP/Python一组常用来搭建动态网站或者服务器的开源软件,本身都是各自独立的程序,但是因为常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的Web应用程序平台。随着开源潮流的蓬勃发展,开放源代码的LAMP已经与J2EE和.Net商业软件形成三足鼎立之势,并且该软件开发的项目在软件方面的投资成本较低,因此受到整个IT界的关注。从网站的流量上来说,70%以上的访问流量是LAMP来提供的,LAMP是最强大的网站解决方案.

Install LAMP via YUM

yum groupinstall -y "mysql数据服务器" "PHP支持"    
yum install -y php-mysql
service httpd start
service mysqld start
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

Install LAMP via ResourceCode

Apache

Port:TCP80 TCP443 
logFile:/var/log/httpd/ 
step1. Install Apache

rpm -e httpd -nodeps   #move system pre-installed httpd software.
tar zxvf http-XXX -C /var/src
./configure --prefix=/usr/local/apache2 --enable-so --enable-rewrite && make && make install
/usr/local/apache2/bin/apachectl start
cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd
  • 1
  • 2
  • 3
  • 4
  • 5
  • 1
  • 2
  • 3
  • 4
  • 5

step2. Addition service to chkconfig 
vim /etc/init.d/httpd

#!/bin/sh
#chkconfig:35 12 32
#description:httpd server
#12 --> priority
#32 --> close priority
  • 1
  • 2
  • 3
  • 4
  • 5
  • 1
  • 2
  • 3
  • 4
  • 5

step3. Start the chkconfig service

chkconfig --add httpd
chkconfig httpd on
  • 1
  • 2
  • 1
  • 2

step4. Edit the httpd service config file 
vim /usr/local/apache2/conf/httpd.conf

#Global
ServerRoot "URL"            #Directory for store the config file
Timeout 60                  #connect timeout
PidFile run/httpd.pid       #the directory for store pid file
listen 80                   #listen into port
user  XXX                   #httpd default users:will use 'apache' user when you install via YUM, otherwise you have to create the 'daemon' user to run the httpd service when you install resource.
group  XXX                  #httpd service default group

keepAlive on                #one connect much transfer data
MaxkeepAliveRequests 500    #Max connection count.
keepAliveTimeout 50         #keep connect alive timeout
prefork                     #work model to small web
work                        #work model to big web
Server Admin:ManagerMail
ServerName:www.domain.com:80
DocumentRoot "[websiteUrl]"   #VirtualHost more preferential  a.yum install: /var/www/html  b.resource install:/usr/local/apache2//htdocs
DirectoryIndex:   #set welcome page
#Set welcome page example:
<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>
AddDefaultCharset UTF-8  #add character set
#Locality:
<Directory "/var/www/html[websiteUrl]">
  Options
  AllowOverride
  Order
  Deny from
</Directory>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

step5. Httpd Stress testing

ab -c X httpdServerIP   #X:Sub-requent requests count
ab -n X httpdServerIP   #X:Total requests count
Forexample:
ab -c 2000 -n 4000 http://www.domain.com/    #2000 times PV(PageView) at the same time.
ulimit -n 2000       #Change the max supervene access count. Because the max supervene access count have to less than 1024 in the linux file.
ulimit -a                #Check all limit
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

Apache Virtual Machine Type

  1. Virtual Machine type: 
    (1) DomainName-based virtual hosting 
    (2) IP address-based 
    (3) Port-based

Use name-based virtual hosting(the same of ip and port)

step1

mkdir htdocs/baidu htdocs/sina
echo www.baidu.com > htdocs/baidu/index.html
echo www.sina.com > htdocs/sina/index.html
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

step2. Open virtual machine function 
vim httpd.conf

#Virtual Hosts
Include conf/extra/httpd-vhosts.conf
  • 1
  • 2
  • 1
  • 2

vim conf/extra/httpd-vhosts.conf #Define virtual machine domain 
For example:

NameVirtualHost \*:80   #specify virtual machine to name-based hosts. 
                        #Attention: "*:80" have to same as below sections.
<VirtualHost *:80>
     ServerAdmin jmilk@fan.com
     DocumentRoot "/usr/local/apache2/htdoes/baidu"
     ServerName Jmilk.fan.com
     ErrorLog "logs/baidu-error_log"
     CustomLog "logs/baidu-access_log" common
     <Directory "/usr/local/apache2/htdoes/baidu">  #Setup website access permission
           Order allow,deny
           Allow from all
      </Directory>
</VirtualHost>
<VirtualHost *:80>
     ServerAdmin jmilk@fan.com
     DocumentRoot "/usr/local/apache2/htdoes/sina"
     ServerName Jmilk.fan.com
     ErrorLog "logs/sina-error_log"
     CustomLog "logs/sina-access_log" common
</VirtualHost>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

vim /etc/hosts

10.20.0.210 www.baidu.com www.sina.com
  • 1
  • 1
service httpd restart
  • 1
  • 1

Use IP-based virtual hosting

Much step of setup the IP-based virtual hosting as same as the name-based virtual hosting,but different as below. 
step1. Comments the “NameVritualHost *:80” 
step2. Specify the different IP in the sections of <VirtualHost IP:80>

Use Post-based virtual hosting

step1. Add the Listen port 
vim httpd.conf

  Listen 80
  Listen 81
  • 1
  • 2
  • 1
  • 2

step2. Comments the “NameVritualHost *:80” 
step3. Specify the different IP in the sections of <VirtualHost IP:Post>

Create personal page.

vim httpd.conf #open home directory

 #User home directories
 Include conf/extra/httpd-userdir.conf
  • 1
  • 2
  • 1
  • 2

vim httpd-userdir.conf

 userDir public_html   --> Create Public_html file in the home directory.
  • 1
  • 1

Login the personal page

 chmod o+x /home/user
 http://IP/~userName
  • 1
  • 2
  • 1
  • 2

Security access https

step1. Install Apache by resource and enable ssl protocol

yum -y install mod_ssl
rpm -qa |grep openssl 
./configure --enable-so --enable-rewirte --enable-ssl && make && make install
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

step2. Edit the Apache config file to enable ssl function module 
vim httpd.conf

LoadModule ssl_module modules/mod_ssl.so 
# Secure (SSL/TLS) connections
Include conf/extra/httpd-ssl.conf
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

setp3. Create ssl cert 
cd conf/ and Running the cert script as below

#certcreate.sh
#!/bin/bash
read -p "文件名称前缀:" name
openssl genrsa -des3 -out ${name}a.key 1024
openssl rsa -in ${name}a.key -out ${name}.key
openssl req -new -key ${name}.key -out ${name}.csr
openssl x509 -req -days 1000 -in ${name}.csr -signkey ${name}.key -out ${name}.crt
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

step4. Specify virtual machine which used security(ssl) cert and ssl cert’s store directory url. 
vim extra/httpd-ssl.conf

Listen 443
AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl    .crl
SSLPassPhraseDialog  builtin
SSLSessionCache        "shmcb:/usr/local/apache2//logs/ssl_scache(512000)"
SSLSessionCacheTimeout  300
SSLMutex  "file:/usr/local/apache2//logs/ssl_mutex"
NameVirtualHost *:443

<VirtualHost *:443>
       DocumentRoot "/usr/local/apache2//htdocs/baidu"
       ServerName jmilk.fan.com:443
       ServerAdmin jmilk@fan.com
       ErrorLog "/usr/local/apache2//logs/baidu_error_log"
       TransferLog "/usr/local/apache2//logs/baidu_access_log"
       SSLEngine on
       SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL  -->列出运行客户端协商的密码
       SSLCertificateFile "/usr/local/apache2//conf/server.crt"
       SSLCertificateKeyFile "/usr/local/apache2//conf/server.key"
       <FilesMatch "\.(cgi|shtml|phtml|php)$">
                SSLOptions +StdEnvVars
       </FilesMatch>
       <Directory "/usr/local/apache2//cgi-bin">
                SSLOptions +StdEnvVars
       </Directory>

       BrowserMatch ".*MSIE.*" \
       nokeepalive ssl-unclean-shutdown \
       downgrade-1.0 force-response-1.0
       CustomLog "/usr/local/apache2//logs/ssl_request_log" \
       "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32

step4. restart httpd service

service httpd restart
  • 1
  • 1

Access control

Only permission user who can access this web pager. 
step1. Install awstats software.

unzip awstats-7.0.zip               #Program by Analytic language ,so don't need to compile.
cd /usr/local/awstats-7.0/tools
./awstats_configure.pl              #Install of interactive mode
service httpd restart               #The entry into force of awstats plugin
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

step2. Edit the awstats plugin configure file. 
vim /etc/awstats/awstats.jmilk.fan.com.conf(awstats.domain.com.conf)

LogFile="/usr/local/apache2/logs/baidu-access_log"
  • 1
  • 1
mkdir /var/lib/awstats
http://localhost/awstats/awstats.pl  #access awstats software
  • 1
  • 2
  • 1
  • 2

step3. Edit apache configure file to add awstats plugin 
vim httpd-vhosts.conf #change the CustomLog type from “common” to “combined”

CustomLog "logs/sina-access_log" common  --> CustomLog "logs/baidu-access_log" combined
  • 1
  • 1
service httpd restart
  • 1
  • 1

step4. setting awstats’s access limit 
vim httpd.conf

#Add section below for example:
#This is to permit URL access to scripts/files in AWStats directory.
#
<Directory "/usr/local/awstats-7.0/wwwroot">
    Options None
    AllowOverride None
    Order allow,deny
    Allow from all
    AuthName "AWSTATS"
    AuthType Basic
    AuthUserFile /usr/local/awstats/wwwroot/.htpasswd
    require valid-user
</Directory>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

step5. Create htpasswd user by htpasswd tool

cd /usr/local/apache2/bin/htpassed
htpasswd -c /usr/local/apache2/conf/.htpasswd userName1   #In frist create user,you have to use option -c to specify the htpasswd file store url
htpasswd userName2
service httpd restart    
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

MySQL

Port: TCP 3306 
step1. install Mysql 
step1. Install MySQL via resource

tar zxvf mysql-XXX -C /var/src
useradd mysql -s /sbin/nologin -M    #-M --> have not home directory
./configure --prefix=/usr/local/mysql --sysconfdir=/etc/ && make && make install
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

step2. Initialization Mysql configure.

cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf 
/usr/local/mysql/bin/mysql-install-db --user=mysql
chown -R root:mysql /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql/var
ln -s /usr/local/mysql/bin/* /usr/local/bin
  • 1
  • 2
  • 3
  • 4
  • 5
  • 1
  • 2
  • 3
  • 4
  • 5

vim /etc/profile

PATH=${PATH}/usr/local/mysql/bin
  • 1
  • 1

step3. Start mysql service

mysql_safe --user=mysql &
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod a+x /etc/init.d/mysqld
echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf   --> setup mysql interface
ldconfig   #Refresh the ld.so.conf file.
service mysqld start
chkconfig mysqld on
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

step4. Setup mysql’s user and password.

mysqladmin -u root password '123'    #setting password
mysql -u root -p123          #login mysql
#or
mysql_secure_installation --> Basic secure setting
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

step5. Check the Mysql install

 mysal -u root -p123
 show databases;
 use mysql;
 show tables;
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

step6. Mysql usage 
a. list user’s table field information 
describe user; 
b. create database and create file in the /usr/local/mysql/var/ 
create database world; 
c. create table 
create table tableName(id int not null,name char(16) not null,password char(16) not null default '123',primany key(id)); 
d. delete table

drop table table DBName.tableName;
delete fro tableName where id=3;
  • 1
  • 2
  • 1
  • 2

e. select table info or select table item info.

select * from tableName;
select * from tableName where price > 10;  #selece by condition
select * from tableName order by price;    #from small to big sort
select * from tableName order by price desc;  #from big to small sort. desc 降序
select avg(price) from tableName;    #average value
select sum(price) from tableName;    #summation; or use function min() max() count():output notes conunt.
select type,avg(price) from tableName group by type;
type,avg(price)     #every type's average price
select type,avg(price) from tableName group by type having avg(price) > 10;     #use where before grouping, use having after grouping. 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

f. select from much table.

select table1Name.name,table2Name.nation from table1Name,table2Name where table1Name.id=table2Name.id;           #内链接查询
select table1Name.name,table2Name.nation from table1Name left join table2Name on table1Name.id=table2Name.id;    #左链接(left join)查询,以左表为主,左表必须全列出符合的记录,右表若没有对应的记录时,以null补全
select table1Name.name,table2Name.nation from table1Name right join table2Name on table1Name.id=table2Name.id;   #右链接(right join)
select table1Name.name,table2Name.nation from table1Name cross join table2Name;                                  #全链接查询,交叉查询(cross join)笛卡儿积
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

g. Insert item into table 
insert into tableName(id,name,password) values(1,'userName','123'); 
h. Update the table item info. 
update tableName set password=encrypt('123') where id=1; 
b.Mysql date backup and recover: 
(1) Backup:

mysqldump -u root -p123 databaseName > tableName.sql  --> backup a database
mysqldump -u root -p123 --all-databases > all.sql  --> backup all database
  • 1
  • 2
  • 1
  • 2

(2) Recover:

mysql -u root -p123 tableName < tableName.sql 
mysql -u root -p123 < all.sql  --> resover all the database
  • 1
  • 2
  • 1
  • 2

PHP

step1. Install php support

tar zxvf libmcrypt -C /usr/local
tar zxvf mhach -C /usr/local
tar zxvf mcrypt -C /usr/local    #libmcrypr,mhach annd mcrypt combine to secure encrypt deal with.
cd /usr/local/libmcrypt
./configure && make && make install
echo "/usr/local/lib" >> /etc/ld.so.conf
ldconfig
cd /usr/local/mhach
./configure && make && make install
ldconfig
cd /usr/local/mcrypt
./configure && make && make install
tar zxvf php-XXX.tar.gz -C /usr/local
mv php-XXX PHP5
cd /usr/local/php5
./configure --prefix=/usr/local/php5 --with-apxs2=/usr/local/apache2/bin/apx5 --with-mysql=/usr/local/mysql --with-mcrpyt --with-config-file-path=/usr/local/php5 --enable-mbstring && make && make install
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

step2. Edit php Configure file

cp /usr/local/php5/php.ini-development /usr/local/php5/php.ini
  • 1
  • 1

vim /usr/local/apache2/conf/httpd.conf #add php plugin to apache


<IfModule mime_module>   #加入.PHP后缀识别模块
        AddType application/x-httpd-php .php
</IfModule>

<IfModule dir_module>   #加入PHP欢迎页面
        DirectoryIndex index.html index.php
</IfModule>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

step3. Test the php module 
vim TestPHP.php

<?php
    phpinfo()
?>
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

step4. Install phpMyAdmin manager paper.

tar phpMyAdmin -C /usr/local/apache2/htdocs/baidu
mv phpMyAdmin pma
cp pma/confg.sample.inc.php pma/config.inc.php
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

step5. Install Discuz

unzip Discuz
cd Discuz
mv upload /usr/local/apache2/htdoes/bbs
chown -R daemon:daemon /usr/local/apache2/htdoes/bbs
http://localhost/bbs  #enter installtation pager        


转载:http://blog.csdn.net/jmilk/article/details/50273995

目录
相关文章
|
4月前
|
域名解析 网络协议 安全
在Linux中,想在命令行下访问某个网站,并且该网站域名还没有解析,如何做?
在Linux中,想在命令行下访问某个网站,并且该网站域名还没有解析,如何做?
|
4月前
|
监控 前端开发 安全
在Linux中,假如公司网站访问速度变的很慢很慢,该如何处理?
在Linux中,假如公司网站访问速度变的很慢很慢,该如何处理?
|
3月前
|
Linux 编译器 开发工具
快速在linux上配置python3.x的环境以及可能报错的解决方案(python其它版本可同样方式安装)
这篇文章介绍了在Linux系统上配置Python 3.x环境的步骤,包括安装系统依赖、下载和解压Python源码、编译安装、修改环境变量,以及常见安装错误的解决方案。
260 1
|
2月前
|
存储 Linux
服务器数据恢复—Linux操作系统网站服务器数据恢复案例
服务器数据恢复环境: 一台linux操作系统网站服务器,该服务器上部署了几十个网站,使用一块SATA硬盘。 服务器故障&原因: 服务器在工作过程中突然宕机。管理员尝试重新启动服务器失败,于是将服务器上的硬盘拆下检测,发现很多坏扇区。联系当地的一家数据恢复公司处理,但是没有成功。
|
3月前
|
存储 数据挖掘 Linux
服务器数据恢复—Linux操作系统网站服务器数据恢复案例
服务器数据恢复环境: 一台linux操作系统服务器上跑了几十个网站,服务器上只有一块SATA硬盘。 服务器故障: 服务器突然宕机,尝试再次启动失败。将硬盘拆下检测,发现存在坏扇区
|
3月前
|
监控 安全 Linux
如何利用Kali Linux进行网站渗透测试:最常用工具详解
如何利用Kali Linux进行网站渗透测试:最常用工具详解
138 6
|
4月前
|
监控 测试技术 Linux
在Linux中,什么叫网站灰度发布?
在Linux中,什么叫网站灰度发布?
|
4月前
|
Web App开发 监控 网络协议
在Linux中,当用户反馈网站访问慢,如何处理?
在Linux中,当用户反馈网站访问慢,如何处理?
|
4月前
|
Linux 网络安全 Python
Linux离线安装Python时ssh和hashlib死活安装不上的解决方案
本文提供了Linux环境下离线安装Python时遇到的"ImportError: No module named _ssl"和"ERROR:root:code for hash md5|sha1|sha224|sha256|sha384|sha512 was not found"两个问题的解决方案,通过设置OpenSSL环境变量和编辑Python源码配置文件来解决。
69 1
|
5月前
|
关系型数据库 Linux 数据库
如何在Linux云服务器上通过Docker Compose部署安装Halo,搭建个人博客网站?
本文指导用户如何在Linux服务器上使用Docker Compose部署Halo博客系统。首先确保拥有Linux服务器并安装Docker及Docker Compose。接着创建文件夹(例如`~/halo`),用于存放所有Halo相关数据。可以选择不同的Halo Docker镜像源,推荐使用具体版本而非`latest`标签以避免误操作。示例中提供了三种`docker-compose.yaml`配置方法:Halo+PostgreSQL、Halo+MySQL以及使用默认的H2数据库。每种配置都包括网络设置、健康检查和环境变量。
246 1