LNMP安装配置
关闭SELINUX
[root@localhost]# vi /etc/selinux/config #SELINUX=enforcing #注释掉 #SELINUXTYPE=targeted #注释掉 SELINUX=disabled #增加 [root@localhost]# shutdown -r now #重启系统
安装mysql
[root@localhost]# yum -y install mysql-server mysql mysql-devel
安装ngnix
安装GCC编译器及相关工具
[root@localhost]# yum -y install gcc gcc-c++ autoconf automake
安装模块依赖的库
[root@localhost]# yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel libxml2-devel libxml2 openssl-devel curl curl-devel libjpeg-devel libpng libpng-devel freetype-devel library-devel library libmcrypt libmcrypt-devel
更新系统时间,让对时服务开机启动
[root@localhost]# ntpdate time.nist.gov [root@localhost]# chkconfig ntpd on
直接yum安装
[root@localhost]# yum install -y nginx
启动nginx
[root@localhost]# service ngnix start
安装PHP
[root@localhost]# cd /etc/yum.repos.d [root@localhost]# wget http://dev.centos.org/centos/5/CentOS-Testing.repo [root@localhost]# rpm –import http://dev.centos.org/centos/RPM-GPG-KEY-CentOS-testing [root@localhost]# yum install -y php php-mysql php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash libmcrypt libmcrypt-devel php-fpm #启动php-fpm [root@localhost]# /etc/rc.d/init.d/php-fpm start 设置自动启动 [root@localhost]# chkconfig php-fpm on
配置nginx支持php
[root@localhost]# cp /etc/nginx/nginx.conf /etc/nginx/nginx.confbak [root@localhost]# vi /etc/nginx/nginx.conf #修改nginx运行账号为:nginx组的nginx用户 [root@localhost]# user nginx nginx; [root@localhost]# cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.confbak [root@localhost]# vi /etc/nginx/conf.d/default.conf #增加index.php index index.php index.html index.htm; 取消FastCGI server部分location的注释,并要注意fastcgi_param行的参数,改为$document_root$fastcgi_script_name,或者使用绝对路径
配置php-fpm
[root@localhost]# cp /etc/php-fpm.d/www.conf /etc/php-fpm.d/www.confbak [root@localhost]# vi /etc/php-fpm.d/www.conf #修改用户为nginx user = nginx #修改组为nginx group = nginx
安装MYSQL
[root@localhost]# yum -y install mysql mysql-server 启动mysql [root@localhost]# service mysqld start [root@localhost]# chkconfig mysqld on #设为开机启动
为root账户设置密码
[root@localhost]# mysql_secure_installation
重启所有服务
[root@localhost]# service mysqld restart [root@localhost]# service nginx restart [root@localhost]# /etc/rc.d/init.d/php-fpm restart
PHP编译安装参数
[root@localhost]# ./configure --prefix=/etc/php/ --with-config-file-path=/etc/php/etc --with-mysql --with-mysqli --with-pdo-mysql --with-libxml-dir --with-gd --with-freetype-dir --with-curl --with-xmlrpc --with-curl --with-zlib --with-jpeg-dir --with-png-dir --with-openssl --enable-fpm --enable-static --disable-inline-optimization --enable-sockets --enable-zip --enable-calendar --enable-bcmath --enable-soap --enable-ftp --with-mcrypt --enable-shared --disable-fileinfo
[root@localhost]# vi /usr/local/php5/etc/php.ini #编辑配置文件修改为:
disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname #列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。 找到:;date.timezone = 修改为:date.timezone = PRC #设置时区 找到:expose_php = On 修改为:expose_php = OFF #禁止显示php版本的信息 找到:short_open_tag = Off 修改为:short_open_tag = ON #支持php短标签
配置nginx支持php
[root@localhost]# vi /usr/local/nginx/conf/nginx.conf #编辑配置文件,需做如下修改 user www www; #首行user去掉注释,修改Nginx运行组为www www;必须与/usr/local/php5/etc/php-fpm.conf中的user,group配置相同,否则php运行出错 index index.php index.html index.htm; #添加index.php # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } #取消FastCGI server部分location的注释,并要注意fastcgi_param行的参数,改为$document_root$fastcgi_script_name,或者使用绝对路径 /etc/init.d/nginx restart #重启nginx cd /usr/local/nginx/html/ #进入nginx默认网站根目录 rm -rf /usr/local/nginx/html/* #删除默认测试页 vi index.php #编辑 chown www.www /usr/local/nginx/html/ -R #设置目录所有者 chmod 700 /usr/local/nginx/html/ -R #设置目录权限
[root@localhost]# shutdown -r now #重启系统
在浏览器中打开服务器IP地址,会看到下面的界面,配置成功
服务器相关操作命令
[root@localhost]# service nginx restart #重启nginx [root@localhost]# service mysql restart #重启mysql [root@localhost]# /usr/local/php5/sbin/php-fpm #启动php-fpm [root@localhost]# /etc/rc.d/init.d/php-fpm restart #重启php-fpm ############################################################################# 备注: nginx默认站点目录是:/usr/local/nginx/html/ 权限设置:chown www:www /usr/local/nginx/html/ -R MySQL数据库目录是:/data/mysql 权限设置:chown mysql.mysql -R /data/mysql
安装redis扩展
注意:目录的权限 chomd 777 -R 1、安装redis 下载:https://github.com/nicolasff/phpredis/archive/2.2.4.tar.gz 上传phpredis-2.2.4.tar.gz到/usr/local/src目录 [root@localhost]# cd /usr/local/src #进入软件包存放目录 [root@localhost]# tar zxvf phpredis-2.2.4.tar.gz #解压 [root@localhost]# cd phpredis-2.2.4 #进入安装目录 [root@localhost]# /usr/local/php/bin/phpize #用phpize生成configure配置文件 [root@localhost]# ./configure --with-php-config=/usr/local/php/bin/php-config #配置 [root@localhost]# make #编译 [root@localhost]# make install #安装 安装完成之后,出现下面的安装路径 [root@localhost]# /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/ 2、配置php支持 [root@localhost]# vi /usr/local/php/etc/php.ini #编辑配置文件,在最后一行添加以下内容 添加 extension="redis.so" 然后重启服务