开发者社区> 问答> 正文

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

作为一个技术菜鸟,懵懂中成了一个站长,其间的心酸只有自己知道,别的不说,只在安装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.



展开
收起
东山西峰 2015-01-08 10:24:15 14765 0
5 条回答
写回答
取消 提交回答
  • Re你再也不需要军哥的lnmp一键安装包了
    你太懒了。。。。。也 不翻译一下内容
    2015-01-09 14:34:47
    赞同 展开评论 打赏
  • Re你再也不需要军哥的lnmp一键安装包了
      
    2015-01-09 13:37:24
    赞同 展开评论 打赏
  • 元芳,阿里云云栖论坛总版主,phpwind官方论坛管理员,社区论坛领域应用专家。长期活跃在社区论坛建站领域,对各类社区论坛程序颇有研究!乐于交友,热心助人,以帮助和服务站长朋友为宗旨,帮助数以千计的站长朋友顺利建站!
    说实话,我们更建议新手使用镜像系统~
    2015-01-09 13:24:11
    赞同 展开评论 打赏
  • Re你再也不需要军哥的lnmp一键安装包了
    说人话
    2015-01-08 14:33:50
    赞同 展开评论 打赏
  • 不明觉厉
    2015-01-08 10:31:04
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
15分钟打造你自己的小程序更新版 立即下载
冬季实战营第二期:Linux操作系统实战入门 立即下载
低代码开发师(初级)实战教程 立即下载