Mac - Apache MySql PHP Server mit Homebrew
https://help.macstadium.com/articles/how-to-install-apache-mysql-and-php-using-homebrew-on-macos https://gist.github.com/DragonBe/0faebe58deced34744953e3bf6afbec7
Requirements
Requirements
- Xcode
- Homebrew Paketmanager für Mac OS X
- Homebrew-Cask
- Text Editor (like Sublime Text 2) as you will need to edit some lines of code
- Mac with High Sierra or above
XCode über den App Store installieren Homebrew wie im Wiki beschrieben.
Apache
MacOs System Apache Autostart abschalten
sudo launchctl unload -w/System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null
System Apache stoppen
sudo apachectl stop
Wahrscheinlich läuft aber keiner, es sei denn du hast ihn vorher aktiviert. Daher kann es gut sein dass eine
‘could not find specified service’.
Meldung kommt.
Homebrew Apache installieren
Now we can proceed with the installation of Apache 2.4:
brew install httpd
Achte darauf wie der Apache eingerichtet wird. Bei mir ist das folgendermaßen:
DocumentRoot is /usr/local/var/www. The default ports have been set in /usr/local/etc/httpd/httpd.conf to 8080 and in /usr/local/etc/httpd/extra/httpd-ssl.conf to 8443 so that httpd can run without sudo. To have launchd start httpd now and restart at login: brew services start httpd Or, if you don't want/need a background service you can just run: apachectl start
Check of Apache läuft
Achte auf den Pfad der während der Homebrew-Cask Installation genutzt wurde. Du könntest Ihn verändert haben:
which apachectl /usr/local/bin/apachectl
Du kannst auch
httpd -v Server version: Apache/2.4.39 (Unix) Server built: Apr 19 2019 17:54:07
Nutzen. Das gibt dann die Version und das built ähnlich wie oben aus.
Apache starten
At this stage you should be ready to start Apache:
sudo apachectl start
Die Webseite erreichst du im Browser über den localhost (Port 8080 vgl. Ausgabe oben)
http://localhost:8080/
oder die Lokale IP Adresse. Es sollte die typische Apache Seite kommen.
“It Works!”
Apache Autostart (optional)
Wenn du den Apache beim Mac Start automatisch starten willst, kannst du einen Homebrew Service ienrichten
sudo brew services start httpd
Ich mache das nicht, da ich auch noch den XAMPP für kleinere Sachen nutze, da muss nicht der brew apache die ganze Zeit laufen.
Apache Module und Port konfigurieren
Den Port kannst du hier ändern. Standardmäßig richtet brew den 8080 ein. Eigentlich ganz gut bei mir, da der XAMPP auf dem Standardport 80 läuft, so kann ich theoretisch beide auch mal gleichzeitig nutzen.
open -e /usr/local/etc/httpd/httpd.conf
Finde die Zeile mit
Listen 8080
und passe sie z.B. auf 80 an. Ich lasse es auf 8080
Erlaubte Direktiven für .htaccess - AllowOverride
Look for AllowOverride in your file, we will need to change it to:
- AllowOverride controls what directives may be placed in .htaccess files.
- It can be "All", "None", or any combination of the keywords:
- AllowOverride FileInfoAuthConfig Limit
AllowOverride All
mod_rewrite aktivieren
Suche nach
LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so
und entferne den Hash vorne
Servername
Schön ist noch At last we need to edit our ServerName which would look like this in your file:
- ServerName www.example.com:8080
Replace it with your IP Address or domain:
ServerName 207.254.1.1 You can now restart apache:
sudo apachectl -k restart PART 2 – PHP
First of all you need to decide which version of PHP you require ranging from 5.6 to 7.2, in this tutorial we’ll use 7.2 but installation of any other version would be much alike.
Install PHP 7.2 using brew.
brew install php@7.2 You can simply replace the 7.2 with another version according to your needs, it can be 5.6, 7.0, 7.1.
Once the installation finishes you can begin editing files, beginning with php.ini. It is the default configuration file for running applications.
You can decide to change the memory_limit, upload_max_filesize or max_execution_time. You can also activate safe mode.
Now you need to go back to your httpd.conf file which we edited during the Apache installation process and add a line which will connect PHP with Apache once again use:
open -e /usr/local/etc/httpd/httpd.conf Add libphp somewhere below the last edit we made by uncommenting LoadModule:
LoadModule php7_module /usr/local/opt/php@7.2/lib/httpd/modules/libphp7.so At your discretion depending on the project you’re working on, you can also edit an option which will allow you to load index.php or index.html
Look for:
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
And replace it with:
<IfModule dir_module>
DirectoryIndex index.htmlindex.htm index.php
</IfModule> Now you can stop and start apache once again to validate the changes.
PART 3 – MYSQL
At last you can install mysql and the process is very straightforward. You can even use the Native Packages to run the whole installation process.
For this example, we will go through the process of installing it with Homebrew:
brew install mysql Now you can load and start services:
brew services start mysql It will tell you to secure your installation, run the following command:
mysql_secure_installation Set a new root password, remove anonymous users and other options to limit access to localhost only.
You can now restart the MySQL server:
brew services restart mysql You’re all set.