Webbstackar
Apache, MySQL & PHP - Quick setup guide (Linux)
Note: You need to be logged in as root while performing the steps in this tutorial.
Create group and user mysql
groupadd mysql
useradd -g mysql mysql
Download the tarballs:
A note on how to obtain the MySQL tarball:
Go to http://dev.mysql.com/downloads/
Click the MySQL Community Server link
To be able to download mysql-5.6.21-linux-glibc2.5-i686.tar.gz, you have to change option in the Select Platform: drop-down menu.Click the down arrow to expand the menu and click Linux - Generic to select it.
Scroll down to the Linux - Generic (glibc 2.5) (x86, 32-bit), Compressed TAR Archive file (mysql-5.6.21-linux-glibc2.5-i686.tar.gz) and click the Download button.
You are transferred to a new page. Click the No thanks, just start my download. link below the Login/Sign Up section.
The tarballs:
Apache: httpd-2.4.10.tar.gz (http://httpd.apache.org/download.cgi)
MySQL: mysql-5.6.21-linux-glibc2.5-i686.tar.gz (http://dev.mysql.com/downloads/)
PHP: php-5.6.3.tar.gz (http://www.php.net/downloads.php)
Extract the tarballs
tar -xvzf httpd-2.4.10.tar.gz
tar -xvzf php-5.6.3.tar.gz
Install Apache & MySQL
Apache 2.4.10cd <path to the extracted httpd-2.4.10 folder>
./configure --prefix=/usr/local/apache2 --enable-module=so --enable-ssl
make
make install
MySQL 5.6.21
Set up MySQL
Copy mysql-5.6.21-linux-glibc2.5-i686.tar.gz into /usr/local and extract it:tar -xvzf mysql-5.6.21-linux-glibc2.5-i686.tar.gz
Then do:
cd /usr/local
mv mysql-5.6.21-linux-glibc2.5-i686 mysql
chown -R mysql mysql
chgrp -R mysql mysql
cd /usr/local/mysql/scripts
Note: Put the following mysql_install_db command on a single line before executing by pressing Enter.
In this example I've put the command on multiple lines for clarity.
./mysql_install_db --user=mysql
--basedir=/usr/local/mysql
--datadir=/usr/local/mysql/data
Proceed by doing this:
cd /usr/local
chown -R root mysql
Edit my.cnf
cd /usr/local/mysql
Start a text editor and open my.cnf.
Edit the file to match this:
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
server_id = 1
socket = /tmp/mysql.sock
Save the changes, close the my.cnf file
Set a root password
cd /usr/local/mysql/bin
./mysqld_safe --user=root &
Press Enter to get back to the prompt when the server has started.
./mysqladmin -u root password new_root_password
The command above sets a password for the mysql server root account.You only have to execute this command when you start the mysql server for the very first time.
Test the installation:
cd /usr/local/mysql/bin
./mysql -u root -p
Enter previously set mysql server root account password.
At the mysql prompt, execute the command:
show databases
You should see something like:
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.01 sec)
To exit the server, at the mysql prompt, execute the command:
exit;
Starting the MySQL server:
cd /usr/local/mysql/bin
./mysqld_safe --user=root &
Press Enter to get back to the prompt when the server has started.
Working with the MySQL server:
To log on to the MySQL server, execute these commands:
cd /usr/local/mysql/bin
./mysql -u root -p
Enter previously set new_root_password.
Log off from the MySQL server
To exit the server, at the mysql prompt, execute the command:
exit;
Stopping the MySQL server:
To stop the MySQL server, execute the command:
killall mysqld
Wait for the shutdown operation to complete. Press Enter to get back to the prompt when the server has started.
Install PHP
PHP 5.6.3cd /path/to/the/extracted/php-5.6.3 folder
Note: Put the following ./configure command on a single line before executing by pressing Enter.
In this example I've put the command on multiple lines for clarity.
./configure --prefix=/usr/local/php
--with-apxs2=/usr/local/apache2/bin/apxs
--with-mysql=/usr/local/mysql
--with-mysqli=/usr/local/mysql/bin/mysql_config
--with-mcrypt
--enable-mbstring
--with-bz2
--with-zlib
--enable-zip
--with-pdo-mysql=mysqlnd
--with-mysql-sock=/tmp/mysql.sock
After executing the ./configure command with parameters, execute these commands:
make
make install
Set up PHP
Edit the php.ini filecd /path/to/the/extracted/php folder
cp php.ini-production /usr/local/php/lib/php.ini
Start a text editor and open php.ini.
In the Paths and Directories section of the file, uncomment the UNIX: include_path and set it to "/usr/local/php/include/php", set the doc_root path to "/usr/local/apache2/htdocs" and the extension_dir path to "/usr/local/php/include/php/ext":
In the Module Settings section of the file, set the date.timezone to the timezone that best matches your location (for example "Europe/Stockholm"). To find the names of supported timezones, visit http://php.net/manual/en/timezones.php.
In the Pdo_mysql section of the file, set pdo_mysql.default_socket to /tmp/mysql.sock
Examples:
UNIX: include_path = "/usr/local/php/include/php"
doc_root = "/usr/local/apache2/htdocs"
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-zts-xxxxxxxx"
date.timezone = "Europe/Stockholm"
pdo_mysql.default_socket = /tmp/mysql.sock
Save the changes, close the php.ini file and make it executable:
chmod 755 php.ini
Set up Apache 2
Edit the httpd.conf file (/usr/local/apache2/conf/httpd.conf):Start a text editor and open httpd.conf. Make sure the content matches the examples below.
ServerRoot "/usr/local/apache2"
LoadModule php5_module modules/libphp5.so
DocumentRoot "/usr/local/apache2/htdocs"
Tell Apache to parse .php files as PHP:
At the bottom part of httpd.conf, among the include conf/extra lines, add this line:
include conf/extra/httpd-php.conf
Save the changes and close the httpd.conf file.
Start a text editor and create a file called httpd-php.conf
Copy the FilesMatch tag example below and paste it into the new httpd-php.conf file.
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
Save the file in the extra (/usr/local/apache2/conf/extra) folder.
Reboot computer.
Working with Apache 2
Starting the Apache server:Use the standard procedure for starting the Apache server:
cd /usr/local/apache2/bin
./apachectl start
Test the Apache installation:
Open a web browser, type 127.0.0.1/ in the address field and press Enter. Apache should display its default index.html document.
Test the PHP installation:
Start a text editor and type into the new document:
<?php
phpinfo();
?>
Name the document phpinfo.php and save it in /usr/local/apache2/htdocs. Make sure the file has the proper php extension (.php).
Then open a web browser, type 127.0.0.1/phpinfo.php in the address field and press Enter. If all goes well, some information about your PHP setup should be displayed in the browser window.
Stopping the Apache server:
To stop the Apache server, change folder to /usr/local/apache2/bin and use the apachectl stop command:
cd /usr/local/apache2/bin
./apachectl stop