Mac OS X Apache install not working 403 Forbidden - php

I'm trying to setup an apache server with php and mysql on my Mac OS X.
For this I'm using this tutorial.
After folowing the directions I still get a 403 forbidden error when I load the page.
These are the steps that I've done:
apachectl start
Edited /etc/apache2/httpd.conf (here is my full config file) I uncommented the line LoadModule php5_module libexec/apache2/libphp5.so and the line Include /private/etc/apache2/extra/httpd-vhosts.conf
After this I restarted apache with this command apachectl restart
I installed MySQL with mysql-5.6.25-osx10.9-x86_64.dmg
I clicked on preferences and started MySQL server
I did export PATH=/usr/local/mysql/bin:$PATH because it said so in the tutorial
Ran these command because they were in the tutorial:
cd /var
mkdir mysql
cd mysql
ln -s /tmp/mysql.sock mysql.sock
I edited /etc/apache2/extra/httpd-vhosts.conf to make a new virtual host (here is my full config file)
Restarted apache again with apachectl restart
Added a line to my hosts file: 127.0.0.1 roy.local
Flushed dns: dscacheutil -flushcache
Started a browser and typed in: http//roy.local and I get a 403 forbidden page
I' ve already tried to give my /user/roy/websites folder a chmod of 775 by doing these commands:
cd /user/roy
chmod 775 Websites
And then restarted apache again, this didn't do the trick. Please help me out. If you need more information I'm happy to do that. I can't figure this out myself. Thanks in advance!

Change your setting to this. you are using the old apache syntax.
<Directory "/Users/Roy/Websites">
Require all granted
</Directory>
Just for testing purpose, change permission of the directory and files to 777.

Related

404 Page Not Found when run Codeigniter project inside var/www/html/ on Ubuntu 16.04 LTS?

I have installed LAMP (Linux, Apache2, MySQL, and PHP) stack.
I have a project directory named 'mahasiswa'. When i ran it on Windows 8 was working well (using XAMPP). Then, when i run it on my Ubuntu 16.04 LTS inside var/www/html/ is not working anymore.
The screen shot of the result :
Is there special configuration to run CodeIgniter project on Ubuntu 16.04 LTS ?
:: Any help would be much appreciate. Thank you.
EDIT
My configuration files :
etc/apache2/sites-available/000-default.conf
etc/apache2/sites-available/mahasiswa.conf
etc/hosts
mahasiswa/.htaccess
The current result on browser:
I don't know exactly what i've missing at this configuration. I've followed #eeya instruction / answer below. Any body can help me, please :D
For your question in setting up the apache virtual host configuration: Here's how it goes. If you have [root] privilege, Open your [Terminal] and go to this directory: /etc/apache2/sites-available
Then create a new virtual host configuration, For now, we will name this configuration the name of your project.
sudo vim mahasiswa.conf or sudo nano mahasiswa.conf
<VirtualHost *:80>
ServerName local.mahasiswa.com
DocumentRoot /var/www/html/mahasiswa
<Directory /var/www/html/mahasiswa/>
AllowOverride All
Require all granted
Allow from all
</Directory>
</VirtualHost>
1) ServerName: serves as the the DNS (Think of it as another server name aside from http://localhost or http://127.0.0.1)
2) DocumentRoot: from the word itself, is your [project]'s directory (e.g /var/www/html/mahasiswa)
3) Directory: are used to enclose a group of directives that will apply only to the named directory, sub-directories of that directory, and the files within the respective directories. In this case, we wanted to place control access rights to a directory:
AllowOverride All (This can be either All or None)
Require all granted
Allow from all
You can learn more of this here: http://httpd.apache.org/docs/current/mod/core.html#directory
Going back, Once you've saved this new configuration, Go to your /etc/hosts (hosts file) (e.g sudo vim /etc/hosts) and add the ff:
127.0.0.1 localhost local.mahasiswa.com
Once you've saved these changes on your [hosts] file, Execute this command:
sudo a2ensite mahasiswa.conf
sudo a2enmod rewrite
This will now [enable] your new site configuration and enable the [url rewrite] module as well. Then execute this afterwards:
sudo service apache2 reload
From the command itself, it means you need to reload [apache2] thus the configuration takes affect afterwards.
Then try to access your new domain name: local.mahasiswa.com.
You should be able to see your CI pages you've needed.
For further reference, check [Digital Ocean] guide here: https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-16-04
Hope this helps for your case.
Edit:
In naming the [controller] file(s) (e.g mahasiswa), You might need to set [UpperCase] instead of [lowercase] format to (e.g Mahasiswa)
Enable mod_rewrite
sudo a2enmod rewrite
sudo systemctl restart apache2

Setup laravel app on digitalocen

