#####編譯安裝nginx
(1).
php
[root@lnmp-n nginx-1.4.5]# ./configure --prefix=/usr/local/nginx --user=apache --group=apache --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module && make && make install
(2).編寫啓動腳本
html
#!/bin/bash # # nginx Start up the web server daemon # # chkconfig: 1426 33 22 # description: nginx # # processname: nginx ### BEGIN INIT INFO ### END INIT INFO #source function . /etc/rc.d/init.d/functions #variables NGINX_PID=/usr/local/nginx/logs/nginx.pid NGINX_CONF=/usr/local/nginx/conf/nginx.conf NGINX_BIN=/usr/local/nginx/sbin/nginx #output information function if_no { if [ $2 == 0 ]; then echo -n "nginx is $1 ok!" && success && echo else echo -n "nginx is $1 error!" && faiure && echo fi } #switch case $1 in start) if [ -f ${NGINX_PID} ]; then echo "nginx is already start!" && exit else ${NGINX_BIN} -c ${NGINX_CONF} if_no start $? fi ;; stop) if [ ! -f ${NGINX_PID} ]; then echo "nginx is already stop!" && exit else cat $NGINX_PID | xargs kill -QUIT if_no stop $? fi ;; restart) if [ ! -f ${NGINX_PID} ];then { echo "nginx is already stop!" && echo ${NGINX_BIN} -c ${NGINX_CONF} if_no $1 $? } else cat $NGINX_PID | xargs kill -QUIT if_no stop $? ${NGINX_BIN} -c ${NGINX_CONF} if_no start $? fi ;; "status") if [ -f ${NGINX_PID} ]; then echo "nginx is running!" && exit else echo "nginx is not running!" && exit fi ;; "configtest") $NGINX_BIN -t -c $NGINX_CONF ;; "*") echo "use:{start|stop|restart|status|configtest}" ;; esac
//設置爲開機啓動
mysql
[root@LVS nginx-1.4.6]# chmod +x /etc/init.d/nginxd [root@LVS nginx-1.4.6]# chkconfig --add nginxd [root@LVS nginx-1.4.6]# chkconfig --list|grep nginxd nginxd 0:off 1:on 2:on 3:off 4:on 5:off 6:on
#####編譯安裝mysql
(1).
nginx
[root@lnmp-n mysql-5.5.30]#cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_DATADIR=/data/dbdata \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DMYSQL_UNIX_ADDR=/usr/local/mysql/tmp/mysql.sock \ -DMYSQL_TCP_PORT=3306 \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_EXTRA_CHARSETS=all \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DWITH_SSL=yes\ -DWITH_NDBCLUSTER=1 && make && make install
####編譯安裝mysql5.5 報錯
須要安裝的東西
c++
yum install gcc yum install gcc-c++ yum install cmake.x86_64 yum install make 1.-- Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH) CMake Error at cmake/readline.cmake:83 (MESSAGE): Curses library not found. Please install appropriate package, 解決辦法:安裝ncurses-devel yum -y install ncurses-devel 刪除CMakeCache.txt rm -f CMakeCache.txt
(2).建立mysql用戶
web
[root@lnmp-n mysql-5.5.30]#useradd mysql
(3).建立目錄並受權
sql
[root@lnmp-n mysql-5.5.30]#mkdir -p /data/dbdata [root@lnmp-n mysql-5.5.30]#chown mysql.mysql /usr/local/mysql/ -R [root@lnmp-n mysql-5.5.30]#chown mysql.mysql /data/dbdata
(4).複製配置文件和啓動腳本
shell
[root@lnmp-n mysql-5.5.30]# cp /usr/local/mysql/support-files/my-large.cnf /etc/my.cnf [root@lnmp-n mysql-5.5.30]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
(5).初始化數據庫
數據庫
[root@lnmp-n mysql-5.5.30]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --datadir=/data/dbdata/ --basedir=/usr/local/mysql/
(6).修改用戶密碼
apache
mysql> update user set password=password('mysql') where user='root';
######PHP編譯安裝
(1).
[root@lnmp-n php-5.4.25]# ./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-iconv-dir=/usr/ --with-freetype-dir --with-libxml-dir=/usr --enable-xml --enable-fpm --enable-mbstring --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear
(2).安裝過程當中的錯誤
******
Error..
fopen(http://pear.php.net/install-pear-nozlib.phar): failed to open stream: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution
make: *** [install-pear] Error 1
由於DNS沒有配置的緣由
vim /etc/resolv.conf
***********
configure: error: Cannot find ldap.h
解決:[root@lnmp-n php-5.4.25]# yum install compat-openldap.x86_64 openldap-devel.x86_64
************
configure: error: Cannot find ldap libraries in /usr/lib
解決:cp -frp /usr/lib64/libldap* /usr/lib/
***********
/home/php-5.4.25/sapi/cli/php: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
make: *** [ext/phar/phar.php] Error 127
解決:
執行find命令來查找libmysqlclient.so
[root@yin131 etc]# find / -name libmysqlclient.so
/usr/local/mysql/lib/libmysqlclient.so
/usr/local/src/mysql-5.1.70/libmysql/.libs/libmysqlclient.so
/home/software/mysql-5.5.30/libmysql/libmysqlclient.so
把/usr/local/mysql/lib加入到文件/etc/ld.so.conf中
#####更新配置
[root@yin131 etc]# /sbin/ldconfig -v
*********
Warning: require_once(phar://install-pear-nozlib.phar/index.php): failed to open stream: phar error: invalid url or non-existent phar "phar://install-pear-nozlib.phar/index.php" in /data0/software/php-5.4.25/pear/install-pear-nozlib.phar on line 1236
make[1]: *** [install-pear-installer] Error 255
make: *** [install-pear] E
執行yum install libtool-ltdl-devel
而後刪除PHP解壓目錄,從新解壓configure make && make install
(3).複製PHP的配置文件和php-fpm文件
[root@lnmp-n conf]# cp /home/php-5.4.25/php.ini-production /usr/local/php/php.ini [root@lnmp-n etc]# cp php-fpm.conf.default php-fpm.conf
(4).更改nginx的配置文件
[root@lnmp-n nginx]# vim conf/nginx.conf
放開如下內容,爲對PHP的支持:
location ~ \.php$ {
root html; //默認目錄
fastcgi_pass 127.0.0.1:9000;//監聽端口
fastcgi_index index.php; //瀏覽器中首選的文件格式
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
(5).編輯nginx的文件 fastcgi_params
[root@lnmp-n nginx]# vim conf/fastcgi_params fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name;
(6).啓動nginx和php
[root@lnmp-n nginx]# /etc/init.d/nginxd configtest nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful [root@lnmp-n nginx]# /etc/init.d/nginxd restart nginx is stop ok! [ OK ] nginx is start ok! [ OK ]
//-b後爲監聽端口,與nginx配置文件中的相同,-c後接配置文件
[root@lnmp-n nginx]# /usr/local/php/bin/php-cgi -b 127.0.0.1:9000 -c /usr/local/php/php.ini
#######測試
編寫index.php的測試腳本獲取php的信息
<?php phpinfo(); ?>