meta data for this page
LAMP serwer
czyli jak zainstalować i skonfigurować na Linux: Apache, MySQL i PHP. Zobacz także: Zmiana wersji PHP.
Od wersji Debian 10 MySQL'a nie ma w standardowym repozytorium. Dodanie repozytorium:
apt-get install gnupg wget lsb-release wget http://repo.mysql.com/mysql-apt-config_0.8.36-1_all.deb dpkg -i mysql-apt-config_0.8.36-1_all.deb
Sprawdź jakie jest najnowsze repozytorium na stronie https://dev.mysql.com/downloads/repo/apt/.
Debian
apt-get update apt-get install apache2 apt-get install mysql-server mysql-client apt-get install php php-mysql
CentOS
yum update yum install httpd yum install mariadb-server mariadb yum install php php-mysql yum install mod_ssl openssl # Instalujemy mod_ssl
Wrzucamy pliki strony do /home/page/httpdocs/, gdzie page to nazwa użytkownika (zamień wszędzie na swoją stosowną nazwę).
useradd --create-home --shell /bin/bash page cd /home/page sudo -u page mkdir httpdocs install logs backup
Teraz tworzymy konfigurację serwera Apache w /etc/apache2/sites-available, np. /etc/apache2/sites-available/page.conf (patrz Przykładowa konfiguracja Apache).
W CentOS wystarczy utworzyć konfigurację w /etc/httpd/conf.d/page.conf - zostanie ona automatycznie zainkludowana.
a2ensite page
W sites-enabled powinno się pojawić dowiązanie do konfiguracji. Włączmy niezbędne mody Apache:
a2enmod headers a2enmod ssl a2enmod rewrite
W CentOS musimy ręcznie włączyć uruchamianie serwisów przy starcie systemu:
systemctl enable mariadb systemctl enable httpd
Na koniec restartujemy serwis, żeby nowe ustawienia zaczęły obowiązywać:
service apache2 restart service apache2 status
Jeżeli uruchamiamy stronę na HTTPS, musimy jeszcze wrzucić certyfikaty do katalogu /etc/apache2/ssl. Zmieniamy właściciela plików strony:
chown -R www-data:www-data /home/page/httpdocs/ # W CentOS użytkownik ten nazywa się apache
W MySQL tworzymy bazę danych dla naszej strony, przykładowo (page to nazwa naszej bazy):
mysql -u root -p CREATE DATABASE IF NOT EXISTS page CHARACTER SET 'utf8' COLLATE utf8_polish_ci; GRANT ALL PRIVILEGES ON page.* TO 'page'@'localhost' IDENTIFIED BY 'xxx'; FLUSH PRIVILEGES; SELECT host, user, password FROM mysql.user ORDER BY user, host; # sprawdzenie use page; exit;
W sekcji [mysqld] dopisujemy do /etc/mysql/mysql.conf.d/mysqld.cnf:
default-storage-engine=InnoDB
Przykładowa konfiguracja Apache
- page.conf
<VirtualHost *:443> DocumentRoot /home/page/httpdocs ServerName yourdomain.pl ServerAdmin youremail@yourdomain.pl Header always set Strict-Transport-Security "max-age=63072000; includeSubdomains;" SSLEngine On SSLCertificateFile /etc/apache2/ssl/certs/server.crt SSLCertificateKeyFile /etc/apache2/ssl/private/server.key SSLCertificateChainFile /etc/apache2/ssl/certs/chain.crt ErrorLog /home/page/logs/ssl_error.log CustomLog /home/page/logs/ssl_access.log combined <Directory /home/page/httpdocs> AddType application/x-httpd-php .php .php3 .php4 .inc DirectoryIndex index.php index.php3 index.html Options -Indexes +FollowSymLinks +Includes -ExecCGI AllowOverride All Require all granted #Require all denied #Require ip xxx </Directory> </VirtualHost> <VirtualHost *:80> DocumentRoot /home/page/httpdocs ServerName yourdomain.pl ServerAdmin youremail@yourdomain.pl Redirect permanent / https://yourdomain.pl ErrorLog /home/page/logs/error.log CustomLog /home/page/logs/access.log combined <Directory /home/page/httpdocs> AddType application/x-httpd-php .php .php3 .php4 .inc DirectoryIndex index.php index.php3 index.html Options -Indexes +FollowSymLinks +Includes -ExecCGI AllowOverride All Require all granted #Require all granted #Require not ip 212 #Require all denied #Require ip xxx </Directory> </VirtualHost>