Alibaba Cloud Linux 手动编译Nginx+php+mysql 实操记录
需求:在Alibaba Cloud Linux下自行手动编译Nginx + PHP + mysql 环境,既能学习到环境配置,又能体会Diy动手的乐趣**** 本内容需购买可见 ****."
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
chkconfig--add nginx
chkconfig nginx on
service nginx start #启动
/server/nginx/sbin/nginx -t
正常:
nginx: the configuration file /server/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /server/nginx/conf/nginx.conf test is successful
2.安装php 7.2.34
编译:
wget http://am1.php.net/distributions/php-7.2.34.tar.gz
tar -zvxf php-7.2.34.tar.gz
cd php-7.2.34/
./configure --prefix=/server/php72 --with-config-file-path=/server/php72/ect --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip --with-ldap
make -j 4
make install
配置文件:
cp /root/php-7.2.34/php.ini-development /server/php72/etc/php.ini
cp /server/php72/etc/php-fpm.conf.default /server/php72/etc/php-fpm.conf
cp /server/php72/etc/php-fpm.d/www.conf.default /server/php72/etc/php-fpm.d/www.conf
添加系统变量:
echo 'export PATH=/server/php72/bin/:/server/php72/sbin:$PATH' >> /etc/profile
source /etc/profile
php -v
正常显示。
编辑配置文件
vi /server/php72/etc/php.ini
改:
request_order = "GP" 为 request_order = "CGP"
改:;cgi.force_redirect = 1 为 cgi.force_redirect = 0
vi /server/php72/etc/php-fpm.d/www.conf
改:
user =
group = 为
user = www
group = www
自启动:
vi /etc/init.d/php-fpm72
内容:
#! /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=/server/php72
exec_prefix=${prefix}
php_fpm_BIN=${exec_prefix}/sbin/php-fpm
php_fpm_CONF=${prefix}/etc/php-fpm.conf
php_fpm_PID=${prefix}/var/run/php-fpm.pid
php_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID"
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 --daemonize $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
;;
status)
if [ ! -r $php_fpm_PID ] ; then
echo "php-fpm is stopped"
exit 0
fi
PID=`cat $php_fpm_PID`
if ps -p $PID | grep -q $PID; then
echo "php-fpm (pid $PID) is running..."
else
echo "php-fpm dead but pid file exists"
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|status}"
exit 1
;;
esac
保存
chmod +x php-fpm72
chkconfig--add php-fpm72
chkconfigphp-fpm72 on
service php-fpm72 start
关联nginx
# 编写php部分
location ~ .*\.(php|php5)?$
{
#fastcgi_passunix:/tmp/php-cgi.sock;
fastcgi_pass127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
3.安装mysql
wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.51.tar.gz
tar xvf mysql-5.6.51.tar.gz
cd mysql-5.6.51
cmake \
-DCMAKE_INSTALL_PREFIX=/server/mysql \
-DMYSQL_DATADIR=/data/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
make && make install
编译完成
添加mysql用户
groupadd mysql
useradd -g mysql mysql
执行初始化:
cd /server/mysql
scripts/mysql_install_db --basedir=/server/mysql --datadir=/server/mysql/data --user=mysql
自启动:
cp support-files/mysql.server /etc/init.d/mysql
chkconfig mysql on
service mysql start
配置变量:
echo 'export PATH=/server/mysql/bin:$PATH' >> /etc/profile
source /etc/profile
登陆数据库修改密码:
mysql -uroot
SET PASSWORD = PASSWORD('xmspace.net');
quit
配置my.cnf
vi /etc/my.cnf
内容
port = 3306
socket = /var/lib/mysql/mysql.sock
prompt="MySQL [\d]> "
no-auto-rehash
port = 3306
socket = /var/lib/mysql/mysql.sock
basedir = /server/mysql
datadir = /server/mysql/data
pid-file = /server/mysql/data/mysql.pid
user = mysql
bind-address = 0.0.0.0
server-id = 1
init-connect = 'SET NAMES utf8mb4'
character-set-server = utf8mb4
skip-name-resolve
#skip-networking
back_log = 300
max_connections = 613
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 256
max_allowed_packet = 500M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 32M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 8M
key_buffer_size = 16M
thread_cache_size = 16
query_cache_type = 1
query_cache_size = 16M
query_cache_limit = 2M
ft_min_word_len = 4
#log_bin = mysql-bin
#binlog_format = mixed
expire_logs_days = 7
log_error = /server/mysql/data/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /server/mysql/data/mysql-slow.log
performance_schema = 0
#lower_case_table_names = 1
skip-external-locking
default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_open_files = 500
innodb_buffer_pool_size = 128M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 16M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
interactive_timeout = 28800
wait_timeout = 28800
quick
max_allowed_packet = 500M
key_buffer_size = 16M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
页:
[1]