ubuntu编译安装php5 mysql nginx_MySQL
UbuntuNginx
一、首先下载软件源码包
wget http://sysoev.ru/nginx/nginx-0.8.53.tar.gz
wget http:/.s135.com/soft/linux/nginx_php/php/php-5.2.10.tar.gz
wget http:/.s135.com/soft/linux/nginx_php/phpfpm/php-5.2.10-fpm-0.5.11.diff.gz
wget http:/.s135.com/soft/linux/nginx_php/mysql/mysql-5.1.38.tar.gz
wget http:/.s135.com/soft/linux/nginx_php/libiconv/libiconv-1.13.tar.gz
wget http:/.s135.com/soft/linux/nginx_php/mcrypt/libmcrypt-2.5.8.tar.gz
wget http:/.s135.com/soft/linux/nginx_php/mcrypt/mcrypt-2.6.8.tar.gz
wget http:/.s135.com/soft/linux/nginx_php/memcache/memcache-2.2.5.tgz
wget http:/.s135.com/soft/linux/nginx_php/mhash/mhash-0.9.9.9.tar.gz
wget http:/.s135.com/soft/linux/nginx_php/pcre/pcre-7.9.tar.gz
wget http:/.s135.com/soft/linux/nginx_php/eaccelerator/eaccelerator-0.9.5.3.tar.bz2
wget http:/.s135.com/soft/linux/nginx_php/pdo/PDO_MYSQL-1.0.2.tgz
wget http:/.s135.com/soft/linux/nginx_php/imagick/ImageMagick.tar.gz
wget http:/.s135.com/soft/linux/nginx_php/imagick/imagick-2.2.2.tgz
二、安装PHP 5.2.10(FastCGI模式)
1、首先安装PHP 5.2.10所需的支持库
tar zxvf libiconv-1.13.tar.gz
cd libiconv-1.13/
./configure –prefix=/usr/local
make
make install
cd ..
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure
make
make install
cd ..
#在make中途出错的话, apt-get install g++ ,然后重新再做一边
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
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make
make install
cd ..
2、编译安装MySQL 5.1.38
添加mysql用户组和用户
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
tar zxvf mysql-5.1.38.tar.gz
cd mysql-5.1.38/
./configure –prefix=/usr/local/webserver/mysql/ –enable-assembler –with-extra-charsets=complex –enable-thread-safe-client –with-big-tables –with-readline –with-ssl –with-embedded-server –enable-local-infile –with-plugins=innobase
make && make install
chmod +w /usr/local/webserver/mysql
chown -R mysql:mysql /usr/local/webserver/mysql
cd ..
#如果编译过程中出现如下错误
#checking for tgetent in -ltermcap… no
#checking for termcap functions library… configure: error: No curses/termcap library found
#说明 curses/termcap 库没有安装去下载一个ncurses-5.6.tar.gz,
#wget http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.6.tar.gz
#tar zxvf ncurses-5.6.tar.gz
#cd ncurses-5.6
# ./configure –prefix=/usr –with-shared –without-debug
# make
# make install clean
#然后再重新编译Mysql进行安装。
#如果又遇到如下错误:
make[2]: *** [do_abi_check] 错误 1
make[2]: Leaving directory `/tmp/mysql-5.5.3-m3′
make[1]: *** [abi_check] 错误 2
make[1]: Leaving directory `/tmp/mysql-5.5.3-m3′
make: *** [all-recursive] 错误 1
#在网上搜了一下,说是Mysql的一个Bug,解决方法是打开Makefile将do_abi_check:后面的语句删除,注意do_abi_check:需要留下来,然后再 make && make install
附:以下为附加步骤,如果你想在这台服务器上运行MySQL数据库,则执行以下两步。如果你只是希望让PHP支持MySQL扩展库,能够连接其他服务器上的MySQL数据库,那么,以下两步无需执行。
1)、创建MySQL数据库存放目录
mkdir -p /var/webserver/mysql/3306/data
chown -R mysql:mysql /var/webserver/mysql/3306
2)、以mysql用户帐号的身份建立数据表:
/usr/local/webserver/mysql/bin/mysql_install_db –basedir=/usr/local/webserver/mysql –datadir=/var/webserver/mysql/3306/data –user=mysql
3)、创建my.cnf配置文件:
vim /var/webserver/mysql/3306/my.cnf
输入以下内容:
[client]
default-character-set = utf8
port = 3306
socket = /tmp/mysql.sock
[mysql]
prompt=”(/u:blog.s135.com:)[/d]> ”
no-auto-rehash
[mysqld]
#default-character-set = utf8
user = mysql
port = 3306
socket = /tmp/mysql.sock
basedir = /usr/local/webserver/mysql
datadir = /var/webserver/mysql/3306/data
open_files_limit = 10240
back_log = 600
max_connections = 3000
max_connect_errors = 6000
table_cache = 614
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 2M
join_buffer_size = 2M
thread_cache_size = 300
thread_concurrency = 8
query_cache_size = 32M
query_cache_limit = 2M
query_cache_min_res_unit = 2k
default-storage-engine = MyISAM
default_table_type = MyISAM
thread_stack = 192K
transaction_isolation = READ-COMMITTED
tmp_table_size = 246M
max_heap_table_size = 246M
long_query_time = 1
log_long_format
log-bin = /var/webserver/mysql/3306/binlog
binlog_cache_size = 4M
binlog_format = MIXED
max_binlog_cache_size = 8M
max_binlog_size = 512M
expire_logs_days = 7
key_buffer_size = 256M
read_buffer_size = 1M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_max_extra_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
skip-name-resolve
#master-connect-retry = 10
slave-skip-errors = 1032,1062,126,1114,1146,1048,1396
server-id = 1
innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 2048M #如果启动不了Mysql把它改为1024或者增大swap分区的大小
innodb_data_file_path = ibdata1:1024M:autoextend
innodb_file_io_threads = 4
innodb_thread_concurrency = 8
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 16M
innodb_log_file_size = 128M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = 0
[mysqldump]
quick
max_allowed_packet = 32M
4)、创建管理MySQL数据库的shell脚本:
vim /etc/init.d/mysql
输入以下内容:
#!/bin/sh
mysql_port=3306
mysql_username=”root”
mysql_password=”root”
function_start_mysql()
{
printf “Starting MySQL…/n”
/bin/sh /usr/local/webserver/mysql/bin/mysqld_safe –defaults-file=/var/webserver/mysql/${mysql_port}/my.cnf 2>&1 > /dev/null &
}
function_stop_mysql()
{
printf “Stoping MySQL…/n”
/usr/local/webserver/mysql/bin/mysqladmin -u ${mysql_username} -p${mysql_password} -S /tmp/mysql.sock shutdown
}
function_restart_mysql()
{
printf “Restarting MySQL…/n”
function_stop_mysql
sleep 5
function_start_mysql
}
function_kill_mysql()
{
kill -9 $(ps -ef | grep ‘bin/mysqld_safe’ | grep ${mysql_port} | awk ‘{printf $2}’)
kill -9 $(ps -ef | grep ‘libexec/mysqld’ | grep ${mysql_port} | awk ‘{printf $2}’)
}
if [ "$1" = "start" ]; then
function_start_mysql
elif [ "$1" = "stop" ]; then
function_stop_mysql
elif [ "$1" = "restart" ]; then
function_restart_mysql
elif [ "$1" = "kill" ]; then
function_kill_mysql
else
printf “Usage: /var/webserver/mysql/${mysql_port}/mysql {start|stop|restart|kill}/n”
fi
5)、添加执行权限
sudo chmod +x /etc/init.d/mysql
6)、添加mysql服务(ubuntu),并启动服务添加自定义shell命令
#添加mysql服务
sudo update-rc.d mysql defaults 100
#启动mysql服务
service mysql start
#添加自写义shell命令,方便进入mysql
sudo vim ~/.bashrc
#在最后一行加入以下内容
mysql () {
/usr/local/webserver/mysql/bin/mysqlr
}
#让其立即生效
source ~/.bashrc
7)、登陆mysql以上添加好之后,直接输入mysql就可以登陆进去了
8)、输入以下SQL语句,创建一个具有root权限的用户
GRANT ALL PRIVILEGES ON *.* TO ‘root’@'localhost’ IDENTIFIED BY ”;
GRANT ALL PRIVILEGES ON *.* TO ‘root’@’127.0.0.1′ IDENTIFIED BY ”;
3、编译安装PHP(FastCGI模式)
tar zxvf php-5.2.10.tar.gz
gzip -cd php-5.2.10-fpm-0.5.11.diff.gz | patch -d php-5.2.10 -p1
cd php-5.2.10/
./configure –prefix=/usr/local/webserver/php –with-config-file-path=/usr/local/webserver/php/etc –with-mysql=/usr/local/webserver/mysql –with-mysqli=/usr/local/webserver/mysql/bin/mysql_config –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-inline-optimization –with-curl –with-curlwrappers –enable-mbregex –enable-fastcgi –enable-fpm –enable-force-cgi-redirect –enable-mbstring –with-mcrypt –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 –without-pear
#如果出现下面的错误提示
#checking for xml2-config… no
#checking for xml-config… no
#configure: error: XML configuration could not be found
#安装 apt-get install libxml2-dev
#如果出现下面的错误提示
#checking for pkg-config… /usr/bin/pkg-config
#configure: error: Cannot find OpenSSL’s
#安装 apt-get install libssl-dev”
#如果出现下面的错误提示
#checking for cURL in default path… not found
#configure: error: Please reinstall the libcurl distribution – easy.h should be in
#安装: apt-get install libcurl4-gnutls-dev
#如果出现:
#configure: error: libjpeg.(a|so) not found.
#安装: apt-get install libjpeg-dev
#如果出现:
#configure: error: libpng.(a|so) not found.
#安装: apt-get install libpng12-dev
#如果出现:configure: error: freetype.h not found.
#安装: apt-get install libfreetype6-dev
#如果出现:configure: error: sasl.h not found!
#安装: apt-get install libsasl2-dev
如果出现:
+——————————————————————–+
| *** ATTENTION *** |
| |
| Something is likely to be messed up here, because the configure |
| script was not able to detect a simple feature on your platform. |
| This is often caused by incorrect configuration parameters. Please |
| see the file debug.log for error messages. |
| |
| If you are unable to fix this, send the file debug.log to the |
| php-install@lists.php.net mailing list and include appropiate |
| information about your setup. |
+——————————————————————–+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+——————————————————————–+
Thank you for using PHP.
#到php安装程序目录(编译PHP的目录)去查看debug.log最后几行如果有以下警告
A conftest.c:3: warning: incompatible implicit declaration of built-in function ‘exit’
B ./conftest: error while loading shared libraries: libmysqlclient.so.16: cannot open shared object file: No such file or directory
#增加LD_LIBRARY_PATH=/usr/local/mysql/lib/mysql到环境变量,方法为编辑/etc/profile文 件,添 加:export LD_LIBRARY_PATH=/usr/local/webserver/mysql/lib/mysql
#如果不想重启使用 . /etc/profile 就可以了,注意.和/etc中间有空格,然后再重新编译
make ZEND_EXTRA_LIBS=’-liconv’
make install
#复制配置好的php.ini到/usr/local/webserver/php/etc/目录下
cp php.ini-dist /usr/local/webserver/php/etc/php.ini
cd ..
#curl http://pear.php.net/go-pear | /usr/local/webserver/php/bin/php
4、编译安装PHP5扩展模块
tar zxvf memcache-2.2.5.tgz
cd memcache-2.2.5/
/usr/local/webserver/php/bin/phpize
./configure –with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
cd ..
#如果出现:
#Cannot find autoconf. Please check your autoconf installation and the
#$PHP_AUTOCONF environment variable. Then, rerun this script.
#安装:
#sudo apt-get install m4
#sudo apt-get install autoconf
#或者直接:
#sudo apt-get install autoconf
#因为autoconf 依赖于m4,所以会自动下载解决这个依赖关系.
tar jxvf eaccelerator-0.9.5.3.tar.bz2
cd eaccelerator-0.9.5.3/
/usr/local/webserver/php/bin/phpize
./configure –enable-eaccelerator=shared –with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
cd ..
tar zxvf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2/
/usr/local/webserver/php/bin/phpize
./configure –with-php-config=/usr/local/webserver/php/bin/php-config –with-pdo-mysql=/usr/local/webserver/mysql
make
make install
cd ..
tar zxvf ImageMagick.tar.gz
cd ImageMagick-6.5.1-2/
./configure
make
make install
cd ..
#如果执行make时出错,信息提示如下:
#/usr/bin/ld: cannot find -lperl
#collect2: ld returned 1 exit status
#make[2]: *** [blib/arch/auto/Image/Magick/Magick.so] 错误 1
#make[2]:正在离开目录 `/home/ouyangjunqiu/下载/ImageMagick-6.5.1-2/PerlMagick’
#make[1]: *** [all-perl] 错误 2
#make[1]:正在离开目录 `/home/ouyangjunqiu/下载/ImageMagick-6.5.1-2′
#make: *** [all] 错误 2
#有两种解决方法
#1.在配置的时候加个。。
#./configure –without-perl
#2.安装库文件
#apt-get install libperl-dev
#安装完成后验证一下是否能正常工作输入convert -version 如果出现如下错误:
convert: error while loading shared libraries: libMagickCore.so.2: cannot open shared object file: No such file or directory
#我们需要把安装目录下缺失的文件,用ln链接到/usr/lib目录下
#ln -s /usr/local/lib/libMagickCore.so.2 /usr/lib
#然后可以使用convert xx.jpg xx.gif 把jpg的图片转换为gif看看能不能正常使用
tar zxvf imagick-2.2.2.tgz
cd imagick-2.2.2/
/usr/local/webserver/php/bin/phpize
./configure –with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
cd ..
5、修改php.ini文件
手工修改:查找/usr/local/webserver/php/etc/php.ini中的extension_dir = “./”
修改为extension_dir = “/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/”
并在此行后增加以下几行,然后保存:
extension = “memcache.so”
extension = “pdo_mysql.so”
extension = “imagick.so”
再查找output_buffering = Off
修改为output_buffering = On
6、配置eAccelerator加速PHP:
mkdir -p /usr/local/webserver/eaccelerator_cache
vi /usr/local/webserver/php/etc/php.ini
按shift+g键跳到配置文件的最末尾,加上以下配置信息:
[eaccelerator]
zend_extension=”/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so”
eaccelerator.shm_size=”64″
eaccelerator.cache_dir=”/usr/local/webserver/eaccelerator_cache”
eaccelerator.enable=”1″
eaccelerator.optimizer=”1″
eaccelerator.check_mtime=”1″
eaccelerator.debug=”0″
eaccelerator.filter=”"
eaccelerator.shm_max=”0″
eaccelerator.shm_ttl=”3600″
eaccelerator.shm_prune_period=”3600″
eaccelerator.shm_only=”0″
eaccelerator.compress=”1″
eaccelerator.compress_level=”9″
7、创建www用户和组:
/usr/sbin/groupadd www
/usr/sbin/useradd -g www www
mkdir -p /var/webserver/www
chmod +w /var/webserver/www
chown -R www:www /var/webserver/www
8、创建php-fpm配置文件(php-fpm是为PHP打的一个FastCGI管理补丁,可以平滑变更php.ini配置而无需重启php-cgi):
在/usr/local/webserver/php/etc/目录中创建php-fpm.conf文件:
rm -rf /usr/local/webserver/php/etc/php-fpm.conf
vi /usr/local/webserver/php/etc/php-fpm.conf
输入以下内容(如果您安装 Nginx + PHP 用于程序调试,请将以下的
All relative paths in this config are relative to php’s install prefix
Pid file
Error log file
Log level
When this amount of php processes exited with SIGSEGV or SIGBUS …
… in a less than this interval of time, a graceful restart will be initiated.
Useful to work around accidental curruptions in accelerator’s shared memory.
Time limit on waiting child’s reaction on signals from master
Set to ‘no’ to debug fpm
Name of pool. Used in logs and stats.
Address to accept fastcgi requests on.
Valid syntax is ‘ip.ad.re.ss:port’ or just ‘port’ or ‘/path/to/unix/socket’
Set listen(2) backlog
Set permissions for unix socket, if one used.
In Linux read/write permissions must be set in order to allow connections from web server.
Many BSD-derrived systems allow connections regardless of permissions.
Additional php.ini defines, specific to this pool of workers.
Unix user of processes
Unix group of processes
Process manager settings
Sets style of controling worker process count.
Valid values are ‘static’ and ‘apache-like’
Sets the limit on the number of simultaneous requests that will be served.
Equivalent to Apache MaxClients directive.
Equivalent to PHP_FCGI_CHILDREN environment in original php.fcgi
Used with any pm_style.
Settings group for ‘apache-like’ pm style
Sets the number of server processes created on startup.
Used only when ‘apache-like’ pm_style is selected
Sets the desired minimum number of idle server processes.
Used only when ‘apache-like’ pm_style is selected
Sets the desired maximum number of idle server processes.
Used only when ‘apache-like’ pm_style is selected
The timeout (in seconds) for serving a single request after which the worker process will be terminated
Should be used when ‘max_execution_time’ ini option does not stop script execution for some reason
’0s’ means ‘off’
The timeout (in seconds) for serving of single request after which a php backtrace will be dumped to slow.log file
’0s’ means ‘off’
The log file for slow requests
Set open file desc rlimit
Set max core size rlimit
Chroot to this directory at the start, absolute path
Chdir to this directory at the start, absolute path
Redirect workers’ stdout and stderr into main error log.
If not set, they will be redirected to /dev/null, according to FastCGI specs
How much requests each process should execute before respawn.
Useful to work around memory leaks in 3rd party libraries.
For endless request processing please specify 0
Equivalent to PHP_FCGI_MAX_REQUESTS
Comma separated list of ipv4 addresses of FastCGI clients that allowed to connect.
Equivalent to FCGI_WEB_SERVER_ADDRS environment in original php.fcgi (5.2.2+)
Makes sense only with AF_INET listening socket.
Pass environment variables like LD_LIBRARY_PATH
All $VARIABLEs are taken from current environment
9、启动php-cgi进程,监听127.0.0.1的9000端口,进程数为200(如果服务器内存小于3GB,可以只开启64个进程)
ulimit -SHn 65535
/usr/local/webserver/php/sbin/php-fpm start
注:/usr/local/webserver/php/sbin/php-fpm还有其他参数,包 括:start|stop|quit|restart|reload|logrotate,修改php.ini后不重启php-cgi,重新加载配置文件 使用reload。
三、安装Nginx 0.8.53
1、安装Nginx所需的pcre库:
tar zxvf pcre-7.9.tar.gz
cd pcre-7.9/
./configure
make && make install
cd ..
2、安装Nginx
tar zxvf nginx-0.8.53.tar.gz
cd nginx-0.8.53/
./configure –user=www –group=www –prefix=/usr/local/webserver/nginx –with-http_stub_status_module –with-http_ssl_module
make && make install
cd ..
3、创建Nginx日志目录
mkdir -p /var/log/nginx
chmod +w /var/log/nginx
chown -R www:www /var/log/nginx
4、创建Nginx配置文件
1、在/usr/local/webserver/nginx/conf/目录中创建nginx.conf文件:
rm -f /usr/local/webserver/nginx/conf/nginx.conf
vi /usr/local/webserver/nginx/conf/nginx.conf
输入以下内容:
user www www;
worker_processes 2;
error_log /var/log/nginx/nginx_error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /usr/local/webserver/nginx/conf/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”‘;
access_log /var/log/nginx/access.log main;
sendfile on;
autoindex off;
map $scheme $fastcgi_https { ## Detect when HTTPS is used
default off;
https on;
}
keepalive_timeout 10;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffers 8 128k;
gzip on;
gzip_comp_level 2;
gzip_proxied any;
#gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
# Load config files from the /usr/local/webserver/nginx/conf/conf.d directory
include /usr/local/webserver/nginx/conf/conf.d/*.conf;
}
添加虚似主机(注:因本人要使用Magento所以下面有的东西是给Magento写的,这只是个例子)
vim /usr/local/webserver/nginx/conf/conf.d/zozhang.test.conf
写下配置文件
server {
listen 80;
server_name zozhang.test;
#下面这包主要是给没有加www的添加www,由于是本地测试,就不启用了。
#rewrite / $scheme://www.$host$request_uri permanent; ## Forcibly prepend a www
}
server {
listen 80 default; #default 所的配置文件中,只能定义一个;
server_name zozhang.test; ## Domain is here twice so server_name_in_redirect will favour the www
root /var/webserver/www/test;
location / {
index index.html index.php; ## Allow a static html file to be shown first
try_files $uri $uri/ @handler; ## If missing pass the URI to Magento’s front handler
expires 30d; ## Assume all files are cachable
}
location /minify/ { ## Needed for Fooman Speedster
rewrite ^/minify/([0-9]+)(/.*/.(js|css))$ /lib/minify/m.php?f=$2&d=$1 last;
}
## These locations would be hidden by .htaccess normally
location /app/ { deny all; }
location /includes/ { deny all; }
location /lib/ { deny all; }
location /lib/minify/ { allow all; } ## Deny is applied after rewrites so must specifically allow minify
location /media/downloadable/ { deny all; }
location /pkginfo/ { deny all; }
location /report/config.xml { deny all; }
location /var/ { deny all; }
location /var/export/ { ## Allow admins only to view export folder
auth_basic “Restricted”; ## Message shown in login window
auth_basic_user_file htpasswd; ## See /usr/local/webserver/nginx/confhtpassword
autoindex on;
}
location /. { ## Disable .htaccess and other hidden files
return 404;
}
location @handler { ## Magento uses a common front handler
rewrite / /index.php;
}
location ~ /.php/ { ## Forward paths like /js/index.php/x.js to relevant handler
rewrite ^(.*/.php)/ $1 last;
}
location ~ /.php$ { ## Execute PHP scripts
expires off; ## Do not cache dynamic content
fastcgi_pass 127.0.0.1:9000;
fastcgi_param HTTPS $fastcgi_https;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params; ## See /usr/local/webserver/nginx/conf/fastcgi_params
}
}
2、在/usr/local/webserver/nginx/conf/目录中创建fcgi.conf文件:
vi /usr/local/webserver/nginx/conf/fcgi.conf
输入以下内容:
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;
# PHP only, required if PHP was built with –enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
5、启动Nginx
ulimit -SHn 65535
/usr/local/webserver/nginx/sbin/nginx
#启动过程中如果提示:/usr/local/webserver/nginx/sbin/nginx: error while loading shared libraries: libpcre.so.0: cannot open shared object file: No such file or directory
#解决方法,在/lib中创建一个symbol link到/usr/local/lib/libpcre.so.0
# ln -s /usr/local/lib/libpcre.so.0 /lib
四、配置开机自动启动Nginx + PHP
vi /etc/rc.local
在末尾增加以下内容:
ulimit -SHn 65535
/usr/local/webserver/php/sbin/php-fpm start
/usr/local/webserver/nginx/sbin/nginx
创建Nginx管理脚本(启动、停止、配置、重启)
################################################
#!/bin/bash
# v.0.0.3
# create by jackbillow at 2007.10.15
# redevelop by XGuru at 2010.6.28
# On Ubuntu 10.04
# nginx – This shell script takes care of starting and stopping nginx.
#
# description: nginx [engine x] is light http web/proxy server
# that answers incoming ftp service requests.
###############################################
nginx_path=”/usr/local/webserver/nginx/” #配置nginx安装路径
nginx_pid=”/usr/local/webserver/nginx/logs/nginx.pid”
prog=”nginx”
RETVAL=0
start() {
# Start daemons.
if [ -e $nginx_path/conf/nginx.conf ];then
echo -n $”Starting $prog: ”
$nginx_path/sbin/nginx -c $nginx_path/conf/nginx.conf &
RETVAL=$?
[ $RETVAL -eq 0 ] && {
echo Start “$prog” successfully!
}
else
RETVAL=1
fi
return $RETVAL
}
# Stop daemons.
stop() {
echo -n $”Stopping $prog/n”
sudo killall -9 nginx
RETVAL=$?
}
# See how we were called.
conf(){
vim “$nginx_path/conf/nginx.conf” #这里请设置要使用什么方式打开配置文件,我使用的是vim
}
case “$1″ in
start)
start
;;
stop)
stop
;;
conf)
conf
;;
restart)
stop
start
;;
*)
echo $”Usage: $0 {start|stop|conf|restart}”
echo $”Your may need root privilege to execute this script!”
exit 1
esac
exit $RETVAL
六、在不停止Nginx服务的情况下平滑变更Nginx配置
1、修改/usr/local/webserver/nginx/conf/nginx.conf配置文件后,请执行以下命令检查配置文件是否正确:
/usr/local/webserver/nginx/sbin/nginx -t
如果屏幕显示以下两行信息,说明配置文件正确:
the configuration file /usr/local/webserver/nginx/conf/nginx.conf syntax is ok
the configuration file /usr/local/webserver/nginx/conf/nginx.conf was tested successfully
2、这时,输入以下命令查看Nginx主进程号:
ps -ef | grep “nginx: master process” | grep -v “grep” | awk -F ‘ ‘ ‘{print $2}’
屏幕显示的即为Nginx主进程号,例如:
6302
这时,执行以下命令即可使修改过的Nginx配置文件生效:
kill -HUP 6302
或者无需这么麻烦,找到Nginx的Pid文件:
kill -HUP `cat /usr/local/webserver/nginx/nginx.pid`
七、编写每天定时切割Nginx日志的脚本
1、创建脚本/usr/local/webserver/nginx/sbin/cut_nginx_log.sh
vi /usr/local/webserver/nginx/sbin/cut_nginx_log.sh
输入以下内容:
#!/bin/bash
# This script run at 00:00
# The Nginx logs path
logs_path=”/usr/local/webserver/nginx/logs/”
mkdir -p ${logs_path}$(date -d “yesterday” +”%Y”)/$(date -d “yesterday” +”%m”)/
mv ${logs_path}access.log ${logs_path}$(date -d “yesterday” +”%Y”)/$(date -d “yesterday” +”%m”)/access_$(date -d “yesterday” +”%Y%m%d”).log
kill -USR1 `cat /usr/local/webserver/nginx/nginx.pid`
2、设置crontab,每天凌晨00:00切割nginx访问日志
crontab -e
输入以下内容:
00 00 * * * /bin/bash /usr/local/webserver/nginx/sbin/cut_nginx_log.sh
当你幸福的时候,我不在,当我幸福的时候,你也不在

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











