以do为例

lamp

apache

安装
sudo yum install httpd
启动
sudo service httpd start
这时候打开你的ip地址,应该可以看到apache已经运行了

mysql

安装
sudo yum install mysql-server
启动
sudo service mysqld start
修改密码
sudo /usr/bin/mysql_secure_installation

php

默认安装是5.3的
sudo yum install php php-mysql
如果需要其他扩展可以搜索yum search php-
安装php5.5

1
2
yum remove php php-*
sudo yum install php55w php55w-mysql

测试

echo '<?php phpinfo();?>' >> /usr/share/nginx/html/i.php
打开你的IP:i.php就能看到信息了

LNMP

默认的源中没有Nginx,需要添加EPEL源
sudo yum install epel-release

nginx

安装
sudo yum install nginx
启动
sudo /etc/init.d/nginx start
配置
修改/etc/nginx/conf.d/default.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#
# The default server
#
server {
listen 80;
server_name example.com;
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;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# 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 $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

测试配置
nginx -t

mysql

与上面一样,不在多说

php

版本的选择与上面一样,不在多说,不过nginx需要安装php-fpm
安装
sudo yum install php-fpm php-mysql
配置
编辑 /etc/php.ini
修改; cgi.fix_pathinfo=1, 为 cgi.fix_pathinfo=0
修改/etc/php-fpm.d/www.conf,找到user和group,默认是apache修改为nginx

1
2
3
4
; RPM: apache Choosed to be able to access some dir as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx

重载
sudo service php-fpm start
打开你的IP/info.php,不出问题的话,就成功了
打开页面是空白?nginx的配置没写fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
参考
https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-centos-6
https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-centos-6