CentOS 6.5編譯安裝Nginx1.6.2+MySQL5.5.32+PHP5.3.27

1、系統及軟件版本

Linux:Centos 6.5php

Nginx:nginx-1.6.2html

Mysql:mysql-5.5.32-linux2.6-x86_64.tarmysql

PHP  :php-5.3.27linux

2、Nginx安裝

①安裝準備pcre ,openssl
yum install pcre pcre-devel -y
yum install openssl openssl-devel -y
②編譯安裝nginx
./configure --user=nginx --group=nginx --prefix=/application/nginx-1.6.2 --with-http_stub_status_module --with-http_ssl_module
make
echo $?
make install
echo $?
ln -s /application/nginx-1.6.2/ /application/nginx
③啓動Nginxnginx

#添加nginx用戶sql

useradd nginx -s /sbin/nologin -M數據庫

#檢測語法vim

/application/nginx/sbin/nginx -t app

#啓動nginx
/application/nginx/sbin/nginx curl

#查80端口檢測服務
netstat -lntup |grep nginx|grep -v grep

④配置站點目錄 

cd /application/nginx/conf

備份配置文件,清除註釋及空行

cp nginx.conf nginx.conf.bak

egrep -v "#|^$" nginx.conf.bak > nginx.conf

vim nginx.conf

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
### 日誌格式
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
### 防止惡意域名綁定
    server {
       listen       80;
          location / {
              deny all;
             }
} ### 301跳轉 server { listen
80; server_name panda.org; rewrite ^/(.*) http://www.panda.org/$1 permanent; } ### www主機 server { listen 80; server_name www.panda.org; root html/www; index index.html index.htm; access_log logs/www_access.log; } ### bbs主機 server { listen 80; server_name bbs.panda.org; root html/bbs; index index.html index.htm; access_log logs/bbs_access.log; } ### blog主機 server { listen 80; server_name blog.panda.org; root html/blog; index index.html index.htm; access_log logs/blog_access.log; } }

建立html文件

for n in www bbs blog;do echo "$n.panda.org" > /application/nginx/html/$n/index.html;done
for n in www bbs blog;do cat /application/nginx/html/$n/index.html ;done

 

 檢查語法,重啓服務

/application/nginx/sbin/nginx -t
/application/nginx/sbin/nginx -s reload

 

本地解析,關閉防火牆,檢測站點

echo "192.168.174.20 www.panda.org bbs.panda.org blog.panda.org" >> /etc/hosts
/etc/init.d/iptables stop
for n in www bbs blog;do curl $n.panda.org;done

 

至此Nginx搭建完成!

 

2、Mysql 5.5安裝(二進制包安裝)

 ①解壓及初始化數據庫

tar xf mysql-5.5.32-linux2.6-x86_64.tar.gz 
mv mysql-5.5.32-linux2.6-x86_64 /application/mysql
useradd mysql -s /sbin/nologin -M
chown -R mysql.mysql /application/mysql/data
cd /application/mysql/
./scripts/mysql_install_db --user=mysql --basedir=/application/mysql/ --datadir=/application/mysql/data/

 

 

 ②生成啓動文件及配置文件

啓動文件

cp support-files/mysql.server /etc/init.d/mysqld
 sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld_safe
vim /etc/init.d/mysqld

修改:

basedir=/application/mysql
datadir=/application/mysql/data/

sed -i 's#/usr/local/mysql#/application/mysql#g' /etc/init.d/mysqld

生成配置文件,並啓動服務

cp support-files/my-small.cnf /etc/my.cnf
/etc/init.d/mysqld start
/etc/init.d/mysqld status

③配置環境變量,進入MySQL

配置環境變量

法一:

echo 'export PATH=$PATH:/application/mysql/bin' >> /etc/profile
source /etc/profile

法二:

cp /application/mysql/bin/* /usr/local/sbin/

法三:

vi /etc/profile
PATH=/application/mysql/bin:$PATH

 配置MySQL帳戶密碼並登錄

mysqladmin -uroot password "123456"
mysql -uroot -p

 3、PHP安裝配置

①依賴包、編譯安裝PHP

yum install zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel -y
tar xf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
make && make install
安裝libmcrypt庫(更換epel源,簡易安裝方法)
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
yum install libmcrypt-devel -y
安裝mhash庫(epel源)
yum install mhash mhash-devel -y
安裝mcrypt庫(epel源)
yum install mcrypt -y
yum install libxslt libxslt-devel -y

編譯安裝php

tar xf php-5.3.27.tar.gz
cd php-5.3.27
./configure --prefix=/application/php5.3.27 --with-mysql=/application/mysql --with-iconv-dir=/usr/local/libiconv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-short-tags --enable-zend-multibyte --enable-static --with-xsl --with-fpm-user=nginx --with-fpm-group=nginx --enable-ftp

 

ln -s /application/mysql/lib/libmysqlclient.so.18 /usr/lib64/
touch ext/phar/phar.phar
make
make install
ln -s /application/php5.3.27/ /application/php

②配置php.ini及php-fpm.conf

cp php.ini-production /application/php/lib/php.ini
cd /application/php/etc/
cp php-fpm.conf.default php-fpm.conf
mkdir -p /app/logs

啓動php服務

/application/php/sbin/php-fpm

③nginx結合php

vim /application/nginx/conf/nginx.conf
### blog主機
    server {
        listen       80;
        server_name  blog.panda.org;
        location /{
            root   html/blog;
            index  index.html index.htm;
            }
        location ~.*\.(php|php5)?$ {
            root   html/blog;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi.conf;
            }
        access_log logs/blog_access.log main;
    }
/application/nginx/sbin/nginx -s reload

④測試nginx+php

cd /application/nginx/html/www/
vim phpinfo.php
<?php
phpinfo();
?>

打開網頁http://www.panda.org/phpinfo.php驗證(注意本機host解析)

 

⑤測試鏈接Mysql數據庫

cd /application/nginx/html/www/
vim test_sql.php
<?php
$link_id=mysql_connect('localhost','root','123456') or mysql_error();
if($link_id){
       echo"mysql successful by panda!";
        }else{
           echo mysql_error();
           }
?>

網頁測試 http://www.panda.org/test_sql.php

 

至此基本的LNMP環境搭建完成!

CentOS 6.6編譯安裝Nginx1.6.2+MySQL5.6.21+PHP5.6.3

CentOS 7.2.1511編譯安裝Nginx1.10.1+MySQL5.7.14+PHP7.0.11

相關文章
相關標籤/搜索