요즘 Ubuntu에서 사용자가 터미널을 여는 것을 허용하지 않는 것은 매우 일반적인 문제입니다. 유사한 문제가 발생하고 다음에 무엇을 해야 할지 모르는 경우 Linux 장치에서 "Ubuntu가 터미널을 열 수 없음" 문제를 해결하는 방법에 대한 5가지 수정 사항에 대해 알아보세요. 더 이상 고민하지 말고 문제의 원인과 이에 대한 해결 방법을 살펴보겠습니다. Ubuntu가 터미널을 열 수 없는 이유는 무엇입니까? 이는 주로 결함이 있는 소프트웨어를 설치하거나 터미널 구성을 수정할 때 발생합니다. 이 외에도 로캘과 상호 작용하여 이를 손상시키는 새로운 응용 프로그램이나 게임도 비슷한 문제를 일으킬 수 있습니다. 일부 사용자는 Ubuntu의 활동 메뉴에서 터미널을 검색할 때 이 문제에 대한 수정 사항을 보고했습니다. 이는 다음을 보여줍니다.

우분투 시스템에서는 상단에 자물쇠 모양이 있는 폴더가 자주 나타나는데, 이 파일은 편집할 수 있는 권한이 없기 때문에 권한을 수정해야 하는 경우가 많습니다. 오른쪽 하단에 잠그나요? 아래의 자세한 튜토리얼을 살펴보겠습니다. 1. 잠긴 폴더--속성을 마우스 오른쪽 버튼으로 클릭합니다. 2. 창에서 권한 옵션을 선택합니다. 3. 파일을 생성하고 삭제하려면 내부의 모든 항목을 선택하세요. 4. 그런 다음 하단에 포함된 파일의 권한 변경을 선택합니다. 이 권한도 파일 생성 및 삭제로 설정되어 있습니다. 마지막으로 오른쪽 상단에 있는 변경을 클릭하는 것을 잊지 마세요. 5. 위의 잠금이 여전히 제거되지 않거나 옵션이 회색으로 표시되어 조작할 수 없는 경우 마우스 오른쪽 버튼을 클릭하여 터미널을 엽니다. 6. 만들다

