前回はwslでAoache2とPHPの設定を行い、SOY CMSを動かしました。

WSL2でSOY CMSの開発環境を作ってみた

今回は、virtualhostを立てて、そこにSOY CMSを入れてみます。

最終的な環境

OS:Windows 10 Home

wsl2上の環境

Ubuntu-20.04 

Apache2.4.38

PHP7.4.3

Virtualhostを立ち上げる時に、あらかじめドキュメントルートにしたいディレクトリを作る。

今回は、/home/ryoko/workspace/demo/を作成し、ここにSOYCMSのディレクトリを作成することにする。


端末を立ち上げて下記のコマンドを入力する。

$ cd /etc/apache2
$ cd saites-enabled
#000-default.confにapache2の設定が入っているか確認する
$ less 000-default.conf
<VirtualHost *: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>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
#一つ上の階層に移動する
$ cd ../
$ cd sites-available
#000-default.confをdemo.confと名前をつけたファイルにコピーする
$ sudo cp 000-default.conf demo.conf
#availableディレクトリにコピーファイルができると、enabledディレクトリにシンボリックリンクができる
$ sudo vim demo.conf
Listen 8080

<VirtualHost *:8080>
	# 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 /home/ryoko/workspace/demo
	<Directory /home/ryoko/workspace/demo/>
		Options FollowSymLinks
		AllowOverride All
		Require all granted
	</Directory>

	# 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>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

一番上の行にListen 8080を追加。

その下を<Virtual Host *:8080>に変更

ServerAdminの下のDocumentRootを下記に変更する。

DocumentRoot /home/ryoko/workspace/demo

その下に下記4行を追加する


<Directory /home/ryoko/workspace/ryoko/demo>
	Options FollowSymLinks
	AllowOverride All
	Require all granted
</Directory>

vimを閉じて、

#sites-enabledにあるdemo.confにも設定を反映させる

$ sudo a2ensite demo.conf
#apache2の再起動<
$ sudo /etc/init.d/apache2 restart

後は、demoディレクトリにSOY CMSのディレクトリと表示したいhtmlファイルを入れる

アドレス欄にlocalhost:8080を入れてSOY CMSの管理画面が表示されればOK