sudo apt-get install apache2
Before we proceed with setting up apache lets set up the hosts file, this file holds ip mappings to machine names.
sudo gedit /etc/hosts
You will see something like this
127.0.0.1 localhost.localdomain localhost # The following lines are desirable for IPv6 capable hosts ::1 localhost ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters ff02::3 ip6-allhosts
Add the line 127.0.0.1 test-site-name.local to make it look something like this, i have used the name "ccl" in this example
127.0.0.1 localhost.localdomain localhost 127.0.0.1 ccl.local z3d-laptop # The following lines are desirable for IPv6 capable hosts ::1 localhost ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters ff02::3 ip6-allhosts
Now when you are done setting up the hosts file, we'll now configure virtual hosting so that we can host multiple domains (or subdomains) with the server.
cd /etc/apache2/sites-available
Once in the directory lets make setup our virtual host, for this we'll use the template provided by apache. This file is named default. Create a copy of the file first.
sudo cp default your-site-name
Now open the file you just created (by copying) for editing
sudo gedit your-site-name
This should open something similar to this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | <VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> ErrorLog /var/log/apache2/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog /var/log/apache2/access.log combined Alias /doc/ "/usr/share/doc/" <Directory "/usr/share/doc/"> Options Indexes MultiViews FollowSymLinks AllowOverride None Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 ::1/128 </Directory> </VirtualHost> |
In this file add the line ServerName test-site-name.local just above the DocumentRoot directive (in front of line 4). Edit DocumentRoot /var/www path on line 4 and set it to /path-to-the-test-site-WITHOUT-trailing-slash. It should look something like this
DocumentRoot /path-to-the-test-site-WITHOUT-trailing-slash
Edit path on line 9 and set it to /path-to-the-test-site-WITH-trailing-slash/. It should look something like this
Directory /path-to-the-test-site-WITH-trailing-slash/
Please Note: Be careful regarding where there is a trailing slash where there is none. Also change
AllowOverride None
to
AllowOverride All
for the first two directory nodes (the / one and the one with the path to your site). That will allow all the .htaccess files to work properly and allow redirection.
Now we are almost done, we just need to enable the site
sudo a2ensite test-site-name
sudo /etc/init.d/apache2 restart
In the next step lets configure and install MySQL
apt-get install mysql-server
when prompted for a password choose one and save it for future reference Note the configuration file for MySQL is located at /etc/mysql/my.cnf we will not be modifying it but you should know it for future reference. Running the next command is recommended for securing your server, especially if it is a production server. When you will run the command you will be prompted for many things answering them with a yes is recommended.
mysql_secure_installation
Next lets create a database and grant control to a user
mysql -u root -p create database test-db; grant all on test-db.* to 'zed' identified by 'password'; flush privileges; quit
Note: The semicolons are important and identify end of MySQL commands. In the above case a database with the name of test-db has been created and the user zed has been granted full control over it. The password for the user is password. You can keep any password that you like. With Apache and MySQL installed we are now ready to move on to installing PHP. Install php
apt-get install php5 php-pear
If you are not experienced with PHP the following configurations are useful for more detailed logging and better performance
sudo gedit /etc/php5/apache2/php.ini
Change the fields as shown below
max_execution_time = 30 memory_limit = 64M error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR display_errors = Off log_errors = On error_log = /var/log/php.log register_globals = Off
Now restart Apache
sudo /etc/init.d/apache2 restart
if you need MySQL support in PHP then install the following package
apt-get install php5-mysql apt-get install php5-suhosin
The second package is a recommended package for security, it provided additionally security for PHP Restart Apache to make sure everything is correct
sudo /etc/init.d/apache2 restart
Wola! Your lamp server is now configured and good to go! :)
No comments:
Post a Comment