Ubuntu 시스템 시작 메뉴에는 많은 소프트웨어 아이콘이 나열되어 있습니다. 일반적이지 않은 아이콘을 삭제하려면 어떻게 해야 합니까? 아래의 자세한 튜토리얼을 살펴보겠습니다. 1. 먼저 우분투 데스크탑에 들어가서 왼쪽 패널 아래의 시작 메뉴를 클릭합니다. 2. 내부에서 텍스트 편집기 아이콘을 찾을 수 있으며 이를 삭제해야 합니다. 3. 이제 바탕 화면으로 돌아가 마우스 오른쪽 버튼을 클릭하여 터미널을 엽니다. 4. 명령을 사용하여 애플리케이션 목록 디렉터리를 엽니다. sudonautilus/usr/share/applicationssudonautilus~/.local/share/applications5 내부에서 해당 텍스트 편집기 아이콘을 찾으세요. 6. 그럼 직진하세요

Ubuntu 시스템에서는 루트 사용자가 일반적으로 비활성화되어 있습니다. 루트 사용자를 활성화하려면 passwd 명령을 사용하여 비밀번호를 설정한 다음 su- 명령을 사용하여 루트로 로그인할 수 있습니다. 루트 사용자는 무제한 시스템 관리 권한을 가진 사용자입니다. 그는 파일, 사용자 관리, 소프트웨어 설치 및 제거, 시스템 구성 변경에 액세스하고 수정할 수 있는 권한을 가지고 있습니다. 루트 사용자와 일반 사용자 사이에는 분명한 차이가 있습니다. 루트 사용자는 시스템에서 가장 높은 권한과 더 넓은 제어 권한을 갖습니다. 루트 사용자는 일반 사용자가 할 수 없는 중요한 시스템 명령을 실행하고 시스템 파일을 편집할 수 있습니다. 이 가이드에서는 Ubuntu 루트 사용자, 루트로 로그인하는 방법, 일반 사용자와 어떻게 다른지 살펴보겠습니다. 알아채다

