lnamp完整版[linux+apache2.4+php5.5.6+mysql5.6]

來源:互聯網
上載者:User

標籤:

Lnamp環境安裝實錄將採用的開源軟體:Apache [必須,WEB動態指令碼伺服器,做nginx的反向 Proxy  8080連接埠]Tengine [必須,WEB靜態檔案伺服器  80連接埠]MySQL [必須]PHP [必須]1.Apache安裝A.apr安裝wget -c http://mirror.bjtu.edu.cn/apache/apr/apr-1.5.1.tar.gztar -zxvf apr-1..5.tar.gzcd apr-1.5.1./configure --prefix=/usr/local/aprmakemake installB.apr-util安裝wget -c wget http://mirror.bjtu.edu.cn/apache/apr/apr-util-1.5.4.tar.gztar -zxvf  apr-util-1.5.4.tar.gzcd apr-util-1.5.4./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/aprmakemake installC.pcre安裝wget -c ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.36.tar.gztar -zxvf pcre-8.36.tar.gzcd pcre-8.36./configure --prefix=/usr/local/pcremakemake installD.apache安裝wget -c http://mirror.symnds.com/software/Apache//httpd/httpd-2.4.10.tar.gztar -zxvf httpd-2.4.10.tar.gzcd httpd-2.4.10./configure --prefix=/usr/local/apache --enable-so-rewrite=shared --with-mpm=prefork 
--with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre如果提示openssl(舊版),運行yum install openssl-develyum update opensslmakemake install E.把apache加入系統service,開機自啟動 cp /usr/local/apache/bin/apachectl /etc/init.d/httpdvim /etc/init.d/httpd# beyound# chkconfig: 35 85 15# description: Apache is a World Wide Web server. chmod +x /etc/init.d/httpd/sbin/chkconfig --add httpd/sbin/chkconfig --list httpdln -s /sbin/chkconfig /usr/bin/chkconfigln -s /sbin/service /usr/bin/service2.MySQL安裝A.準備工作 安裝一些必須的軟體:yum install cmake automake autoconf libtool gcc g++ bisonyum install ncurses-devel mkdir -p /data/mysqlmkdir -p /var/run/mysqldgroupadd mysql //添加一個mysql標準組useradd -g mysql mysql //添加mysql使用者並加到mysql組中 B.下載安裝wget -c http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.11.tar.gz/from/http://cdn.mysql.com/tar -zxvf mysql-5.6.11.tar.gzcd mysql-5.6.11cmake-DCMAKE_INSTALL_PREFIX=/usr/local/mysql #安裝路徑-DMYSQL_DATADIR=/data/mysql/ #資料檔案存放位置-DSYSCONFDIR=/etc #my.cnf路徑-DWITH_MYISAM_STORAGE_ENGINE=1 #支援MyIASM引擎-DWITH_INNOBASE_STORAGE_ENGINE=1 #支援InnoDB引擎-DWITH_MEMORY_STORAGE_ENGINE=1 #支援InnoDB引擎-DWITH_READLINE=1 #快速鍵功能(我沒用過)-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock #串連資料庫socket路徑-DMYSQL_TCP_PORT=3306 #連接埠-DENABLED_LOCAL_INFILE=1 #允許從本地匯入資料-DWITH_PARTITION_STORAGE_ENGINE=1 #安裝支援資料庫分區-DWITH_EXTRA_CHARSETS:STRING=utf8,gbk #安裝需要的字元集-DDEFAULT_CHARSET=utf8 #預設字元-DDEFAULT_COLLATION=utf8_general_ci #預設字元集-DMYSQL_USER=mysql 如果安裝過程中報錯,解決錯誤後重新cmake前需刪除CMakeCache.txt檔案 makemake install C.配置 設定檔這一步中需要注意的是my.cnf的載入順序,Linux優先順序從高到低
/etc/my.cnf->/etc/mysql/my.cnf->SYSCONFDIR/my.cnf->$MYSQL_HOME/my.cnf,
高優先順序的my.cnf設定會覆蓋低優先順序的my.cnf,所以一般把config檔案copy到etc中即可。#如果/etc下沒有my.cnfcp support-files/my-medium.cnf /etc/my.cnfvim /etc/my.cnf [client]default-character-set=utf8port=3306 [mysqld_safe]log-error=/var/log/www/mysql/mysqld.logpid-file=/var/run/mysqld/mysqld.pid [mysqld]datadir=/var/lib/mysql#socket=/var/lib/mysql/mysql.socksocket=/tmp/mysqld.sockuser=mysql# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0 wait-timeout = 30max_connections = 512max_allowed_packet=64Mslow_query_logslow_query_log_file=/var/log/www/mysql/slow.loglog-error = /var/log/www/mysql/error.log #資料目錄的許可權chown mysql.mysql -R /data/mysqlchown -R mysql:mysql /var/run/mysqldchmod +x /usr/local/mysqlchown -R mysql.mysql /usr/local/mysql #資料初始化/usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf
--basedir=/usr/local/mysql --datadir=/data/mysql --user=mysql #設定軟串連使mysql, mysqldump, mysqladmin這三個bin命令能在shell中直接運行ln -s /usr/local/mysql/bin/mysql /usr/binln -s /usr/local/mysql/bin/mysqldump /usr/binln -s /usr/local/mysql/bin/mysqladmin /usr/bin #啟動MySQL/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf
--user=mysql --datadir=/data/mysql & #配置開機自啟動vim /etc/rc.local 添加/usr/local/mysql/bin/mysqld_safe
--defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql & #修改mysql密碼UPDATE user SET password=PASSWORD("newpassword") WHERE user=‘root‘;FLUSH PRIVILEGES; create database db_test; B.建立一個新使用者用於管理 db_test 資料庫insert into mysql.user(Host,User,Password)
values("localhost","admin",password("newpassword"));flush privileges; C.賦予許可權grant all privileges on db_test.* to [email protected] identified by ‘newpassword‘;3.Tengine[Nginx]安裝A.準備工作需要下載的東西wget -c http://zlib.net/zlib-1.2.8.tar.gztar -zxvf zlib-1.2.8.tar.gz wget -c http://www.openssl.org/source/openssl-1.0.1e.tar.gztar -zxvf openssl-1.0.1e.tar.gz wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz tar zxvf ngx_cache_purge-2.3.tar.gz groupadd www //添加一個www標準組useradd -g www www //添加www使用者並加到www組中 B.下載安裝 wget -c http://tengine.taobao.org/download/tengine-2.1.0.tar.gztar -zxvf tengine-2.1.0.tar.gzcd tengine-2.1.0 ./configure --user=www --group=www --prefix=/usr/local/nginx
--with-http_stub_status_module --with-http_sub_module --with-http_realip_module
--with-http_flv_module --with-http_dav_module --with-http_gzip_static_module
--with-http_addition_module --with-http_ssl_module
--with-openssl=../openssl-1.0.1h
--with-pcre=../pcre-8.36
--with-zlib=../zlib-1.2.8
--add-module=/usr/local/src/ngx_cache_purge-2.3make make install C.配置 vim /etc/init.d/nginx #! /bin/sh # Author: rui ding # Modified: Geoffrey Grosenbach http://topfunky.com # Modified: Clement NEDELCU # Reproduced with express authorization from its contributors set -e PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DESC="nginx daemon" NAME=nginx DAEMON=/usr/local/nginx/sbin/$NAME SCRIPTNAME=/etc/init.d/$NAME # If the daemon file is not found, terminate the script. test -x $DAEMON || exit 0 start() { $DAEMON || echo -n " already running" } stop() { $DAEMON -s quit || echo -n " not running" } reload() { $DAEMON -s reload || echo -n " could not reload" } case "$1" in start) echo -n "Starting $DESC: $NAME" start echo "." ;; stop) echo -n "Stopping $DESC: $NAME" stop echo "." ;; reload) echo -n "Reloading $DESC configuration..." reload echo "reloaded." ;; restart) echo -n "Restarting $DESC: $NAME" stop # Sleep for two seconds before starting again, this should give the # Nginx daemon some time to perform a graceful stop. sleep 2 start echo "." ;; *) echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2 exit 3 ;; esac exit 0 chmod +x /etc/init.d/nginx service nginx startservice nginx reloadservice nginx restartservice nginx stop vim /etc/rc.local 添加一行/usr/local/nginx/sbin/nginx & 4.PHP編譯安裝A.yum安裝相關庫包 yum install gd-devel php-gdyum install zlib zlib-develyum install freetype-devel freetype-demos freetype-utilsyum install libpng libpng-devel libpng10 libpng10-develyum install libjpeg libjpeg-develyum install ImageMagickyum install flexyum install ImageMagick-develyum install libxml2 libxml2-develyum install libxml2 curl curl-develyum -y install libtool libtool-ltdl-develyum install mhash-develyum install patch B.可能需要源碼編譯的包 wget -c ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gztar -zxvf libmcrypt-2.5.7.tar.gzcd libmcrypt-2.5.7./configure --prefix=/usr/local/libmcryptmake && make install wget -c http://iweb.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gztar -zxvf mhash-0.9.9.9.tar.gzcd mhash-0.9.9.9./configure --prefix=/usr/local/libmhashmake && make install C.編譯安裝 wget -c http://cn2.php.net/get/php-5.6.6.tar.gz/from/this/mirrortar -zxvf php-5.6.6.tar.gzcd php-5.6.6 ./configure --prefix=/usr/local/php
--with-config-file-path=/usr/local/php/etc
--with-mysql=/usr/local/mysql/
--with-mysqli=/usr/local/mysql/bin/mysql_config
--with-apxs2=/usr/local/apache/bin/apxs
--with-iconv-dir=/usr/local
--with-freetype-dir
--with-jpeg-dir --with-png-dir --with-zlib
--with-libxml-dir=/usr --enable-xml --disable-rpath
--enable-discard-path --enable-safe-mode --enable-bcmath
--enable-shmop --enable-sysvsem --enable-sysvshm --enable-sysvmsg --enable-inline-optimization
--with-curl --with-curlwrappers --enable-mbregex --enable-fpm
--enable-fastcgi --enable-force-cgi-redirect
--enable-mbstring --with-mcrypt=/usr/local/libmcrypt
--with-gd --enable-gd-native-ttf --with-openssl
--with-mhash --enable-pcntl --enable-sockets
--with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap
--enable-ftp --enable-sigchild
--with-pear --enable-cli --enable-exif
--enable-calendar --with-bz2 --enable-pdo --with-pdo-mysql --enable-freetype --disable-fileinfo configure: error: Cannot find ldap.hyum install openldapyum install openldap-devel Configure: error: Please reinstall the BZip2 distributioncentos: yum install bzip2 bzip2-devel 錯誤:configure: error: Cannot find ldap libraries in /usr/lib解決辦法:cp -frp /usr/lib64/libldap* /usr/lib/ 錯誤:configure: error: Unable to find your mysql installation解決辦法:ln -s /usr/local/mysql/bin/mysql_config /usr/bin/mysql_config 編譯出錯後重新編譯時間需先make clean再make makemake install修改apache的設定檔httpd.conf  vim /usr/local/apache/conf/httpd.conf  然後在文本最後面添加  LoadModule php5_module modules/libphp5.so
(注意,在apache安裝目錄下,modules下有libphp5.so,這是php安裝時添加進去的,如果沒有,php,你需要重裝下)AddType application/x-httpd-php .php (.前面有空格)AddType application/x-httpd-php .html cp php.ini-production /usr/local/php/etc/php.ini 5.環境整合A.整合apache mkdir -p /home/www/test.comchown -R www.www /home/www apache將被nginx代理,因此將apache的預設監聽連接埠改為8080 vim /usr/local/apache/conf/httpd.conf 將hosts定向到 Include conf/extra/httpd-vhosts.confListen 8080 User wwwGroup www <IfModule dir_module> DirectoryIndex index.php index.html index.htm</IfModule> vim /usr/local/apache/conf/extra/httpd-vhosts.conf將裡面的*:80全部改成yourdomain.name:8080並添加虛擬hosts <VirtualHost *:8080> ServerAdmin [email protected] DocumentRoot "/home/www/test.com" DirectoryIndex index.php index.html ServerName a.test.com <Directory "/home/www/a.test.com"> AllowOverride None Options None Require all granted </Directory> ErrorLog "/var/log/www/apache/a.test.com-error_log" CustomLog "/var/log/www/apache/a.test.com-access_log" common</VirtualHost> vim /home/www/test.com/phpinfo.php <?phpphpinfo(); service httpd start,訪問http://a.test.com:8080/phpinfo.php B.配置php-fpm cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf#開啟php-fpm慢指令碼日誌request_slowlog_timeout = 30slowlog = /var/log/www/php/php-fpm.log.slow #指令碼等待時間request_terminate_timeout = 120 pid = /usr/local/php/var/run/php-fpm.piderror_log = /var/log/www/php/php-fpm.log.errorlog_level = notice user = wwwgroup = www listen = 127.0.0.1:9000pm = dynamicpm.max_children = 100pm.start_servers = 10pm.min_spare_servers = 5pm.max_spare_servers = 100pm.max_requests = 1000 /usr/local/php/sbin/php-fpm #將php-fpm整合成系統服務 vim /etc/init.d/php-fpm #! /bin/sh### BEGIN INIT INFO# Provides: php-fpm# Required-Start: $remote_fs $network# Required-Stop: $remote_fs $network# Default-Start: 2 3 4 5# Default-Stop: 0 1 6# Short-Description: starts php-fpm# Description: starts the PHP FastCGI Process Manager daemon### END INIT INFO prefix=/usr/local/phpexec_prefix=${prefix} php_fpm_BIN=${exec_prefix}/sbin/php-fpmphp_fpm_CONF=${prefix}/etc/php-fpm.confphp_fpm_PID=${prefix}/var/run/php-fpm.pid php_opts="--fpm-config $php_fpm_CONF" wait_for_pid () { try=0 while test $try -lt 35 ; do case "$1" in ‘created‘) if [ -f "$2" ] ; then try=‘‘ break fi ;; ‘removed‘) if [ ! -f "$2" ] ; then try=‘‘ break fi ;; esac echo -n . try=`expr $try + 1` sleep 1 done } case "$1" in start) echo -n "Starting php-fpm " $php_fpm_BIN $php_opts if [ "$?" != 0 ] ; then echo " failed" exit 1 fi wait_for_pid created $php_fpm_PID if [ -n "$try" ] ; then echo " failed" exit 1 else echo " done" fi ;; stop) echo -n "Gracefully shutting down php-fpm " if [ ! -r $php_fpm_PID ] ; then echo "warning, no pid file found - php-fpm is not running ?" exit 1 fi kill -QUIT `cat $php_fpm_PID` wait_for_pid removed $php_fpm_PID if [ -n "$try" ] ; then echo " failed. Use force-quit" exit 1 else echo " done" fi ;; force-quit) echo -n "Terminating php-fpm " if [ ! -r $php_fpm_PID ] ; then echo "warning, no pid file found - php-fpm is not running ?" exit 1 fi kill -TERM `cat $php_fpm_PID` wait_for_pid removed $php_fpm_PID if [ -n "$try" ] ; then echo " failed" exit 1 else echo " done" fi ;; restart) $0 stop $0 start ;; reload) echo -n "Reload service php-fpm " if [ ! -r $php_fpm_PID ] ; then echo "warning, no pid file found - php-fpm is not running ?" exit 1 fi kill -USR2 `cat $php_fpm_PID` echo " done" ;; *) echo "Usage: $0 {start|stop|force-quit|restart|reload}" exit 1 ;; esac chmod +x /etc/init.d/php-fpm service php-fpm startservice php-fpm stopservice php-fpm reloadservice php-fpm restart #開機啟動vim /etc/rc.local添加一行/usr/local/php/sbin/php-fpm & C.Nginx整合 mkdir /usr/local/nginx/conf/vhosts vim /usr/local/nginx/conf/nginx.conf user www www;worker_processes 8; error_log /var/log/www/nginx/error.log crit;#error_log /var/log/www/nginx/error.log notice;#error_log /var/log/www/nginx/error.log info; #pid logs/nginx.pid; worker_rlimit_nofile 65535;events { use epoll; worker_connections 1024;} http { include mime.types; default_type application/octet-stream; log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘ ‘$status $body_bytes_sent "$http_referer" ‘ ‘"$http_user_agent" "$http_x_forwarded_for"‘; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 8m; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 128k; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.0; gzip_comp_level 2; gzip_types text/plain application/x-javascript text/css application/xml; gzip_vary on; include vhosts/*.conf;} vim /usr/local/nginx/conf/vhosts/a.test.com.conf #反向 Proxyupstream www.test { a.test.com:8080;}server { listen 80; server_name www.test.com; charset utf-8; root /home/www/www.test; location / { index index.php index.html index.htm;if (!-e $request_filename) { #rewrite ^(.*)$ /index.php?s=$1 last; #break; } } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ~ \.php$ { #開啟支援php fastcgi_pass 127.0.0.1:9000; #php fastcgi服務地址及連接埠 fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }} service nginx reload D.Apache+nginx+php反向 Proxy vim /usr/local/nginx/conf/vhosts/a.test.com.conf #反向 Proxyupstream www.test{ server a.test.com:8080;}server { listen 80; server_name www.test.com; charset utf-8; root /home/www/test.com; location / { index index.php index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ~ \.php$ { #fastcgi_pass 127.0.0.1:9000; #php fastcgi服務地址及連接埠 #fastcgi_index index.php; #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #include fastcgi_params; proxy_pass http://www.test; #apache反向 Proxy proxy_pass_header User-Agent; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 10m; client_body_buffer_size 128k; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 512k; proxy_buffers 4 512k; proxy_busy_buffers_size 512k; proxy_temp_file_write_size 512k; }} service nginx reload 再訪問 http://www.test.com/phpinfo.php 如,系統已經用apache來解析動態請求了,反向 Proxy配置正確完成

 

   

lnamp完整版[linux+apache2.4+php5.5.6+mysql5.6]

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.