一、安装配置nginx。
a) 执行安装nginx操作
wget http://oss.aliyuncs.com/aliyunecs/onekey/nginx/nginx-1.4.4.tar.gz
tar zxvf nginx-1.4.4.tar.gz
cd nginx-1.4.4/
./configure --user=www --group=www --prefix=/usr/local/server/nginx --with-http_stub_status_module --with-http_ssl_module --with-md5=/usr/lib
make && make install
cd ../
b) 配置nginx
vim /usr/local/server/nginx/conf/fastcgi_params
找到SCRIPT_NAME 上面一行增加 此语句
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
c) 配置nginx.conf文件
vim /usr/local/server/nginx/conf/nginx.conf
d)修改配置后检查 是否正常
/usr/local/server/nginx/sbin/nginx -t
#当出现ok successful 则证明ok 再平滑启动nginx
/usr/local/server/nginx/sbin/nginx -s reload
c)配置nginx启动文件
vim /etc/init.d/nginx
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# this script create it by ruijie. at 2014.02.26
# if you find any errors on this scripts,please contact ruijie.
# and send mail to ruijie at gmail dot com.
#
[email protected]
nginxd=/usr/local/server/nginx/sbin/nginx
nginx_config=/usr/local/server/nginx/conf/nginx.conf
nginx_pid=/usr/local/server/nginx/logs/nginx.pid
RETVAL=0
prog="nginx"
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ] && netstat -tunpl | grep nginx &> /dev/null;then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog!"
$nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog!"
$nginxd -s stop
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/nginx
}
# reload nginx service functions.
reload() {
echo -n $"Reloading $prog!"
#kill -HUP `cat ${nginx_pid}`
$nginxd -s reload
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|help}"
exit 1
esac
exit $RETVAL
chmod +x /etc/init.d/nginx
/etc/init.d/nginx start
二、安装配置mysql
a)安装cmake软件
下载选择地址:http://www.cmake.org/cmake/resources/software.html
wget http://www.cmake.org/files/v3.0/cmake-3.0.0.tar.gz
tar zxvf cmake-3.0.0.tar.gz
cd cmake-3.0.0
./bootstrap
make
make install
cd ../
b)安装mysql源码
wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.19.tar.gz
yum install gcc gcc-c++ libtool autoconf automake imake mysql-devel libxml2-devel expat-devel
/usr/sbin/groupadd mysql
/usr/sbin/useradd -M -g mysql mysql
mkdir -p /www/data/mysql
tar zxvf mysql-5.6.19.tar.gz
cd mysql-5.6.19/
/usr/local/bin/cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/server/mysql -DSYSCONFDIR=/etc -DMYSQL_DATADIR=/www/mysql/data
/usr/local/bin/cmake . \
-DCMAKE_BUILD_TYPE:STRING=Release \
-DCOMMUNITY_BUILD:BOOL=ON \
-DENABLED_PROFILING:BOOL=ON \
-DENABLE_DEBUG_SYNC:BOOL=OFF \
-DINSTALL_LAYOUT:STRING=STANDALONE \
-DMYSQL_MAINTAINER_MODE:BOOL=OFF \
-DWITH_EMBEDDED_SERVER:BOOL=ON \
-DWITH_EXTRA_CHARSETS:STRING=all \
-DWITH_SSL:STRING=bundled \
-DWITH_UNIT_TESTS:BOOL=OFF \
-DWITH_ZLIB:STRING=bundled \
-LH
make
make install
mkdir -p /www/mysql/data
/usr/local/server/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/server/mysql --datadir=/www/mysql/data
chown -R mysql:mysql /www/mysql/data
chmod -R 755 /www/mysql/data
chmod +w /www/mysql/data
chown -R mysql:mysql /usr/local/server/mysql
cp -rf support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod 755 /etc/rc.d/init.d/mysqld
/sbin/chkconfig --add mysqld
/sbin/chkconfig mysqld on
cp -rf /usr/local/server/mysql/bin/* /usr/sbin
ln -s /usr/local/server/mysql/lib/mysql /usr/lib/mysql
ln -s /usr/local/server/mysql/include/mysql /usr/include/mysql
cd ../
b.1) 编辑配置文件
vim /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
log-bin=mysql-bin
binlog_format=mixed
server-id = 1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
END
b.2) 启动mysql
chmod 755 /etc/init.d/mysqld
/etc/init.d/mysqld start
b.3) 修改数据库密码
/usr/local/server/mysql/bin/mysqladmin -uroot password 123456
三、安装php软件
1)安装前准备 php所需软件
1.1) libmcrypt
wget http://iweb.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure
make
make install
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make
make install
cd ../
1.2) mhash
wget http://ncu.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.bz2
tar jxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make
make install
cd ../
ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
1.3) mcrypt
wget http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz
ln -s /usr/local/bin/libmcrypt_config /usr/bin/libmcrypt_config
export LD_LIBRARY_PATH=/usr/local/lib: LD_LIBRARY_PATH
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make
make install
cd ../
(注)安装报错解决网址:http://blog.csdn.net/hotlinhao/article/details/24399913
1.4) mcrypt
wget http://ftp.gnu.org/gnu/libiconv/libiconv-1.9.1.tar.gz
tar zxvf libiconv-1.9.1.tar.gz
cd libiconv-1.9.1/
./configure --prefix=/usr/local
make
make install
cd ../
---->>以下选择性安装
wget http://mirrors-au.go-parts.com/mirrors/ImageMagick/ImageMagick-6.8.9-3.tar.gz
tar zxvf ImageMagick.tar.gz
cd ImageMagick-6.5.1-2/
./configure
make
make install
cd ../
<<-----
yum install -y gdbm-devel
mkdir -p /usr/local/server/php
2)安装php软件
#目前暂时安装 5.4.29版本。
2.1)编译安装php软件
wget http://cn2.php.net/get/php-5.4.29.tar.gz/from/this/mirror
wget http://cn2.php.net/distributions/php-5.5.4.tar.gz
tar zxvf php-5.4.29.tar.gz
cd php-5.4.29/
./configure --prefix=/usr/local/server/php \
--with-config-file-path=/usr/local/server/php/etc \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--enable-fpm \
--enable-fastcgi \
--enable-static \
--enable-inline-optimization \
--enable-sockets \
--enable-wddx \
--enable-zip \
--enable-calendar \
--enable-bcmath \
--enable-soap \
--with-zlib \
--with-iconv \
--with-gd \
--with-xmlrpc \
--enable-mbstring \
--without-sqlite \
--with-curl \
--enable-ftp \
--with-mcrypt \
--with-freetype-dir=/usr/local/freetype.2.1.10 \
--with-jpeg-dir=/usr/local/jpeg.6 \
--with-png-dir=/usr/local/libpng.1.2.50 \
--disable-ipv6 \
--disable-debug \
--with-openssl \
--disable-maintainer-zts \
--disable-safe-mode \
--disable-fileinfo
编译PHP 会遇到的各种错误:http://lyp.cn/350_how-to-fix-php-compile-errors
make ZEND_EXTRA_LIBS='-liconv' -j4
ln -s /usr/local/server/mysql/lib/libmysqlclient.so /usr/lib64/
ln -s /usr/local/server/mysql/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18
cp /www/soft/php-5.4.29/ext/phar/phar/phar.php phar.phar
make install
cp php.ini-development /usr/local/server/php/etc/php.ini
2.2)建立配置文件
vim /usr/local/server/php/etc/php-fpm.conf
[global]
pid = run/php-fpm.pid
error_log = log/php-fpm.log
log_level = error
emergency_restart_threshold = 0
emergency_restart_interval = 0
process_control_timeout = 0
daemonize = yes
rlimit_files = 32768
[www]
user = www
group = www
listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1
pm = dynamic
pm.max_children = 500
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.process_idle_timeout = 10s;
pm.max_requests = 1024
php_flag[display_errors] = on
2.3)其次:配置init.d.php-fpm
vim sapi/fpm/init.d.php-fpm
改文件作为启动文件,需要配置的就是在开头位置的几个变量值,包括:
1、php_fpm_BIN:指向安装好的php目录/sbin/php-fpm
2、php_fpm_CONF:指向安装好的php目录/etc/php-fpm.conf {如果该配置文件你不是叫这个名字,跟这里应该为你真是得配置名}
3、php_fpm_PID:这里指向php-fpm的pid存放路径。
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod a+x /etc/init.d/php-fpm
/sbin/chkconfig --add php-fpm
/sbin/chkconfig php-fpm on
2.4)安装php自带扩展:
cd /www/soft/php-5.4.29/ext/mysqli
/usr/local/server/php/bin/phpize
./configure --with-php-config=/usr/local/server/php/bin/php-config --with-mysqli=/usr/local/server/mysql/bin/mysql_config
make
make install
cd /www/soft/php-5.4.29/ext/pdo_mysql
/usr/local/server/php/bin/phpize
./configure --with-php-config=/usr/local/server/php/bin/php-config --with-pdo-mysql=/usr/local/server/mysql
make
make install
四、防火墙开启80 ,3306端口
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT #开启8000端口
/etc/rc.d/init.d/iptables save #保存配置
/etc/rc.d/init.d/iptables restart #重启服务
查看端口是否已经开放
/etc/init.d/iptables status
五、下载phpmyadmin管理mysql数据库
选择所需版本:https://www.phpmyadmin.net/downloads/
wget https://files.phpmyadmin.net/phpMyAdmin/4.4.11/phpMyAdmin-4.4.11-all-languages.tar.gz
六、检查安装是否可用
vim /www/htdocs/index.php
//phpinfo();
try {
$user = 'root';
$pass = '123456';
$dbh = new PDO('mysql:host=localhost;dbname=6dmap', $user, $pass);
foreach($dbh->query('SELECT * from test') as $row) {
print_r($row);
}
$dbh = null;
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "
";
die();
}
?>