코드명 "NobleNumbat"인 Ubuntu24.04LTS가 곧 출시됩니다! Ubuntu 23.10과 같은 LTS가 아닌 버전을 사용하는 경우 조만간 업그레이드를 고려해야 합니다. Ubuntu20.04LTS 또는 Ubuntu22.04LTS를 사용하는 경우 업그레이드 여부를 고려해 볼 가치가 있습니다. Canonical은 Ubuntu 24.04LTS가 다음과 같이 분류하여 최대 12년 동안 업데이트 지원을 제공할 것이라고 발표했습니다. LTS 버전으로서 5년간 정기적인 유지 관리 및 보안 업데이트가 제공됩니다. Ubuntu Pro를 구독하면 추가로 5년 동안 지원을 받을 수 있습니다. 현재 이 추가 지원 기간은 7년으로 연장되어 최대 12년까지 지원을 받으실 수 있습니다.

OBS는 전 세계의 자원 봉사자들이 자유 시간에 개발한 오픈 소스 소프트웨어입니다. 주로 비디오 녹화 및 라이브 스트리밍에 사용되는 비디오 라이브 녹화 소프트웨어입니다. Ubuntu/Mint 설치 시 OBSStudio는 ChromeOS에서 완벽하게 작동하지 않으며 화면, 창 캡처 등의 기능을 사용할 수 없는 점 참고하시기 바랍니다. 전체 화면 프로젝터와 같은 OBS의 특정 기능에 대한 잠재적인 성능 문제를 방지하려면 xserver-xorg1.18.4 또는 최신 버전을 사용하는 것이 좋습니다. FFmpeg가 필요합니다. FFmpeg가 설치되어 있지 않은 경우(확실하지 않은 경우) 다음을 사용하여 설치할 수 있습니다. sudoaptinstallffmpeg 여기에 이미 설치되어 있습니다.