I an trying to get my Laravel site running on Digital Ocean. My laravel app is static so no SQL is used and I developed it locally with Homestead.
I can get the site showing the home page on IPaddress /public. It won't link to any pages though. I am guessing it is some rewrite problem I am having. I want to get rid of the /public and get it linking to other pages. Then worry about making it work on a domain
I followed PHPAcademys Cloud Server Set-up tutorial https://www.youtube.com/watch?v=1-ok9d_6xrc
The only difference is I used UBUNTU 14.04 x64. While following the tutorial I found I had a html folder inside /var/www. I needed to put my app within the html folder.
Code setup
sudo apt-get update
sudo apt-get install apache 2
sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt
I didnt use mysql because i dont need it for this app. Its a static site with laravel.
It said mcrypt was needed so I used
sudo php5enmod mcrypt
sudo service apache2 restart
Then I was getting an exception handler error, so i fixed that with
chgrp -R www-data /var/www/html
chmod -R 775 /var/www/html/app/storage
You need to setup an apache2 virtual host
cd /etc/apache2/sites-available
sudo nano myapp.conf
<VirtualHost *:80>
ServerName myapp.com
ServerAlias www.myapp.com
DocumentRoot "/var/www/html/myapp/public"
<Directory "/var/www/html/myapp/public/">
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
exit nano
sudo a2ensite myapp.conf
sudo service apache2 restart
First go to your virtual host file which can be found on
/etc/apache2/sites-available/default.conf
I am not very sure about the path because I have been using nginx for so long. Anyways locate the conf file and change your root directory to something like
/var/www/html/public
rest all looks fine to me if that doesn't work chmod 777 app/storage

How to open HTML file in browser in centos?

I am accessing one system with ipaddress 192.168.1.41 as a server. In this system has one HTML file which is located at path opt/openerp/apache/htdocs/index.html. Now how can I access the html file in my local system browser ?
I tried with 192.168.1.41/index.html but it does not work.
Can anyone help me how to access the file in my local browser
Put index.html in /var/www/ and try opening with the browser 192.168.1.41/index.html. First check apache2 is installed
Steps -
1. sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/site_name
2. Change the default document root and directory directive in the new file to new location.
3. sudo a2dissite default && sudo a2ensite mysite [deactivate old site and activate new site]
4. sudo service apache2 restart

Where do I find DocumentRoot on Ubuntu after installing PHP, MySQL and Apache2?

I am new to Ubuntu Linux (version 13.10). I am following this tutorial to install MySQL, PHP, and Apache2.
It installed successfully, but I don't know where to write PHP files that execute when you navigate to the URL localhost/example.php.
I am looking at this link, but I am afraid that maybe it will not work and have to reinstall Ubuntu again.
In a newer version should be in a different path: /var/www/html
With a series of commands you can find:
ls /etc/apache2/sites-available/
That answers with something like
000-default.conf default-ssl.conf
In this case you need the second file default-ssl.conf; with
grep -n -e "DocumentRoot" /etc/apache2/sites-available/default-ssl.conf
you can obtain:
5: DocumentRoot /var/www/html
That means you can find (and change) DocumentRoot definition in the 5-th lines of the file /etc/apache2/sites-available/default-ssl.conf.
As a simple Google search would have showed you, it's (by default), /var/www/.
In the Ubuntu default config, that is defined in the default virtual host, the config file for that is /etc/apache2/sites-available/default
The default location of document root is /var/www. This, assuming you haven't touched the HTTPd configuration.
By the way, if you simply need a development server for PHP scripts, you can use the one emebedded in PHP > 5.4. Just cd to the project directory and launch:
php -S localhost:8008
In vscode (I'm sure in other editors as well) you can right click the file and copy path and copy relative path.
http://127.0.0.1:8000/site.php
Works for me.

How to start with PHP on Ubuntu

I am newbie in PHP. I have successfully installed PHP on Ubuntu, now I want start my first program. I am using gPHPEdit as IDE.
Where should I save .php files that I create? And how to run/test them?
Make sure you have LAMP installed. Do a sudo tasksel and select lamp then hit enter, its gotta be the most simple *amp install ever made. Its a good idea to install phpmyadmin: sudo apt-get install phpmyadmin. After that just copy the files to /var/www/ and then they will show up on http://localhost. I recommended using Eclipse PDT or the Netbeans build for PHP.
You should pick up a book or start following some good tutorials on the web.
If you are just scripting using php, you can save them anywhere and run the php on the terminal using the php command line interpreter.
If you are trying write web scripts (and I think you are), you need to install and configure a web server (typically apache) and save your scripts in the server's document root (typically /var/www). Also, I highly recommend you to read up a little about servers and HTTP and figure out how all this works on the inside before learning to building websites in php.
If you cannot save or copy to var/www/html, to run your php scripts on your browser. If you are using Ubuntu 14.04.
I followed these steps and it worked for me.
Execute sudo su on the terminal.
Enter your password
Execute sudo subl /etc/apache2/sites-available/000-default.conf on your terminal to open this file. Note you can change the subl to any text editor to open the file e.g sudo nano /etc/apache2/sites-available/000-default.conf.
Change DocumentRoot /var/www/html to /home/user/yoursubdir
Save the file and close it.
Execute sudo subl /etc/apache2/apache2.conf on your terminal to open this file.
Add the following to end of the file
<Directory /home/user/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Save and Close the file.
Execute sudo service apache2 restart
Go to your browser, type the URL of your script e.g 127.0.1.1/directory/document.php.
I hope this helps.
remove the index.html file from /var/www/
$ sudo rm index.html
create a new php file there:
$ sudo gedit /var/www/index.php
write in it:
<?php
print_r(phpinfo());
?>
Restart your Apache2 Server :
$ sudo service apache2 restart
OR
$ sudo /etc/init.d/apace2 restart
and point to yout localhost and /index.php
if err arises visit : http://www.allaboutlinux.eu/how-to-run-php-on-ubuntu/
https://www.php.net/manual/en/features.commandline.webserver.php
this is an easy way to test your files in php.
$ cd ~/public_html
$ php -S localhost:8000
then you can go to your browser and enter localhost:8000/myfile.php.

Categories