nginx是俄罗斯开发人员开发的web服务器软件,其特点是运行速度快,占用内存小,CPU低消耗,使用迅速在web服务器市场上占领了一席之地,现在nginx已经成立了一家专门的公司。
在本教程中使用主机名server1.example.com,IP 地址 192.168.0.100 。这些设置可能会有所不同,所以你必须在适当情况下以取代他们。
首先安装MySQL 5,输入命令:
yum install mysql mysql-server
设置开机自动启动MYSQL
chkconfig --levels 235 mysqld on
/etc/init.d/mysqld start
现在,检查网络启用。运行
netstat -tap | grep mysql
如果运行正常,应该显示:
[root@server1 ~]# netstat -tap | grep mysql
tcp 0 0 *:mysql *:* LISTEN 2479/mysqld
[root@server1 ~]#
如果没有如上显示,编辑/etc/my.cnf文件并注释掉选项跳过网络:
vi /etc/my.cnf
#skip-networking
并重新启动您的MySQL服务器:
/etc/init.d/mysqld restart
然后运行代码设置MySQL账户密码
mysql_secure_installation
[root@server1 ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we’ll need the current
password for the root user. If you’ve just installed MySQL, and
you haven’t set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): <– 回车
OK, successfully used password, moving on…
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] <– 回车
New password: <– 输入Root账户密码
Re-enter new password: <– 再输入一次
Password updated successfully!
Reloading privilege tables..
… Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] <– 回车
… Success!
Normally, root should only be allowed to connect from ‘localhost’. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] <– 回车
… Success!
By default, MySQL comes with a database named ‘test’ that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] <– 回车
– Dropping test database…
… Success!
– Removing privileges on test database…
… Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] <– 回车
… Success!
Cleaning up…
All done! If you’ve completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
[root@server1 ~]#
安装的Nginx,输入以下命令作安装前准备:
cd /etc/yum.repos.d/
wget http://centos.karan.org/kbsingh-CentOS-Extras.repo
配置文件:
vi /etc/yum.repos.d/kbsingh-CentOS-Extras.repo
修改内容如下:
# pkgs in the -Testing repo are not gpg signed
[kbs-CentOS-Testing]
name=CentOS.Karan.Org-EL$releasever – Testing
gpgcheck=0
gpgkey=http://centos.karan.org/RPM-GPG-KEY-karan.org.txt
enabled=1
baseurl=http://centos.karan.org/el$releasever/extras/testing/$basearch/RPMS/
之后,我们可以安装nginx的如下:
yum install nginx
然后,我们创建系统启动nginx的链接并启动它:
chkconfig --levels 235 nginx on
/etc/init.d/nginx start
浏览器输入您的Web服务器IP地址或主机名(如类型http://192.168.0.100),你应该看到一个空白页,说明网站已经工作 此空白主页地址(/usr/share/nginx/html/index.html,可以自己修改一下看看):
安装PHP5
yum install lighttpd-fastcgi php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-mssql php-snmp php-soap php-tidy
打开/etc/php.ini配置cgi.fix_pathinfo = 1:
vi /etc/php.ini
cgi.fix_pathinfo = 1
lighttpd的FastCGI包附带的可执行文件/usr/bin/spawn-fcgi,可以看帮助:
spawn-fcgi --help
要开始一个PHP FastCGI的守护进程侦听端口 9000 localhost 上的用户和组运行nginx的,我们运行下面的命令 :
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u nginx -g nginx -f /usr/bin/php-cgi -P /var/run/fastcgi-php.pid
当然,你不想在键入该命令时手动启动系统,使系统在开机时自动执行命令,打开/etc/rc.local:
vi /etc/rc.local
在文件没为加入如下内容:
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u nginx -g nginx -f /usr/bin/php-cgi -P /var/run/fastcgi-php.pid
配置nginx的:
vi /etc/nginx/nginx.conf
配置是很容易理解(你可以了解它在这里:http://wiki.codemongers.com/NginxFullExample:http://wiki.codemongers.com/NginxFullExample2)
改变一下内容:
[…]
worker_processes 5;
[…]
keepalive_timeout 2;
[…]
虚拟主机配置。让我们如下修改默认的虚拟主机 :
[…]
server {
listen 80;
server_name _;#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
include fastcgi_params;
}# deny access to .htaccess files, if Apache’s document root
# concurs with nginx’s one
#
location ~ /\.ht {
deny all;
}
}
[…]
现在保存文件,重新启动nginx的:
/etc/init.d/nginx restart
创建一个探针文件:info.php,看看那些模块正常运行了
vi /usr/share/nginx/html/info.php
内容如下:
《?php
phpinfo();
?》
把双引号改为英文半角输入的单引号。
然后浏览器输入:http://192.168.0.100/info.php查看运行结果:
继续往下浏览,看看MYSQL运行情况:
相关软件连接:
投稿作者 | 作者网站 |
---|---|
微信捐赠 | 支付宝捐赠 |
---|---|
评论功能已经关闭!