LoginSignup
2

More than 5 years have passed since last update.

phpでHPを公開する。開発環境としてcloud9を導入する。

Last updated at Posted at 2017-10-30

公開する環境と開発環境をインストールする。

とりあえずVPSやクラウドを契約してください。
または、グローバルIPのあるPCを用意する。
サーバーのOSはubutu16.04を選択、インストールしてください。

とりあえず最初にやっておきましょう

アプリケーションとかを最新のものにします。
セキュリティも向上します。

sudo apt-get update
sudo apt-get upgrade

必要なパッケージをインストール

cloud9を使うにはnode.js環境が必要なのでインストールする。周辺の環境も必要なのでnpmもインストール
nパッケージというものを使い最新バージョンに更新して古いバージョンを消します。

sudo apt-get install -y nodejs npm 
sudo npm cache clean
sudo npm install n -g
sudo npm install npm -g
sudo npm install forever -g

sudo n stable
sudo ln -sf /usr/local/bin/node /usr/bin/node

sudo apt-get purge nodejs
sudo apt-get purge npm

PHPのインストール

phpで公開したいのでインストール
途中でパスワードの入力を求められるので適当に打ってください。

sudo apt-get install php mysql-server apache2

cloud9のインストール

とりあえずダウンロード。githubにて公開しているのでgitをインストール。

sudo apt-get install -y git
git clone git://github.com/c9/core.git cloud9
cd cloud9
./scripts/install-sdk.sh
nano server.js -p 10080 -a :

あとりあえず下のどれかライブラリが動かなければ、下の感じで動くかも

cd cloud9
npm install
npm install amd-loader --save
npm install architect
npm install c9/urls
git reset --hard

cloud9を永久に起動できるように、自動起動の設定をしましょう

sudo nano /etc/rc.local
/etc/rc.local
/usr/local/bin/forever start /home/ando/cloud9/server.js -p 10080 -a :
exit 0

アクセスするアドレスごとに振り分けを行う

bash
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod proxy_balancer
sudo a2enmod lbmethod_byrequests

sudo nano /etc/apache2/sites-available/000-default.conf
#以下を入力する。
/etc/apache2/sites-available/000-default.conf
<VirtualHost ide.example.com:80>
        ServerName ide.example.com

        <IfModule mod_proxy.c>
                ProxyRequests Off
                ProxyPreserveHost On
                ProxyPass / http://127.0.0.1:10080/
                ProxyPassReverse / http://127.0.0.1:10080/
        </IfModule>

</VirtualHost>

<VirtualHost www.example.com:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

以下のコマンドで設定をする。

bash
sudo service apache2 reload
sudo service apache2 restart

RSA認証

SSH接続の時はRSA認証をすると、セキュリティがよくなる。応急処置ですが、最低限やっておきましょう。
参考

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2