摘要: 整理的Ubuntu编译安装nginx,php,mysql的步骤,主要来自对驻云的sh-1.4.1中脚本的整理,随时代进步,内容中的软件或者命令请自行更新
目录准备
创建用户
userdel www
groupadd www
useradd -g www -M -d /alidata/www -s /usr/sbin/nologin www &> /dev/null
创建目录
mkdir -p /server
mkdir -p /server/www
mkdir -p /server/log
mkdir -p /server/log/php
mkdir -p /server/log/mysql
mkdir -p /server/log/nginx
mkdir -p /server/log/nginx/access
chown -R www:www /server/log
安装依赖
apt-get -y install unzip build-essential libncurses5-dev libfreetype6-dev libxml2-dev libssl-dev libcurl4-openssl-dev libjpeg62-dev libpng12-dev libfreetype6-dev libsasl2-dev libpcre3-dev autoconf libperl-dev libtool libaio*
Mysql
获取mysql
wget http://zy-res.oss-cn-hangzhou.aliyuncs.com/mysql/mysql-5.6.21-linux-glibc2.5-x86_64.tar.gz
tar -xzvf mysql-5.6.21-linux-glibc2.5-x86_64.tar.gz
mv mysql-5.6.21-linux-glibc2.5-x86_64/* /server/mysql
创建用户
groupadd mysql
useradd -g mysql -s /sbin/nologin mysql
安装mysql
/server/mysql/scripts/mysql_install_db --datadir=/server/mysql/data/ --basedir=/server/mysql --user=mysql
chown -R mysql:mysql /server/mysql/
chown -R mysql:mysql /server/mysql/data/
chown -R mysql:mysql /log/mysql
设置启动文件
cp -f /server/mysql/support-files/mysql.server /etc/init.d/mysqld
sed -i 's#^basedir=$#basedir=/server/mysql#' /etc/init.d/mysqld
sed -i 's#^datadir=$#datadir=/server/mysql/data#' /etc/init.d/mysqld
配置文件
cat > /etc/my.cnf <<END
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-external-locking
log-error=/server/log/mysql/error.log
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-binbinlog_format=mixedserver-id = 1sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysqldump]
quickmax_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 20Msort_buffer_size = 20Mread_buffer = 2Mwrite_buffer = 2M
[mysqlhotcopy]
interactive-timeoutEND
启动
chmod 755 /etc/init.d/mysqld
/etc/init.d/mysqld start
Nginx
获取nginx
wget http://nginx.org/download/nginx-1.10.1.tar.gz
tar zxvf nginx-1.10.1.tar.gz
nginx编译设置
./configure --user=www --group=www --prefix=/server/nginx --with-http_stub_status_module --without-http-cache --with-http_ssl_module --with-http_gzip_static_module
make -j 2(2:多核编译,cat /proc/cpuinfo | grep processor | wc -l获取核心数)
make install
chmod 775 /server/nginx/logs
chown -R www:www /server/nginx/logs
chmod -R 775 /server/www
chown -R www:www /server/www
启动
chmod 755 /server/nginx/sbin/nginx
mv /server/nginx/conf/nginx /etc/init.d/
chmod +x /etc/init.d/nginx
/etc/init.d/nginx start
PHP
获取PHP
wget http://cn2.php.net/distributions/php-5.6.22.tar.gz
tar zxvf php-5.6.22.tar.gz
编译
./configure --prefix=/server/php --enable-opcache --with-config-file-path=/server/php/etc --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=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
make
make install
配置php.ini
cp php-5.6.22/php.ini-production /server/php/etc/php.ini
sed -i 's#; extension_dir = \"\.\/\"#extension_dir = "/server/php/lib/php/extensions/no-debug-non-zts-20131216/"#' /server/php/etc/php.ini
sed -i 's/post_max_size = 8M/post_max_size = 64M/g' /server/php/etc/php.ini
sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 64M/g' /server/php/etc/php.ini
sed -i 's/;date.timezone =/date.timezone = PRC/g' /server/php/etc/php.ini
sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=1/g' /server/php/etc/php.ini
sed -i 's/max_execution_time = 30/max_execution_time = 60/g' /server/php/etc/php.ini
配置php-fpm
cp /server/php/etc/php-fpm.conf.default /server/php/etc/php-fpm.conf
sed -i 's,user = nobody,user=www,g' /server/php/etc/php-fpm.conf
sed -i 's,group = nobody,group=www,g' /server/php/etc/php-fpm.conf
sed -i 's,^pm.min_spare_servers = 1,pm.min_spare_servers = 5,g' /server/php/etc/php-fpm.conf
sed -i 's,^pm.max_spare_servers = 3,pm.max_spare_servers = 35,g' /server/php/etc/php-fpm.conf
sed -i 's,^pm.max_children = 5,pm.max_children = 100,g' /server/php/etc/php-fpm.conf
sed -i 's,^pm.start_servers = 2,pm.start_servers = 20,g' /server/php/etc/php-fpm.conf
sed -i 's,;pid = run/php-fpm.pid,pid = run/php-fpm.pid,g' /server/php/etc/php-fpm.conf
sed -i 's,;error_log = log/php-fpm.log,error_log = /server/log/php/php-fpm.log,g' /server/php/etc/php-fpm.conf
sed -i 's,;slowlog = log/$pool.log.slow,slowlog = /server/log/php/\$pool.log.slow,g' /server/php/etc/php-fpm.conf
启动php-fpm
install -v -m755 php-5.6.22/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
/etc/init.d/php-fpm start
自动随系统启动
在/etc/rc.local
中加入/etc/init.d/mysqld start
,/etc/init.d/nginx start
,/etc/init.d/php-fpm start
加入系统PATH
在/etc/profile
中加入export PATH=$PATH:/server/mysql/bin:/server/nginx/sbin:/server/php/sbin:/server/php/bin