ここのサイトにある最近、Qiitaへ投稿すると、個人ブログへの投稿が少なくなってしまうというのは激しく同意!!
なので同じように FeedWordPress プラグインを使って同期してみた。
Qiitaの下書きにも使えるように、このサイトは JP Markdown を入れて、投稿にマークダウンも使えるようにしているからか
Qiitaから読み込んだ記事がかなり怪しい感じに(笑)なってますが、詳細は Qiita で確認してください。
httpd.conf の
・DirectoryIndex に index.py を追加
・AddHandler に .py を追加。
DirectoryIndex index.html index.php index.py AddHandler cdi-script .cgi .py
ruby、python は、以下のoptionsを設定
Options ExecCGI
Python は cgi として動くのでシェバング(1行目)を忘れずに。別バージョンで使う場合はここを修正する。例) #!/usr/bin/python36
#!/usr/bin/python # coding:utf-8 print "Content-Type: text/html\n"; print "Hello World!";
作ったスクリプトには x 属性を追加しておく。例) chmod +x index.py
最新の Python は python36 だが、Tensorflow(Python36未対応)等を使う場合は Python35 を入れる。(x が 6 とか 5 とかになる。
$ yum install python3x $ yum install python3x-pip
Python35 の pip を使う場合は、以下の様に実行する。
$ python35 -m pip install tensorflow]]>
$ sudo yum update $ sudo yum upgrade
$ sudo yum list available | grep パッケージ名
パッケージ名には httpd* とか指定する。httpd(ver2.2) と httpd24(ver2.4) が見つかる。
複数のバージョンが混在しない場合は httpd をインストールすればOK
バージョンによってパッケージが様変わりするのでバージョンの確認方法を
cat /etc/system-release
apache2
$ sudo yum -y install httpd24 $ vi /etc/httpd/conf/httpd.conf + <Directory /var/www/html> + AllowOverride all + </Directory> $ chkconfig httpd on $ service httpd start
$ sudo yum -y install mod24_ssl
参考:チュートリアル: Amazon Linux で SSL/TLS を使用できるように Apache ウェブサーバーを設定する
mysql も mysql(5.5-1)、mysql51、mysql55(5.5.58)、mysql56、mysql57 がある。
$ sudo yum install mysql57-server $ mysql_secure_installation
※ 201709版のAWSLinuxは上のリポジトリが入っているが、201712版は入っていないので注意すること。
ユーザ作成
$ mysql -p Enter password: mysql> CREATE USER ユーザ名; mysql> CREATE USER user IDENTIFIED BY [PASSWORD] ‘パスワード’; MySQL> CREATE DATABASE DB名 CHARACTER SET utf8; MySQL> GRANT ALL ON DB名.* to ユーザ名; MySQL> FLUSH PRIVILEGES; mysql> \q
PHPも、PHP(5.3)、PHP54、PHP55、PHP56、PHP70、PHP71 があるので妥当なバージョンを選択する。
PHP 7.1 インストール
$ sudo yum install php71 php71-opcache php71-mbstring php71-xml php71-gd php71-mysqli php71-zip php71-curl $ service httpd restart
wp-config.phpの上部に
// for https on if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') { $_SERVER['HTTPS'] = 'on'; }
を追記。wp_opions の seturl と home を https:// に変更する。
□公式ドキュメント
Function Reference/is ssl « WordPress Codex
$ vi /etc/selinux/config - SELINUX=enforcing + SELINUX=disabled
$ sudo apt-get update $ sudo apt-get upgrade
apache2
$ apt-get -y install apache2 root@www:~# vi /etc/apache2/conf-enabled/security.conf # 25行目:変更 ServerTokens Prod $ vi /etc/apache2/mods-enabled/dir.conf # 2行目:ディレクトリ名のみでアクセスできるファイル名を設定 DirectoryIndex index.html index.htm $ vi /etc/apache2/apache2.conf # 70行目:サーバー名追記 ServerName xxx.xxx.xxx $ vi /etc/apache2/sites-enabled/000-default.conf # 11行目:管理者アドレス変更 ServerAdmin xxx@xxx.xxx + <Directory /var/www/html> + Options FollowSymLinks + AllowOverride all + </Directory> $ a2enmod rewrite $ systemctl restart apache2
https も使うなら SSL のモジュールを有効にする。
$ sudo a2enmod ssl $ sudo a2ensite default-ssl $ vi /etc/apache2/sites-available/default-ssl.conf + ServerName localhost:443 DocumentRoot /var/www/html : + <Directory /var/www/html> ← .htaccess とか使うならこれも必要 + Options FollowSymLinks + AllowOverride all + </Directory> $ sudo service apache2 restart
ファイヤーウォール設定
$ ufw status $ ufw allow to any port 80 $ ufw allow to any port 443 ← https も使うなら設定する。 $ ufw reload
インストール
$ sudo apt-get install mysql-server # 途中で root のパスワードを聞いてくるので入力して控えておく $ systemctl enable mysql $ systemctl start mysql $ mysql_secure_installation
ユーザ作成
$ mysql -p Enter password: mysql> CREATE USER ユーザ名; mysql> CREATE USER user IDENTIFIED BY [PASSWORD] ‘パスワード’; MySQL> CREATE DATABASE DB名 CHARACTER SET utf8; MySQL> GRANT ALL ON DB名.* to ユーザ名; MySQL> FLUSH PRIVILEGES; mysql> \q
リポジトリインストール
PHP 7.0 インストール
$ sudo apt-get install php7.0 php7.0-opcache php7.0-mbstring php7.0-xml php7.0-gd php7.0-mysqli php7.0-zip php7.0-curl $ sudo apt-get install libapache2-mod-php7.0 $ a2enmod php7.0 $ systemctl restart apache2
Composer で何かやろうとしたとき以下の様なエラーが出る
[Composer\Downloader\TransportException] The "http://packagist.org/p/provider-2017-07%248509dd1d7587d7cde6c580bdbac4c49c3f3b373f243c953dfce84ed8916a4c5a .json" file could not be downloaded (HTTP/1.1 404 Not Found)
diag を実行するとどこでエラーかわかるので、見てみると pubkeys でエラーになっていた。
$ composer diag : Checking pubkeys: FAIL Missing pubkey for tags verification Missing pubkey for dev verification Run composer self-update --update-keys to set them up
こんなときは pubkey を入れなおす。update-keys を実行すると以下の様に聞いてくるので
$ composer self-update --update-keys Enter Dev / Snapshot Public Key (including lines with -----): Enter Tags Public Key (including lines with -----):
https://composer.github.io/pubkeys.html の —–BEGIN PUBLIC KEY—– から —–END PUBLIC KEY—– までを全て入力する。
apt-get update で以下の様なエラーが出る場合
W: GPG エラー: http://ftp.debian.org jessie-backports InRelease: 公開鍵を利用できないため、以下の署名は検証できませんでした: NO_PUBKEY 8B48AD6246925553 NO_PUBKEY 7638D0442B90D010
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 8B48AD6246925553 $ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7638D0442B90D010
の様にキーを追加してやる。debian.org とかあるけれど keyserver.ubuntu.com で良いらしい。
]]>$ php artisan make:migration modify_users_admin_column
これで空のマイグレーションファイルを作ってから、それを編集してフィールドを追記する。
database/migrations/YYYY_MM_DD_HHIISS_modify_users_admin_column.php
public function up() { + Schema::table('users', function ($table) { + $table->boolean('role')->default(0)->after('remember_token'); + }); }
app/User.php に追加した権限に対応する処理を追加する。
class User extends Authenticatable { : + /** + * 管理者か? + * @return bool true:管理者 + */ + public function isAdmin() + { + return $this->role == 1; + } }
モデル依存の場合は個別にPolicyファイルを作るが、全体の場合は、app/Providers/AuthServithProvider.php の boot() に直接記述する。
app/Providers/AuthServiceProvider.php
- use Illuminate\Support\Facades\Gate; : - public function boot() - { - parent::registerPolicies(); + use Illuminate\Contracts\Auth\Access\Gate; : + public function boot(Gate $gate) + { + parent::registerPolicies($gate); + + // user + $gate->define('user', function($user) { + return true; + }); + + // admin + $gate->define('admin', function($user) { + return $user->isAdmin() ? true : false; + }); }
これで blade 内で
@can('admin') : @endcan
で制御できるようになる。
]]>Centos7のボックス追加から立ち上げ
> vagrant box add Centos/7 > cd \vagrant\centos7 > vagrant init Centos/7 > vagrant up > vagrant ssh $ sudo su -
SELinuxオフ
$ vi /etc/selinux/config - SELINUX=enforcing + SELINUX=disabled
アップデート・アップグレード
$ yum update $ yum upgrade
apache2
$ yum install httpd
ファイヤーウォール設定
$ firewall-cmd --add-service=http --zone=public --permanent $ firewall-cmd --add-service=https --zone=public --permanent $ firewall-cmd --reload
mariaDBライブラリとデータフォルダの削除
$ yum remove -y mariadb-libs $ rm -rf /var/lib/mysql/
リポジトリ追加
$ yum localinstall –y http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
インストール
$ yum -y install mysql-community-server $ systemctl enable mysqld $ systemctl start mysqld /var/log/mysqld.log に root の初期パスワードが出力される。 $ cat /var/log/mysqld.log | grep root [Note] A temporary password is generated for root@localhost: ********** ********* 部分を控えて、下記を実行する。 $ mysql_secure_installation
ユーザ作成
$ mysql -p Enter password: mysql> CREATE USER ユーザ名; mysql> CREATE USER user IDENTIFIED BY [PASSWORD] ‘パスワード’; MySQL> CREATE DATABASE DB名 CHARACTER SET utf8; MySQL> GRANT ALL ON DB名.* to ユーザ名; MySQL> FLUSH PRIVILEGES; mysql> \q
リポジトリインストール
$ yum install -y epel-release $ rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
PHP 7.2 インストール
$ yum install --enablerepo=remi,remi-php72 php php-opcache php-mbstring php-xml php-gd php-mysqli php-fpm php-zip
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements mysql> SHOW VARIABLES LIKE 'validate_password%'; # 再度パスワードの設定を確認 +--------------------------------------+--------+ | Variable_name | Value | +--------------------------------------+--------+ | validate_password_dictionary_file | | | validate_password_length | 8 | | validate_password_mixed_case_count | 1 | | validate_password_number_count | 1 | | validate_password_policy | MEDIUM | | validate_password_special_char_count | 1 | +--------------------------------------+--------+ 6 rows in set (0.01 sec) mysql> SET GLOBAL validate_password_length=4; mysql> SET GLOBAL validate_password_policy=LOW;
Vagrantのバージョンの問題。
1.9.7 から PowerShell5.x が必要なので(Windows7 に入っているのは PowerShell2) PowerShell5.x を入れる。
Cygwinを使っている場合は、Vagrantを1.9.6、VirtualBoxを5.1.30にダウングレードするか、Cygwinターミナルを使わず、コマンドプロンプトを使う。
Extention Packが必要
1. 最新のVirtual Boxをインストール。
http://www.oracle.com/technetwork/server-storage/virtualbox/downloads/index.html#vbox
2. VirtualBox Extension PackをVirtual Boxに追加。
http://www.oracle.com/technetwork/server-storage/virtualbox/downloads/index.html?ssSourceSiteId=otnjp#extpack
+ config.ssh.insert_key = false
$ mkdir -p /home/vagrant/.ssh $ wget --no-check-certificate https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub -O /home/vagrant/.ssh/authorized_keys $ chmod 0700 /home/vagrant/.ssh $ chmod 0600 /home/vagrant/.ssh/authorized_keys $ chown -R vagrant /home/vagrant/.ssh
$ vagrant reload]]>