微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Linux环境LNMP搭建

MysqL安装】

1. 下载MysqL到/usr/local/src/

cd /usr/local/src/

wget http://syslab.comsenz.com/downloads/linux/MysqL-5.0.86-linux-i686-icc-glibc23.tar.gz

2. 解压

tar zxvf /usr/local/src/ MysqL-5.0.86-linux-i686-icc-glibc23.tar.gz

3. 把解压完的数据移动到/usr/local/MysqL

mv MysqL-5.0.86-linux-i686-ii-glibc23 /usr/local/MysqL

4. 建立MysqL用户

useradd MysqL

5. 初始化数据库

cd /usr/local/MysqL

mkdir /data/MysqL ; chown -R MysqL:MysqL /data/MysqL

./scripts/MysqL_install_db --user=MysqL --datadir=/data/MysqL

--user定义数据库的所属主,--datadir定义数据库安装到哪里,建议放到大空间的分区上,这个目录需要自行创建。

6. 拷贝配置文件

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

7. 拷贝启动脚本文件修改属性

cp support-files/MysqL.server  /etc/init.d/MysqLd

chmod 755 /etc/init.d/MysqLd

8. 修改启动脚本

vim /etc/init.d/MysqLd

需要修改的地方有datadir=/data/MysqL(前面初始化数据库时定义的目录)

9. 把启动脚本加入系统服务项,并设定开机启动,启动MysqL

chkconfig --add MysqLd

chkconfig MysqLd on

service MysqLd start

如果启动不了,请到/data/MysqL/ 下查看错误日志,该日志格式为主机名.err。

PHP的安装

这里要先声明一下,针对NginxPHP安装和针对apache的PHP安装是有区别的,因为Nginx中的PHP是以fastcgi的方式结合Nginx的,可以理解为Nginx代理了PHP的fastcgi,而apache是把PHP作为自己的模块来调用的。

useradd www

cd /usr/local/src/

wget http://syslab.comsenz.com/downloads/linux/PHP-5.2.10.tar.gz

wget http://syslab.comsenz.com/downloads/linux/PHP-5.2.10-fpm-0.5.13.diff.gz

下载的第二个包PHP-5.2.10-fpm-0.5.13.diff.gz是用来给PHP打补丁的,认情况下,PHP是无法编译出fastcgi的。

tar zxvf PHP-5.2.10.tar.gz

gzip -cd PHP-5.2.10-fpm-0.5.13.diff.gz | patch -d PHP-5.2.10 -p1

cd PHP-5.2.10

./configure --prefix=/usr/local/PHP --with-config-file-path=/usr/local/PHP/etc --with-MysqL=/usr/local/MysqL --with-MysqL-sock=/tmp --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt=/usr/local/libmcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --enable-zend-multibyte --disable-ipv6 --enable-fastcgi --enable-fpm

make && make install

mkdir /usr/local/PHP/etc

cp PHP.ini-dist /usr/local/PHP/etc/PHP.ini  

vim /usr/local/PHP/etc/PHP-fpm.conf

<value name="listen_address">/tmp/PHP-fcgi.sock</value> 这一行要改成这样,这里这样修改了以后,在配置Nginx的时候就需要注意这个路径了。
修改用户和组的名称为”www”
去掉注释,改成这样:
Unix user of processes
                        <value name="user">www</value>
                        Unix group of processes
                        <value name="group">www</value>

/usr/local/PHP/sbin/PHP-fpm start

其他关于PHP的扩展模块安装请参考:

CentOS 5.5下安装mysql5.1.57+php5.2.17(FastCGI)+nginx1.0.1高性能Web服务器

Nginx 安装以及配置

1. Nginx源码安装

cd /usr/local/src/

wget http://syslab.comsenz.com/downloads/linux/Nginx-0.9.6.tar.gz

tar zxvf Nginx-0.9.6.tar.gz

cd Nginx-0.9.6

