linux 源码搭建lnmp_LINUX CENTOS 6.5下源码搭建LNMP
本機IP:192.168.1.18
操作系統:
一.源碼安裝nginx
1.安裝依賴包
yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre* make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel
2.獲取nginx軟件包
wget http://nginx.org/download/nginx-1.9.15.tar.gz
3.源碼安裝nginx
建立nginx用戶
useradd nginx -s /sbin/nologin -M
解壓安裝包
tar -zxvf nginx-1.9.15.tar.gz
進入解壓后目錄
cd nginx-1.9.15
編譯參數./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module --with-pcre
#用4個線程編譯安裝
make -j 4 && make install
4.編輯nginx配置文件,使其支持fastcgi功能
cd /usr/local/nginx/conf/
cp nginx.conf nginx.conf.`date +%F` 備份配置文件
vim nginx.conf
#############
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
}
}
5.編寫Nginx啟動腳本
cd /etc/init.d/
vim nginx
##########
#!/bin/bash
#chkconfig: 2345 89 89
#Description:This is Nginx web script"
PID="/usr/local/nginx/logs/nginx.pid"
start(){
/usr/local/nginx/sbin/nginx
if [ $? -eq 0 ];then
echo -en "Starting Nginx...\t\t\t["
echo -en "\033[32;34mOK\033[0m"
echo "]"
else
echo "Starting Nginx Error"
fi
}
stop(){
/usr/local/nginx/sbin/nginx -s stop
if [ $? -eq 0 ];then
echo -en "Stop Nginx...\t\t\t["
echo -en "\033[32;34mOK\033[0m"
echo "]"
else
echo "Stop Nginx Error"
fi
}
status(){
if [ -f $PID ];then
ID=$(cat $PID)
echo "Ngix($ID) is running..."
else
echo "Nginx is stop"
fi
}
case $1 in
start)
start;;
stop)
stop;;
restart)
stop
start
;;
status)
status;;
*)
echo "Usage:$0 {start|stop|restart|status}"
esac
5.啟動nginx
iptables -I INPUT -p tcp --dport 80 -j ACCEPT #防火墻規則
chmod +x /etc/init.d/nginx #腳本賦予執行權限
chkconfig --add nginx ?#開機啟動項中加載nginx
chkconfig nginx on #開啟
service nginx start #啟動nginx服務
Starting Nginx... [OK]
二.源碼安裝php
鏈接:http://pan.baidu.com/s/1c14SaIk 密碼:xwox
yum -y install lrzsz (安裝上傳工具)
利用上傳工具將源碼包上傳到服務器
2.源碼安裝php
tar -zxvf php-5.5.35.tar.gz
cd php-5.5.35
#預編譯模塊
./configure --prefix=/usr/local/product/php-5.5.35 --with-config-file-path=/usr/local/product/php-5.5.35/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath
#編譯安裝
make -j 4 && make install
#軟連接目錄到/usr/local/下
ln -s /usr/local/product/php-5.5.35 /usr/local/php
cp php.ini-production /usr/local/php/etc/php.ini
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
#編輯/etc/下php配置文件
vim php.ini
需要修改以下幾個參數:
max_execution_time = 300
post_max_size = 16M
max_input_time = 300
date.timezone = PRC
4.啟動PHP服務
cd /usr/local/php/sbin/
./php-fpm
5.檢查php是否啟動成功
netstat -untalp | grep :9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 103859/php-fpm
三.源碼安裝mysql
1.創建mysql用戶
groupadd mysql
#創建mysql用戶的數據目錄
mkdir -pv /data/mysql
useradd -r -g mysql -d /yinzhengjie/data/mysql/ -s /sbin/nologin mysql
2.獲取mysql軟件包
3更換國內阿里云源
#替換原有yum源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
#清空yum緩存
yum clean all
#生成新的yum緩存
yum makecache
4.安裝依賴包
yum -y install cmake gcc* ncurses-devel
5.源碼安裝mysql
tar -zxvf mysql-5.5.49.tar.gz
cd mysql-5.5.49
#預編譯參數
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/yinzhengjie/data/mysql -DWITH_EXTRA_CHARSETS=all -DWITH_READLINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -
DMYSQL_TCP_PORT=3306 -DDEFAULT_COLLATION=utf8_general_ci
#啟動4個線程編譯安裝
make -j 4 && make install
#改變/usr/local/mysql的屬組
chown -R mysql.mysql /usr/local/mysql
cd /usr/local/mysql/support-files/
6.拷貝mysql配置文件
cp my-medium.cnf /data/mysql/my.cnf
#拷貝啟動腳本到init下
cp mysql.server /etc/init.d/mysqld
#啟動腳本添加執行權限
chmod +x /etc/init.d/mysqld
7.初始化mysql
cd /usr/local/mysql/scripts
./mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/yinzhengjie/data/mysql/
8.修改mysql的數據目錄
vim /etc/my.cnf
[mysqld]
datadir=data/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
#創建目錄,以及軟連接sock
mkdir -pv /var/lib/mysql/ && ln -s /tmp/mysql.sock /var/lib/mysql/
9.啟動mysql
#設置軟連接,以及啟動mysql服務
ln -s /usr/local/mysql/bin/mysql /usr/bin/
ln -s /usr/local/mysql/bin/mysqladmin /usr/bin/
service mysqld start
#設置root用戶登錄mysql數據庫密碼
mysqladmin -uroot password "123456"
總結
以上是生活随笔為你收集整理的linux 源码搭建lnmp_LINUX CENTOS 6.5下源码搭建LNMP的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [翻译]Orchard如何工作
- 下一篇: openwrt php 编译环境,在li