snap은 Linux 커널과 systemdinit 시스템을 사용하는 운영 체제용으로 Canonical에서 개발한 소프트웨어 패키징 및 배포 시스템입니다. snaps라고 하는 이러한 패키지와 이를 사용하는 도구인 snapd는 다양한 Linux 배포판에서 사용할 수 있으며 업스트림 소프트웨어 개발자가 애플리케이션을 사용자에게 직접 게시할 수 있도록 해줍니다. snap을 사용하면 사용자는 Linux 애플리케이션을 쉽게 설치할 수 있습니다. 기본적으로 snapd는 하루에 4번 업데이트를 확인하고 자동으로 snap 애플리케이션을 최신 버전으로 업데이트합니다. 업데이트 설치 시기와 빈도를 제어하는 방법은 다양하지만 보안상의 이유로 사용자가 자동 업데이트를 완전히 끌 수는 없습니다. 스냅의 본래 의도는 좋지만 많은 사람들이 스냅을 사용하여

Angular.js는 동적 애플리케이션을 만들기 위해 자유롭게 액세스할 수 있는 JavaScript 플랫폼입니다. HTML 구문을 템플릿 언어로 확장하여 애플리케이션의 다양한 측면을 빠르고 명확하게 표현할 수 있습니다. Angular.js는 코드를 작성, 업데이트 및 테스트하는 데 도움이 되는 다양한 도구를 제공합니다. 또한 라우팅 및 양식 관리와 같은 많은 기능을 제공합니다. 이 가이드에서는 Ubuntu24에 Angular를 설치하는 방법에 대해 설명합니다. 먼저 Node.js를 설치해야 합니다. Node.js는 서버 측에서 JavaScript 코드를 실행할 수 있게 해주는 ChromeV8 엔진 기반의 JavaScript 실행 환경입니다. Ub에 있으려면
