DBを設定する
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 34 35 36 37 38 39 40 |
# apt install postgresql # pg_createcluster -u postgres 9.6 testdb1 # createdb -h localhost -p 5433 -U postgres -E UTF8 -O postgres -T template1 test01 # psql -h localhost -p 5433 -U postgres -l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+----------+----------+-------------+-------------+----------------------- postgres | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | template0 | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres test01 | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | (4 rows) # psql -h localhost -p 5433 -U postgres test01 test01=# create table users (id serial, email varchar(255), password varchar(255)); test01=# create table temp_users ( id serial, email varchar(255), password varchar(255), key varchar(255)); test01=# \d users Table "public.users" Column | Type | Modifiers ----------+------------------------+---------------------------------------------------- id | integer | not null default nextval('users_id_seq'::regclass) email | character varying(255) | password | character varying(255) | test01=# \d temp_users Table "public.temp_users" Column | Type | Modifiers ----------+------------------------+--------------------------------------------------------- id | integer | not null default nextval('temp_users_id_seq'::regclass) email | character varying(255) | password | character varying(255) | key | character varying(255) | test01=# INSERT INTO users (email, password) test01=# VALUCES ('test01', '0e698a8ffc1a0af622c7b4db3cb750cc'); test01=# SELECT * FROM users; |
nginxの設定
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# vi /etc/nginx/sites-enabled/default server { listen 80 default_server; listen [::]:80 default_server; root /var/www/html; index index.html index.htm index.nginx-debian.html; server_name _; location / { try_files $uri $uri/ =404; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.1-fpm.sock; } } --- systemctl restart nginx.service |
php-fpmの設定
1 2 3 4 5 6 |
vi /etc/php/7.1/fpm/pool.d/www.conf --- listen = /run/php/php7.1-fpm.sock --- systemctl restart php7.1-fpm.service |
codeigniterの設定
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
cd /var/www/html sudo wget https://github.com/bcit-ci/CodeIgniter/archive/3.1.6.zip unzip 3.1.6.zip mv CodeIgniter-3.1.6 ci vi /var/www/html/ci/application/config/autoload.php --- $autoload['libraries'] = array("database"); $autoload['helper'] = array("form", "url"); --- vi /var/www/html/ci/application/config/database.php --- 'username' => 'postgres', 'database' => 'test01' 'dbdriver' => 'postgre', --- vi /var/www/html/ci/application/config/routes.php --- $route['default_controller'] = 'main'; --- vi /var/www/html/ci/application/views/login.php --- < !DOCTYPE html> <html lang="ja"> <head> <meta charset="utf-8"/> <title>Login Page</title> </head> <body> <div id="container"> <h1>Login Page</h1> < ?php echo form_open("/index.php?/main/login_validation"); echo validation_errors(); echo "<p>Email : " . form_input("email", $this->input->post("email")) . ""; echo "<p>Password: " . form_password("password") . "</p>"; echo "<p>" . form_submit("login_submit", "Login") . "</p>"; echo form_close(); ?> </div> </body> </html> --- vi /var/www/html/ci/application/views/members.php --- < !DOCTYPE html> <html lang="ja"> <head> <meta charset="utf-8"/> <title>member Page</title> </head> <body> <did id="container"> <h1>Member Page</h1> </did> </body> </html> --- vi /var/www/html/ci/application/controller/Main.php --- < ?php class Main extends CI_Controller { public function index() { $this->login(); } public function login() { $this->load->view('login'); } public function members() { $this->load->view("members"); } public function login_validation(){ $this->load->helper(array('form', 'url')); $this->load->library("form_validation"); $this->form_validation->set_rules('email', 'email', 'required|trim|callback_validate_credentials'); $this->form_validation->set_rules('password', 'password', 'required|trim|md5'); if ($this->form_validation->run() == FALSE){ $this->load->view("login"); } else { redirect("/index.php?/main/members"); } } public function validate_credentials() { $this->load->model("model_users"); if($this->model_users->can_log_in()) { return true; } else { $this->form_validation->set_message("validate_credentials", "invalid"); return false; } } } --- vi /var/www/html/ci/application/models/Model_users.php --- < ?php class Model_users extends CI_Model { public function can_log_in() { $this->db->where("email", $this->input->post("email")); $this->db->where("password", md5($this->input->post("password"))); $query = $this->db->get("users"); if($query->num_rows() == 1) { return true; } else { return false; } } } --- |