Skip to content

Instantly share code, notes, and snippets.

@rotten77
Last active May 5, 2023 10:24
Show Gist options
  • Save rotten77/469554712a043dfeadd9c33e1bd3cd2a to your computer and use it in GitHub Desktop.
Save rotten77/469554712a043dfeadd9c33e1bd3cd2a to your computer and use it in GitHub Desktop.
LAMPP on Windows with Cygwin

LAMP on Windows with Cygwin

You can run your "LAMP" server on Windows with all benefits of Linux command line.

Cygwin packages:

Download Cygwin and run setup. Choose this packages:

Web/httpd
Libs/libapr1-devel
Libs/libaprutil1-devel
PHP/httpd-mod_php7
PHP/php
Database/mysql
Database/mysql-server
PHP/php-fileinfo
PHP/php-mysqli
PHP/php-pdo_mysql
PHP/php-gd
PHP/php-Archive_Tar
PHP/php-bz2
PHP/php-zlib
PHP/php-json
PHP/php-ctype
PHP/php-exif
PHP/php-iconv
PHP/php-mbstring
PHP/php-curl
PHP/php-simplexml
PHP/php-xmlreader
PHP/php-xmlrpc
PHP/php-xmlwriter
PHP/php-zip
PHP/php-bcmath
Mail/exim
Mail/mutt
Editors/vim
Net/ncftp
Net/curl
Web/wget
Net/whois

...or you can run setup from command line with selected packages:

setup-x86_64.exe -P httpd -P libapr1-devel -P libaprutil1-devel -P httpd-mod_php7 -P php -P mysql -P mysql-server -P php-fileinfo -P php-mysqli -P php-pdo_mysql -P php-gd -P php-Archive_Tar -P php-bz2 -P php-zlib -P php-json -P php-ctype -P php-exif -P php-iconv -P php-mbstring -P php-curl -P php-simplexml -P php-xmlreader -P php-xmlrpc -P php-xmlwriter -P php-zip -P php-bcmath -P exim -P mutt -P vim -P ncftp -P curl -P wget -P whois 

Configuration:

/etc/httpd/conf/httpd.conf

#42 Mutex posixsem (add)
#177 LoadModule rewrite_module modules/mod_rewrite.so (uncomment)
#212 ServerAdmin yourname@localhost (edit)
#222 ServerName localhost (add)
#245 DocumentRoot DocumentRoot "/cygdrive/c/www/" (edit)
#246 <Directory "/cygdrive/c/www/"> (edit)
#266 AllowOverride All (edit)
    (All/None/AllowOverrideFileInfo/AuthConfig/Limit)
#297 ErrorLog "/cygdrive/c/www/error_log"
#326 CustomLog "/cygdrive/c/www/access_log" common
  • #42 is line number in file, it is approximate value only for your orientation where you put or edit configurations
  • This is configuration for C:\www\ server root folder

etc/php.ini

#586 error_log = "/cygdrive/c/www/php_error_log" (add)

Commands:

Run Apache server:

$ /usr/sbin/httpd -k start (restart/stop)

Run MySQL(MariaDB):

$ mysql_install_db (installation)

$ mysqld_safe & (run daemon)
$ mysqladmin -u root shutdown (shutdowm)

$ mysql_secure_installation (installation with setups)

E-mail

Close Cygwin and run it again as admin, then rum Exim config:

$ exim-config

Who is the local postmaser? [yourname]
Primary host: localhost
IPV6: no
Sendmail: yes
Daemon: no

E-mail queue:

$ mailq (show queue)
$ rm -fvr /var/spool/exim (clear queue)

/etc/exim.conf

Forward all outcoming e-mails from server to yourname@localhost, about #527 line after "begin routers":

catch_all_outgoing:
driver = redirect
data = yourname@localhost

Mutt - e-mail client

Creates /home/yourname/Mail at first start

When error configuration, you can run: mutt -n (runs Mutt without configuration)

Using server.sh

Next file in this gist is server.sh. You can use it for running your server. Run Cygwin and type bash server.sh ? for help.

Examples

Start Apache + MySQL server:

bash server.sh start

Restart only Apache server:

bash server.sh restart

Stop both server and kill all related proceses

bash server.sh kill

Show PHP error log fie

bash server.sh log php_err

php.exe in system variables

For running PHP scripts from Windows command line or editors or IDEs add C:\[cygwin64 folder]\bin\ to system PATH variables.

#!/bin/bash
case "$1" in
# Apache server ===================
start)
bash server.sh apache start
bash server.sh mysql start
exit
;;
stop)
bash server.sh apache stop
bash server.sh mysql stop
bash server.sh kill
exit
;;
# Apache server ===================
apache)
case "$2" in
# start -------------------
start)
echo -e "\tStarting Apache..."
/usr/sbin/httpd -k start
exit
;;
# stop -------------------
stop)
echo -e "\tShutting down Apache..."
/usr/sbin/httpd -k stop
exit
;;
# restart -------------------
restart)
echo -e "\tRestarting Apache..."
/usr/sbin/httpd -k restart
exit
;;
# kill -------------------
kill)
echo -e "\tKilling all httpd processes..."
ps -W | grep httpd | grep -v grep | gawk '{print $1}' | xargs kill -f
exit
;;
# help --------------------
*)
echo " >>> Enter second parameter: start/stop/restart/kill"
exit
esac
;;
# MySQL database ==================
mysql)
case "$2" in
start)
echo -e "\tStarting MySQL..."
mysqld_safe &
exit
;;
# stop -------------------
stop)
echo -e "\tShutting down MySQL..."
mysqladmin -u root shutdown
exit
;;
# kill -------------------
kill)
echo -e "\tKilling all mysql processes..."
ps -W | grep mysqld | grep -v grep | gawk '{print $1}' | xargs kill -f
exit
;;
# help --------------------
*)
echo " >>> Enter second parameter: start/stop/kill"
exit
esac
;;
# Kill ============================
kill|exit|quit)
bash server.sh apache kill
bash server.sh mysql kill
exit
;;
# logs ============================
log)
case "$2" in
# php error ---------------
php_err)
less /cygdrive/c/www/php_error_log
exit
;;
# apache error ------------
err)
less /cygdrive/c/www/error_log
exit
;;
# apache access -----------
access)
less /cygdrive/c/www/access_log
exit
;;
# clear logs ---------------
clear)
rm -f /cygdrive/c/www/php_error_log
rm -f /cygdrive/c/www/error_log
rm -f /cygdrive/c/www/access_log
exit
;;
# help --------------------
*)
echo " >>> Enter second parameter: php_err/err/access/clear"
exit
esac
;;
# help ============================
help|?)
echo ""
echo "SERVER.SH"
echo ""
echo " bash server.sh [PARAM1] [PARAM2]"
echo " start - start HTTP & MySQL server"
echo " stop - stop HTTP & MySQL server"
echo " apache - Apache HTTP server"
echo " start/stop/restart/kill"
echo " mysql - MySQL database"
echo " start/stop/kill"
echo " log - log files"
echo " php_err/err/access/clear"
echo " kill - kill all HTTP & MySQL processes"
exit
;;
*) # if no action found ===========
echo " >>> Enter at least one parameter (\"help\" or \"?\" for help)"
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment