Build LNMP on ubuntu

Operating system Ubuntu Server 18.04.1 LTS 64-bit

One, nginx

  1. installation apt install nginx -y
  2. Startup service nginx start(if you install PHP first, and install apache2 together, nginx cannot be started because port 80 is occupied)

Two, MySQL

  • installation apt install mysql-server -y
  • Installation apt install mysql-client -y(optional, includes a series of tools, backup pressure test, etc.)
  • start up service mysql start
  • Enter mysql -uroot -p(if you can't find mysql, follow the prompts to install)
  • change Password
    • use mysql;
    • Below update user set authentication_string=password("你的密码") where user="root";8.0.11:, Above 8.0.11:alter user 'root'@'localhost' identified with mysql_native_password by '你的密码';
    • Below 8.0.11: update user set plugin="mysql_native_password";(This has not been encountered before, but if you do not execute this, you still do not need a password to log in)
    • update `user` set Host = '%' where User = 'root'; (Remote connection needs to allow host)
    • flush privileges;

Three, PHP

1. Install php
  • apt install php -y
  • apt install php-xml -y
  • apt install php-mysql -y (You also have to install this yourself, the PDO extension display no value bothers me for a while)
2. Install php-fpm
  • Install php-fpm apt install php-fpm -y&
  • nginx configuration vim /etc/nginx/conf.d/test.conf
    server {
        listen 80 default;
        server_name 127.0.0.1;
        root /var/www;
        index index.php;
        
        location ~ \.php {
            fastcgi_pass    127.0.0.1:9000; 
            include         fastcgi.conf;
        }
    }
    
    nginx -s reload
  • Edit the php-fpm configuration vim /etc/php/7.2/fpm/pool.d/www.conf, find it listen = /run/php/php7.2-fpm.sock, and change it to listen = 9000(this works with nginx to monitor the local port 9000, I haven’t studied the way it comes with it)
  • Start php-fpm service php7.2-fpm start
  • In /var/wwwcase create php output phpinfo.

Five, remote connection to MySQL

  • Enter mysql & use mysql;& update user set host = '%' where user = 'root';&flush privileges;
  • vim /etc/mysql/mysql.conf.d/mysqld.cnfComment out bind-address = 127.0.0.1->service mysql restart
  • Install firewall management (you can also bring your own ufw)
    • apt install firewalld -y
    • Open 3306 port external access firewall-cmd --zone=public --add-port=3306/tcp --permanent
    • Make it effective firewall-cmd --reload, view the exposed portfirewall-cmd --list-ports
  • If still not possible, check the cloud service security group port limit

Six, install redis and connect remotely

  • Install redis client apt install redis -y
  • Install php's redis extension apt install php-redis -y
  • Enable remote access
    • vim /etc/redis/redis.conf& Comment out bind 127.0.0.1 ::1& setprotected-mode no
    • Open port 6379 for external access, refer to the above
  • Use password vim /etc/redis/redis.conf&&requirepass 你的密码
  • Re-enter redis-cli, the command is not working (error) ERR invalid password, input auth 你的密码to normal
  • Log an error Failed opening the RDB file root (in server root dir /var/spool/cron) for saving: Read-only file system
    • The catalog /etc/redis/redis.confin the dir /var/lib/redismatch.
    • Enter cli mode redis-cli
    • View config get dir& change configuration config set dir /var/lib/redis(not persistent)
    • config rewrite (Make it lasting)

Seven, other

  • Use ssh to log in as root
    • Modify configuration vim /etc/ssh/sshd_config& uncomment Port 22&PermitRootLogin yes
    • change Password sudo passwd root

Guess you like

Origin blog.csdn.net/z772532526/article/details/107836123