./configure --prefix=/usr/local/Nginx --sbin-path=/usr/local/Nginx/sbin/Nginx --conf-path=/usr/local/Nginx/conf/Nginx.conf --error-log-path=/usr/local/Nginx/logs/error.log --http-log-path=/usr/local/Nginx/logs/access.log --pid-path=/usr/local/Nginx/var/Nginx.pid --lock-path=/usr/local/Nginx/var/Nginx.lock --http-client-body-temp-path=/dev/shm/Nginx_temp/client_body --http-proxy-temp-path=/dev/shm/Nginx_temp/proxy --http-fastcgi-temp-path=/dev/shm/Nginx_temp/fastcgi --user=www --group=www --with-cpu-opt=pentium4F --without-select_module --without-poll_module --with-http_realip_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module --without-http_ssi_module --without-http_userid_module --without-http_geo_module --without-http_memcached_module --without-http_map_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-pcre

make && make install

mkdir /dev/shm/Nginx_temp

有的Nginx版本编译时会因为pcre编译不过去,需要修改一下 --with-pcre=/usr/local/src/pcre-7.8,前提是已经下载了pcre源码包pcre-7.8.tar.gz,并解压到/usr/local/src/pcre-7.8,不需要编译pcre

2. 编写Nginx的启动脚本,并加入系统服务

vi /etc/init.d/Nginx 写入以下内容

#!/bin/bash
# chkconfig: - 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
Nginx Settings
Nginx_SBIN="/usr/local/Nginx/sbin/Nginx"
Nginx_CONF="/usr/local/Nginx/conf/Nginx.conf"
Nginx_PID="/usr/local/Nginx/var/Nginx.pid"
RETVAL=0
prog="Nginx"
start() {
        echo -n $"Starting $prog: "
        mkdir -p /dev/shm/Nginx_temp
        daemon $Nginx_SBIN -c $Nginx_CONF
        RETVAL=$?
        echo
        return $RETVAL
}
stop() {
        echo -n $"Stopping $prog: "
        killproc -p $Nginx_PID $Nginx_SBIN -TERM
        rm -rf /dev/shm/Nginx_temp
        RETVAL=$?
        echo
        return $RETVAL
}
reload(){
        echo -n $"Reloading $prog: "
        killproc -p $Nginx_PID $Nginx_SBIN -HUP
        RETVAL=$?
        echo
        return $RETVAL
}
restart(){
        stop
        start
}
config@R_404_4876@{
    $Nginx_SBIN -c $Nginx_CONF -t
    return 0
}
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  reload)
        reload
        ;;
  restart)
        restart
        ;;
  configtest)
        configtest
        ;;
  *)
        echo $"Usage: $0 {start|stop|reload|restart|configtest}"
        RETVAL=1
esac

exit $RETVAL

保存后,更改/etc/init.d/Nginx的权限

chmod 755 /etc/init.d/Nginx

chkconfig --add Nginx

chkconfig Nginx on

3. Nginx的配置

vim /usr/local/Nginx/conf/Nginx.conf

把原来的文件清空,然后粘贴如下内容

user www www;

worker_processes 2;

error_log /usr/local/Nginx/logs/Nginx_error.log crit;

pid /usr/local/Nginx/var/Nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process.

worker_rlimit_nofile 51200;

events

{

use epoll;

worker_connections 6000;

}

http

{

include mime.types;

default_type application/octet-stream;

server_names_hash_bucket_size 2048;

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 www.example.com;

index index.html index.htm index.PHP;

root /data/www;

location ~ \.PHP$ {

include fastcgi_params;

fastcgi_pass unix:/ PHP-fcgi.sock;

fastcgi_index index.PHP;

fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;

}

}

保存后就可以启动Nginx了,在重启之前最好先检查一下是否有问题

/usr/local/Nginx/sbin/Nginx  -t   如果显示 "Syntax is ok  和  Nginx.conf was tested successfully"这样的信息,就说明配置没有问题了,否则就需要根据提示修改了。
service Nginx start

如果启动不了,请到/usr/local/Nginx/logs/目录下查看Nginx_error.log这个日志文件。若是没有这个日志文件,很有可能是那个目录没有写权限,请执行

chmod +w /usr/local/Nginx/logs/
service  Nginx  restart

测试是否解析PHP文件

 

vim /data/www/1.PHP

写入如下内容

<?PHP
PHPinfo();
?>

然后设定hosts文件,访问 www.***.com/1.PHP 看是否能解析出这个页面

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