你再也不需要军哥的lnmp一键安装包了-问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文

你再也不需要军哥的lnmp一键安装包了

东山西峰 2015-01-08 10:24:15 12865
作为一个技术菜鸟,懵懂中成了一个站长,其间的心酸只有自己知道,别的不说,只在安装linux系统web环境这一节,就花费了大量时间。国内的教程普遍比较陈旧,英文的又看不大懂,所幸还有百度翻译,虽然比较傻瓜;)最终算是顺利搭建了一台自己的服务器(不过后来发现阿里云提供wordpress等一键安装服务,要表扬一下阿里云,服务在国内算是不错的,泪奔~~@@),但是对于喜欢折腾或者没有使用阿里云的朋友来说,下面这个教程可能很有用。
这个教程是英文版的,大体框架来自digitalocean,但是那个教程不是很完整,根据它无法完整安装配置web服务器,参考多方资料后,我进行了加工,英文版的!哈哈~~~
其实很简单,只需要简单的copy命令即可,注意区分大小写。我的meyay.com 就是按照这个思路安装的。
Install LEMP(Linux, Nginx, MySQL, PHP) stack on Linode VPS(CentOS 7)


As a novice at linode,I am curious to know how to install lemp on centos7.I found some courses but not complete.So I decide to share my experience to the novice like me.
Some people advise to change the SELinux mode to permissive or disabled.In fact linode VPS has set SELinux mode disabled.
Install Nginx
To add the CentOS 7 Nginx yum repository, open terminal(I use XSHELL. Xshell:\>ssh IP) and use the following command(You can copy and paste to xshell):
sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
If current user is root,you need not type “sudo”.Next command:
sudo yum install nginx
Afterwards, your web server is installed. Start Nginx on your VPS:
sudo systemctl start nginx.service
Visit your server's public IP address in your web browser:
http://server_domain_name_or_IP/

If you see this page, then your web server is now correctly installed.
Enable Nginx to start on boot:
sudo systemctl enable nginx.service
Install MySQL (MariaDB)
sudo yum install mariadb-server mariadb
Start MariaDB with the following command:
sudo systemctl start mariadb
Remove some da ngerous defaults and lock down access to our database system a little bit. Start the interactive script by running:
sudo mysql_secure_installation
The prompt will ask you for your current root password. Since you just installed MySQL, you most likely won’t have one, so leave it blank by pressing enter. Then the prompt will ask you if you want to set a root password. Go ahead and enter Y, and follow the instuctions:
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 MariaDB
root user without the proper authorisation.


New password: password
Re-enter new password: password
Password updated successfully!
Reloading privilege tables..
... Success!
For the rest of the questions, you should simply hit the "ENTER" key through each prompt to accept the default values.
Enable MariaDB to start on boot:
sudo systemctl enable mariadb.service
Install PHP
We're going to include the php-mysql and php-fpm packages as well:
sudo yum install php php-mysql php-fpm
Open the main php-fpm configuration file with root privileges:
sudo vi /etc/php.ini
What we are looking for in this file is the parameter that sets cgi.fix_pathinfo. This will be commented out with a semi-colon (;) and set to "1" by default.
We will change both of these conditions by uncommenting the line and setting it to "0" like this:
cgi.fix_pathinfo=0
:wq
Save and close the file when you are finished.
Next, open the php-fpm configuration file www.conf:
sudo vi /etc/php-fpm.d/www.conf
Find the line that specifies the listen parameter, and change it so it looks like the following:
listen = /var/run/php-fpm/php-fpm.sock
:wq
Save and quit.
Now, we just need to start our PHP processor by typing:
sudo systemctl start php-fpm
This will implement the change that we made.
Next, enable php-fpm to start on boot:
sudo systemctl enable php-fpm.service
Next time,if you want change those files,but forget the parth,you can use command:
find / -name filename
Configure Nginx to Process PHP Pages
Open the default Nginx server block configuration file by typing:
sudo vi /etc/nginx/conf.d/default.conf
Currently, with the comments removed, the Nginx default server block looks like this:
server {
    listen       80;
    server_name  localhost;


    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}
We need to make some changes to this file for our site.The changes that you need to make are in red in the text below:
server {
    listen       80;
    server_name  server_domain_name_or_IP;


    root   /usr/share/nginx/html;
    index index.php index.html index.htm;


    location / {
        try_files $uri $uri/ =404;
    }
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }


    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}
When you've made the above changes, you can save and close the file.
:wq
Restart Nginx to make the necessary changes:
sudo systemctl restart nginx
Test PHP Processing on your Web Server
In order to test that our system is configured properly for PHP, we can create a very basic PHP script.
sudo vi /usr/share/nginx/html/info.php
This will open a blank file. We want to put the following text, which is valid PHP code, inside the file:
<?php phpinfo(); ?>
When you are finished, save and close the file.
:wq
chown –R nginx:nginx /usr/share/nginx/html/
chmod -R 755 /usr/share/nginx/html
Now we can test whether our web server can correctly display content generated by a PHP script.
http://your_server_IP_address/info.php
The page that you come to should look something like this:

This page basically gives you information about your server from the perspective of PHP. It is useful for debugging and to ensure that your settings are being applied correctly.
If this was successful, then your PHP is working as expected.
Now you can install wordpress or joomla on your server.



关系型数据库 MySQL Unix 应用服务中间件 Linux Go 网络安全 PHP nginx 网络架构
分享到
取消 提交回答
全部回答(5)
  • 老陈小安
    2015-01-09 14:34:47
    Re你再也不需要军哥的lnmp一键安装包了
    你太懒了。。。。。也 不翻译一下内容
    0 0
  • 小沫沫
    2015-01-09 13:37:24
    Re你再也不需要军哥的lnmp一键安装包了
      
    0 0
  • 元芳
    2015-01-09 13:24:11
    说实话,我们更建议新手使用镜像系统~
    0 0
  • 在荥阳
    2015-01-08 14:33:50
    Re你再也不需要军哥的lnmp一键安装包了
    说人话
    0 0
  • 大韵科技
    2015-01-08 10:31:04
    不明觉厉
    0 0
添加回答
开发与运维
使用钉钉扫一扫加入圈子
+ 订阅

集结各类场景实战经验,助你开发运维畅行无忧

推荐文章
相似问题