首页 > 代码库 > web环境

web环境

LAMP搭建

安装mysql:

tar zxvf /usr/local/src/mysql-5.1.40-linux-i686-icc-glibc23.tar.gz 

mv mysql-5.1.40-linux-i686-icc-glibc23 /usr/local/mysql

useradd -s /sbin/nologin mysql

cd /usr/local/mysql

mkdir -p /data/mysql ; chown -R mysql:mysql /data/mysql 

./scripts/mysql_install_db --user=mysql --datadir=/data/mysql

cp support-files/my-large.cnf /etc/my.cnf 

cp support-files/mysql.server /etc/init.d/mysqld 

chmod 755 /etc/init.d/mysqld 

vim /etc/init.d/mysqld        ------>“datadir=/data/mysql”

chkconfig --add mysqld

chkconfig mysqld on

service mysqld start 

安装Apache:

tar jvxf httpd-2.2.24.tar.bz2 

cd httpd-2.2.24

yum install -y zlib-devel

yum install -y pcre pcre-devel apr apr-devel

make && make install

安装PHP:

tar zxf php-5.3.27.tar.gz

cd php-5.3.27
yum install -y libxml2-devel
yum install -y openssl openssl-devel
yum install -y bzip2 bzip2-devel
yum install -y libpng libpng-devel
yum install -y freetype freetype-devel
yum install -y  libmcrypt-devel
rpm -ivh epel-release-6-7.noarch.rpm
 ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/php/etc  --with-mysql=/usr/local/mysql --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif --disable-ipv6
make && make install
cp php.ini-production /usr/local/php/etc/php.ini

apache结合php:

vim /usr/local/apache2/conf/httpd.conf

找到:

AddType application/x-gzip .gz .tgz

在该行下面添加:

AddType application/x-httpd-php .php

找到:

    DirectoryIndex index.html

将该行改为:

    DirectoryIndex index.html index.htm index.php

找到:

#ServerName www.example.com:80

修改为:

ServerName localhost:80
/usr/local/apache2/bin/apachectl -t
/usr/local/apache2/bin/apachectl start
curl localhost

It works!

vim /usr/local/apache2/htdocs/1.php

写入:


curl localhost/1.php
php解析正常[root@localhost ~]#

LNMP搭建

安装mysql:

tar zxvf /usr/local/src/mysql-5.1.40-linux-i686-icc-glibc23.tar.gz 

mv mysql-5.1.40-linux-i686-icc-glibc23 /usr/local/mysql

useradd -s /sbin/nologin mysql

cd /usr/local/mysql

mkdir -p /data/mysql ; chown -R mysql:mysql /data/mysql 

./scripts/mysql_install_db --user=mysql --datadir=/data/mysql

cp support-files/my-large.cnf /etc/my.cnf 

cp support-files/mysql.server /etc/init.d/mysqld 

chmod 755 /etc/init.d/mysqld 

vim /etc/init.d/mysqld        ------>“datadir=/data/mysql”

chkconfig --add mysqld

chkconfig mysqld on

service mysqld start 


安装PHP:

tar zxf php-5.3.27.tar.gz
useradd -s /sbin/nologin php-fpm

cd php-5.3.27

yum install -y libcurl-devel
yum install -y libtool-ltdl-devel
./configure --prefix=/usr/local/php1 --with-config-file-path=/usr/local/php1/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --enable-zend-multibyte --disable-ipv6 --with-pear --with-curl --with-openssl
make && make install
cp php.ini-production /usr/local/php/etc/php.ini
vim /usr/local/php/etc/php-fpm.conf
把如下内容写入该文件:

[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
[www]
listen = /tmp/php-fcgi.sock
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024
保存配置文件后,检验配置是否正确的方法为:
/usr/local/php/sbin/php-fpm -t
cp /usr/local/src/php-5.3.27/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod 755 /etc/init.d/php-fpm
service php-fpm start

安装nginx:

tar zxvf nginx-1.4.4.tar.gz

cd nginx-1.4.4

./configure \

--prefix=/usr/local/nginx \

--with-http_realip_module \

--with-http_sub_module \

--with-http_gzip_static_module \

--with-http_stub_status_module  \

--with-pcre

make && make install

> /usr/local/nginx/conf/nginx.conf

vim /usr/local/nginx/conf/nginx.conf

加入:

user nobody nobody;

worker_processes 1;

error_log /usr/local/nginx/logs/nginx_error.log crit;

pid /usr/local/nginx/logs/nginx.pid;

worker_rlimit_nofile 51200;


events

{

    use epoll;

    worker_connections 6000;

}


http

{

    include mime.types;

    default_type application/octet-stream;

    server_names_hash_bucket_size 3526;

    server_names_hash_max_size 4096;

   log_format combined_realip ‘$remote_addr $http_x_forwarded_for        [$time_local]‘

    ‘$host "$request_uri" $status‘

    ‘"$http_referer" "$http_user_agent"‘;

    sendfile on;

    tcp_nopush on;

    keepalive_timeout 30;

    client_header_timeout 3m;

    client_body_timeout 3m;

    send_timeout 3m;

    connection_pool_size 256;

    client_header_buffer_size 1k;

    large_client_header_buffers 8 4k;

    request_pool_size 4k;

    output_buffers 4 32k;

    postpone_output 1460;

    client_max_body_size 10m;

    client_body_buffer_size 256k;

    client_body_temp_path /usr/local/nginx/client_body_temp;

    proxy_temp_path /usr/local/nginx/proxy_temp;

    fastcgi_temp_path /usr/local/nginx/fastcgi_temp;

    fastcgi_intercept_errors on;

    tcp_nodelay on;

    gzip on;

    gzip_min_length 1k;

    gzip_buffers 4 8k;

    gzip_comp_level 5;

    gzip_http_version 1.1;

gzip_types text/plain application/x-javascript text/css text/htm application/xml;


server

{

    listen 80;

    server_name localhost;

    index index.html index.htm index.php;

    root /usr/local/nginx/html;


    location ~ \.php$ {

      include fastcgi_params;

      fastcgi_pass unix:/tmp/php-fcgi.sock;

      fastcgi_index index.php;

     fastcgi_param SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;

    }


}


}

检验配置:

/usr/local/nginx/sbin/nginx  -t

service nginx start

vim /usr/local/nginx/html/2.php

内容如下:


web环境